Browse Source

Slack webhook support

master
Chris Smith 5 years ago
parent
commit
65435d54ae
4 changed files with 30 additions and 0 deletions
  1. 4
    0
      README.md
  2. 6
    0
      lineandsinker/services/__init__.py
  3. 16
    0
      lineandsinker/services/slack.py
  4. 4
    0
      main.py

+ 4
- 0
README.md View File

@@ -65,6 +65,10 @@ Environment variable | Description
65 65
 
66 66
 LaS can send messages to a ReportBot instance.
67 67
 
68
+### Slack
69
+
70
+LaS accepts Slack-style webhooks. There are no configuration options.
71
+
68 72
 ## Contributing
69 73
 
70 74
 All code is formatted using [Black](https://github.com/ambv/black) with

+ 6
- 0
lineandsinker/services/__init__.py View File

@@ -4,6 +4,7 @@ from .docker import Docker
4 4
 from .gitea import Gitea
5 5
 from .jenkins import Jenkins
6 6
 from .reportbot import ReportBot
7
+from .slack import Slack
7 8
 
8 9
 
9 10
 def docker_factory():
@@ -30,9 +31,14 @@ def reportbot_factory():
30 31
     )
31 32
 
32 33
 
34
+def slack_factory():
35
+    return Slack()
36
+
37
+
33 38
 services = {
34 39
     "docker": docker_factory(),
35 40
     "gitea": gitea_factory(),
36 41
     "jenkins": jenkins_factory(),
37 42
     "reportbot": reportbot_factory(),
43
+    "slack": slack_factory(),
38 44
 }

+ 16
- 0
lineandsinker/services/slack.py View File

@@ -0,0 +1,16 @@
1
+import json
2
+
3
+from .service import Service
4
+
5
+
6
+class Slack(Service):
7
+    def __init__(self):
8
+        super().__init__("slack")
9
+
10
+    def accept_hook(self, identifier, request):
11
+        if request.content_type == "application/json":
12
+            content = request.json()
13
+        else:
14
+            content = json.loads(request.get_data()["payload"])
15
+
16
+        yield {"type": f"slack", "source": identifier, "text": content["text"]}

+ 4
- 0
main.py View File

@@ -26,6 +26,10 @@ def handle_events(events):
26 26
             services["reportbot"].announce(
27 27
                 f"\002[registry]\002 New manifest pushed to {event['host']}/{event['repo']}:{event['tag']} by {event['user']}"
28 28
             )
29
+        elif event["type"] == "slack":
30
+            services["reportbot"].announce(
31
+                f"\002[{event['source']}]\002 {event['text']}"
32
+            )
29 33
 
30 34
 
31 35
 @app.route("/")

Loading…
Cancel
Save