diff options
Diffstat (limited to 'webhook-core.py')
-rwxr-xr-x | webhook-core.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/webhook-core.py b/webhook-core.py index a9418bc..d4c1ab7 100755 --- a/webhook-core.py +++ b/webhook-core.py @@ -28,22 +28,28 @@ import sys, traceback from git_mirror import * if __name__ == "__main__": + # call this with: <reponame> <event name> <signature> repo = None # we will try to use this during exception handling try: repos = load_repos() - reponame = sys.argv[1] if len(sys.argv) > 1 else None + if len(sys.argv) < 4: + raise Exception("Usage: {0} <reponame> <event name> <signature>".format(os.path.basename(sys.argv[0]))) + reponame = sys.argv[1] + githubEvent = sys.argv[2] + githubSignature = sys.argv[3] if reponame not in repos: raise Exception("Repository missing or not found.") repo = repos[reponame] # now sync this repository data = get_github_payload() - if 'zen' in data: + if githubEvent == 'ping': # github sends this initially print("Content-Type: text/plain") print() - print("Welcome!") + print("Pong!") sys.exit(0) + elif githubEvent == 'push': ref = data["ref"] oldsha = data["before"] newsha = data["after"] @@ -62,6 +68,8 @@ if __name__ == "__main__": print("Content-Type: text/plain") print() print("Updated {0}:{1} from mirror {2} from {3} to {4}".format(reponame, ref, mirror, oldsha, newsha)) + else: + raise Exception("Unexpected github event {0}.".format(githubEvent)) except Exception as e: if repo is not None: repo.mail_owner("There was a problem running the git-mirror webhook:\n\n{0}".format(traceback.format_exc())) |