Browse Source

Replace reportbot with irccat for now.

This needs a much better way of working.
master
Chris Smith 5 years ago
parent
commit
91f4613d5a
3 changed files with 28 additions and 4 deletions
  1. 7
    0
      lineandsinker/services/__init__.py
  2. 17
    0
      lineandsinker/services/irccat.py
  3. 4
    4
      main.py

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

@@ -2,6 +2,7 @@ import os
2 2
 
3 3
 from .docker import Docker
4 4
 from .gitea import Gitea
5
+from .irccat import IrcCat
5 6
 from .jenkins import Jenkins
6 7
 from .reportbot import ReportBot
7 8
 from .slack import Slack
@@ -18,6 +19,11 @@ def gitea_factory():
18 19
         install_hooks="LAS_GITEA_ADD_HOOKS" in os.environ,
19 20
     )
20 21
 
22
+def irccat_factory():
23
+    return IrcCat(
24
+        os.environ["LAS_IRCCAT_URL"],
25
+        os.environ["LAS_IRCCAT_CHANNEL"],
26
+    )
21 27
 
22 28
 def jenkins_factory():
23 29
     return Jenkins(
@@ -42,6 +48,7 @@ def slack_factory():
42 48
 services = {
43 49
     "docker": docker_factory(),
44 50
     "gitea": gitea_factory(),
51
+    "irccat": irccat_factory(),
45 52
     "jenkins": jenkins_factory(),
46 53
     "reportbot": reportbot_factory(),
47 54
     "slack": slack_factory(),

+ 17
- 0
lineandsinker/services/irccat.py View File

@@ -0,0 +1,17 @@
1
+import requests
2
+
3
+from .service import Service
4
+
5
+
6
+class IrcCat(Service):
7
+    def __init__(self, url, channel):
8
+        super().__init__("irccat")
9
+        self._url = url
10
+        self._channel = channel
11
+
12
+    def announce(self, message):
13
+        for line in message.split("\n"):
14
+            requests.post(
15
+                self._url,
16
+                f"{self._channel}, {line}",
17
+            )

+ 4
- 4
main.py View File

@@ -14,21 +14,21 @@ def handle_events(events):
14 14
         if event["type"] == "git.push":
15 15
             services["jenkins"].build_job_by_scm_url(event["repo"]["urls"])
16 16
             if event["repo"]["public"]:
17
-                services["reportbot"].announce(
17
+                services["irccat"].announce(
18 18
                     f"\002[git]\002 {event['user']} pushed {len(event['commits'])} commit{'s' if len(event['commits']) != 1 else ''} to {event['repo']['name']}: {event['compare_url']}"
19 19
                 )
20 20
 
21 21
                 for commit in event["commits"][::-1][:3]:
22 22
                     line = commit["message"].split("\n")[0][:100]
23
-                    services["reportbot"].announce(
23
+                    services["irccat"].announce(
24 24
                         f"\002[git]\002 {commit['id']}: {line}"
25 25
                     )
26 26
         elif event["type"] == "docker.push":
27
-            services["reportbot"].announce(
27
+            services["irccat"].announce(
28 28
                 f"\002[registry]\002 New manifest pushed to {event['host']}/{event['repo']}:{event['tag']} by {event['user']}"
29 29
             )
30 30
         elif event["type"] == "slack":
31
-            services["reportbot"].announce(
31
+            services["irccat"].announce(
32 32
                 f"\002[{event['source']}]\002 {event['text']}"
33 33
             )
34 34
 

Loading…
Cancel
Save