Download:
child 252:faef9902f1d1
parent 250:c6c59c348e26
251:5f154c0a2457
Anton Shestakov <av6@dwimlabs.net>, Thu, 17 Nov 2016 00:36:02 +0800
queue: add support for polling GitHub API

1 файлов изменено, 25 вставок(+), 0 удалений(-) [+]
poller-queue.py file | annotate | diff | comparison | revisions
--- a/poller-queue.py Thu Nov 17 00:33:40 2016 +0800
+++ b/poller-queue.py Thu Nov 17 00:36:02 2016 +0800
@@ -24,6 +24,8 @@
if 'scm' not in target:
if target['type'] == 'hgweb':
target['scm'] = 'hg'
+ elif target['type'] == 'github':
+ target['scm'] = 'git'
class CandolintPoller(Application):
@@ -65,6 +67,8 @@
if target['type'] == 'hgweb':
self.parse_hgweb(target, data)
+ elif target['type'] == 'github':
+ self.parse_github(target, data)
target['etag'] = response.headers.get('ETag', None)
elif response.code == 304:
@@ -91,6 +95,27 @@
logging.info('Got %d current hash(es) from %s', len(hashes), target['poll'])
target['hashes'] = hashes
+ def parse_github(self, target, data):
+ hashes = {branch['name']: branch['commit']['sha'] for branch in data}
+ if 'hashes' in target:
+ new = []
+ for name, sha in hashes.items():
+ if target['hashes'].get(name) != sha:
+ new.append(name)
+ if new:
+ base = {
+ 'url': target['url'],
+ 'scm': target['scm'],
+ 'repo': target['repo'],
+ 'source': target['source'],
+ 'timestamp': timestamp()
+ }
+ self.push(base, new)
+ logging.info('Got %d new hash(es) from %s', len(new), target['poll'])
+ else:
+ logging.info('Got %d current hash(es) from %s', len(hashes), target['poll'])
+ target['hashes'] = hashes
+
def push(self, base, changes):
for change in changes:
item = base.copy()