rest.py

changeset 99
147d78eea80b
parent 97
55d7d9aea160
child 100
2a56ccf67782
equal deleted inserted replaced
98:4edbdf390bd1 99:147d78eea80b
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 repo_name = '%s/%s' % (repodata['owner'], repodata['name']) 87 repo_fullname = '%s/%s' % (repodata['owner'], repodata['name'])
88 88
89 if repo_name not in valid_repos: 89 if repo_fullname not in valid_repos:
90 raise ValueError ('unknown repository %s' % repo_name) 90 raise ValueError ('unknown repository %s' % repo_fullname)
91 91
92 commit_data = [] 92 commit_data = []
93 93
94 if 'commits' in jsondata: 94 if 'commits' in jsondata:
95 for commit in jsondata['commits']: 95 for commit in jsondata['commits']:
96 commit_data.append ([commit['node'], commit['message']]) 96 commit_data.append ([commit['node'], commit['message']])
97 97
98 if len (commit_data) > 0: 98 if len (commit_data) > 0:
99 HgPoll.process_new_commits (repo_name, commit_data) 99 HgPoll.process_new_commits (repodata['name'], commit_data)
100 except Exception as e: 100 except Exception as e:
101 Irc.broadcast ('%s provided bad JSON: %s' % (address, e)) 101 Irc.broadcast ('%s provided bad JSON: %s' % (address, e))
102 102
103 try: 103 try:
104 with open ('rejected_json.txt', 'w') as fp: 104 with open ('rejected_json.txt', 'w') as fp:

mercurial