ソースを参照

Add reportbot announcement method

master
Chris Smith 6年前
コミット
7c11da7def
1個のファイルの変更14行の追加0行の削除
  1. 14
    0
      main.py

+ 14
- 0
main.py ファイルの表示

1
 import hashlib
1
 import hashlib
2
+import socket
2
 
3
 
3
 import jenkins
4
 import jenkins
4
 import requests
5
 import requests
76
         yield repo["full_name"], repo["ssh_url"], repo["clone_url"]
77
         yield repo["full_name"], repo["ssh_url"], repo["clone_url"]
77
 
78
 
78
 
79
 
80
+def reportbot_announce(message):
81
+    try:
82
+        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
83
+            host = os.environ["LAS_REPORTBOT_ADDRESS"].split(":")
84
+            sock.connect((host[0], int(host[1])))
85
+            sock.sendall(
86
+                f"{os.environ['LAS_REPORTBOT_PREFIX']} {message}\n".encode("utf-8")
87
+            )
88
+            app.logger.info(f"Report bot response: {sock.recv(512)}")
89
+    except Exception:
90
+        app.logger.exception("Unable to send report bot message")
91
+
92
+
79
 repos = dict((name, [ssh, clone]) for name, ssh, clone in get_gitea_repos())
93
 repos = dict((name, [ssh, clone]) for name, ssh, clone in get_gitea_repos())
80
 jobs = list(get_jenkins_jobs())
94
 jobs = list(get_jenkins_jobs())
81
 app = Flask(__name__)
95
 app = Flask(__name__)

読み込み中…
キャンセル
保存