Add the basics of a github webhook in modules/github.py

This commit is contained in:
jesopo 2018-10-05 23:29:59 +01:00
parent ff00ec1226
commit d817ec9832

27
modules/github.py Normal file
View file

@ -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))