From dfe76a8e156df057ab8576ed617f55bf10e1d3fd Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Sat, 6 Dec 2014 23:06:23 +0100 Subject: yagd.py initial commit --- yagd.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 yagd.py diff --git a/yagd.py b/yagd.py new file mode 100644 index 0000000..fe8442a --- /dev/null +++ b/yagd.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +from flask import Flask, request +from sh import cd, git +import json, configparser + +app = Flask(__name__) + +config = configparser.ConfigParser() +config.read('config.ini') + +repos = config['yagd']['repos'] +basedir = config['yagd']['repodir'] + +def update_mirror(repo): + cd(basedir + repo + '.git') + git.remote.update() + + +@app.route('/',methods=['POST']) +def index(): + data = json.loads(request.data.decode('utf-8')) + + if request.headers.get('X-GitHub-Event') == 'ping': + print("Ping. Zen: {}".format(data['zen'])) + + elif request.headers.get('X-GitHub-Event') == 'push': + user = data['pusher']['name'] + repo = data['repository']['name'] + repo_fn = data['repository']['full_name'] + ref = data['ref'] + before = data['before'] + after = data['after'] + compare = data['compare'] + forced = data['forced'] + print('Push to {}: user {} updated ref {} from {} to {}. {}'.format(repo_fn, user, ref, before, after, compare)) + + if repo in repos: + update_mirror(repo) + + else: + print("New notification: {}".format(data)) + + return "OK" + +if __name__ == '__main__': + app.run(port=5002, debug=True) -- cgit v1.2.3-70-g09d2