summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2014-12-06 23:06:23 +0100
committerJohannes Löthberg <johannes@kyriasis.com>2014-12-06 23:06:23 +0100
commitdfe76a8e156df057ab8576ed617f55bf10e1d3fd (patch)
tree3bf26a5cda17a5e21c82c56ca28be366dcc22238
downloadyagd-dfe76a8e156df057ab8576ed617f55bf10e1d3fd.tar.xz
yagd.py initial commit
-rw-r--r--yagd.py46
1 files changed, 46 insertions, 0 deletions
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)