From d817ec98324c75af263708367d8b3c064183534e Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 5 Oct 2018 23:29:59 +0100 Subject: [PATCH] Add the basics of a github webhook in modules/github.py --- modules/github.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 modules/github.py diff --git a/modules/github.py b/modules/github.py new file mode 100644 index 00000000..e0305d69 --- /dev/null +++ b/modules/github.py @@ -0,0 +1,27 @@ +import json +from src import ModuleManager, utils + +class Module(ModuleManager.BaseModule): + @utils.hook("api.post.github") + def github(self, event): + data = event["data"] + try: + data = json.loads(data) + except: + return + + if "commits" in data: + full_name = data["repository"]["full_name"] + + for commit in data["commits"]: + id = command["id"] + message = commit["message"] + author = "%s <%s>" % (commit["author"]["username"], + commit["author"]["email]) + modified_count = len(commit["modified"]) + added_count = len(commit["added"]) + removed_count = len(commit["removed"]) + + print("(%s) [%d/%d/%d mod/add/del] commit by %s: %s" % ( + full_name, modified_count, added_count, removed_count, + author, message))