Yuvipanda has submitted this change and it was merged.
Change subject: Add github-reciever script to receive webhooks from github
......................................................................
Add github-reciever script to receive webhooks from github
Split out of the SuchABot project
Change-Id: If26c9dc714cf86f5d139e564914ce963699cb830
---
M config.yaml.sample
A src/github-receiver.py
2 files changed, 58 insertions(+), 0 deletions(-)
Approvals:
Yuvipanda: Verified; Looks good to me, approved
diff --git a/config.yaml.sample b/config.yaml.sample
index a3c2cdf..86ecd46 100644
--- a/config.yaml.sample
+++ b/config.yaml.sample
@@ -12,3 +12,7 @@
redis_prefix: "some-long-prefix-that-was-generated-by-openssl"
clients_key: "key-to-use-to-store-clients-list"
max_queue_length: 512
+github_receiver:
+ redis_prefix:
"some-long-prefix-that-was-generated-by-openssl-but-different"
+ clients_key: "key-to-use-to-store-clients-list"
+ max_queue_length: 512
diff --git a/src/github-receiver.py b/src/github-receiver.py
new file mode 100755
index 0000000..d144003
--- /dev/null
+++ b/src/github-receiver.py
@@ -0,0 +1,54 @@
+#!/data/project/gerrit-to-redis/gerrit-to-redis/bin/python
+import cgi
+import json
+import os
+import logging
+
+import redis
+import yaml
+
+
+BASE_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
+PUBLISH_LUA_PATH = os.path.join(BASE_PATH, 'src/publish-clients.lua')
+
+CONFIG_FILE = os.path.join(BASE_PATH, 'config.yaml')
+with open(CONFIG_FILE) as f:
+ config = yaml.load(f)
+
+REDIS_DB = config['redis']['db']
+REDIS_HOST = config['redis']['host']
+PREFIX = config['github_receiver']['redis_prefix']
+CLIENTS_KEY = config['github_receiver']['clients_key']
+MAX_QUEUE_LENGTH = config['github_receiver']['max_queue_length']
+
+form = cgi.FieldStorage()
+payload = json.loads(form['payload'].value)
+repo = payload['repository']['name']
+number = payload['number']
+action = payload['action']
+
+logging.basicConfig(
+ format='%%(asctime)s %s PR#%d %s %%(message)s' % (repo, number,
action),
+ filename=os.path.expanduser('~/logs/%s.receive' % repo),
+ level=logging.INFO
+)
+
+logging.info('Attempting to Redis connection to %s', REDIS_HOST)
+red = redis.StrictRedis(host=REDIS_HOST, db=REDIS_DB)
+logging.info('Redis connection to %s succeded', REDIS_HOST)
+
+logging.info('looking for %s', PUBLISH_LUA_PATH)
+
+with open(PUBLISH_LUA_PATH) as f:
+ publish_clients = red.register_script(f.read())
+
+def make_key(*key_parts):
+ return PREFIX + "_" + '.'.join(key_parts)
+
+
+logging.info('received')
+count = publish_clients(keys=[make_key(CLIENTS_KEY)],
args=[json.dumps(payload), MAX_QUEUE_LENGTH])
+logging.info('Pushed to %s clients', count)
+
+print('HTTP/1.0 200 OK')
+print('\n')
--
To view, visit https://gerrit.wikimedia.org/r/77553
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If26c9dc714cf86f5d139e564914ce963699cb830
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/gerrit-to-redis
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits