Browse Source

Announce git pushes.

master
Chris Smith 5 years ago
parent
commit
ade63668ad
1 changed files with 22 additions and 6 deletions
  1. 22
    6
      main.py

+ 22
- 6
main.py View File

@@ -112,12 +112,28 @@ def handle_hook_gitea(repo, hash):
112 112
         app.logger.info(f"Repository not found. Known repos: {repos.keys()}")
113 113
         abort(404)
114 114
 
115
-    urls = repos[repo]
116
-    for name, spec, url in jobs:
117
-        if url in urls:
118
-            # TODO: Check branches
119
-            app.logger.info(f"Found matching job: {name} with URL {url}")
120
-            jenkins_server.build_job(name)
115
+    if request.headers.get("X-Gitea-Event") == "push":
116
+        urls = repos[repo]
117
+        for name, spec, url in jobs:
118
+            if url in urls:
119
+                # TODO: Check branches
120
+                app.logger.info(f"Found matching job: {name} with URL {url}")
121
+                jenkins_server.build_job(name)
122
+
123
+        data = request.get_json()
124
+        if not data["repository"]["private"]:
125
+            repo = data["repository"]["full_name"]
126
+            commits = len(data["commits"])
127
+            compare = data["compare_url"]
128
+            pusher = data["pusher"]["login"]
129
+
130
+            reportbot_announce(
131
+                f"\002[git]\002 {pusher} pushed {commits} commit{'s' if commits != 1 else ''} to {repo}: {compare}"
132
+            )
133
+            for commit in data["commits"][:3]:
134
+                reportbot_announce(
135
+                    f"\002[git]\002 {commit['id'][:10]}: {commit['message'][:100]}"
136
+                )
121 137
 
122 138
     return "", 204
123 139
 

Loading…
Cancel
Save