8 import json |
8 import json |
9 import urllib |
9 import urllib |
10 import irc as Irc |
10 import irc as Irc |
11 from datetime import datetime, timedelta |
11 from datetime import datetime, timedelta |
12 from configfile import Config |
12 from configfile import Config |
|
13 import hgpoll as HgPoll |
13 |
14 |
14 g_credentials = None |
15 g_credentials = None |
15 g_portnumber = None |
16 g_portnumber = None |
16 g_throttle = [] |
17 g_throttle = [] |
17 |
18 |
18 valid_repos = ['Torr_Samaho/zandronum', 'Torr_Samaho/zandronum-stable', |
19 valid_repos = ['Torr_Samaho/zandronum', 'Torr_Samaho/zandronum-stable', |
19 'crimsondusk/zandronum-sandbox', 'crimsondusk/zandronum-sandbox-stable', |
20 'crimsondusk/zandronum-sandbox', 'crimsondusk/zandronum-sandbox-stable'] |
20 'crimsondusk/testrepo'] |
|
21 |
21 |
22 def is_throttled (address): |
22 def is_throttled (address): |
23 i = 0 |
23 i = 0 |
24 |
24 |
25 while i < len (g_throttle): |
25 while i < len (g_throttle): |
82 jsonstring = urllib.unquote_plus (payload).decode ('utf-8') |
82 jsonstring = urllib.unquote_plus (payload).decode ('utf-8') |
83 |
83 |
84 try: |
84 try: |
85 jsondata = json.loads (jsonstring) |
85 jsondata = json.loads (jsonstring) |
86 repodata = jsondata['repository'] |
86 repodata = jsondata['repository'] |
87 repopath = '%s/%s' % (repodata['owner'], repodata['name']) |
87 repo_name = '%s/%s' % (repodata['owner'], repodata['name']) |
88 |
88 |
89 if repopath not in valid_repos: |
89 if repo_name not in valid_repos: |
90 raise ValueError ('unknown repository %s' % repopath) |
90 raise ValueError ('unknown repository %s' % repo_name) |
|
91 |
|
92 commit_data = [] |
91 |
93 |
92 if 'commits' in jsondata: |
94 if 'commits' in jsondata: |
93 for commit in jsondata['commits']: |
95 for commit in jsondata['commits']: |
94 Irc.broadcast ('%s: new commit %s' % (address, commit['node'])) |
96 commit_data.append ([commit['node'], commit['message']]) |
|
97 |
|
98 if len (commit_data) > 0: |
|
99 HgPoll.process_new_commits (repo_name, commit_data) |
95 except Exception as e: |
100 except Exception as e: |
96 Irc.broadcast ('%s provided bad JSON: %s' % (address, e)) |
101 Irc.broadcast ('%s provided bad JSON: %s' % (address, e)) |
97 |
102 |
98 try: |
103 try: |
99 with open ('rejected_json.txt', 'w') as fp: |
104 with open ('rejected_json.txt', 'w') as fp: |