|
4 | 4 | import urllib, urllib2
|
5 | 5 | import cgi
|
6 | 6 | import cgitb
|
7 |
| -import simplejson as json |
| 7 | +import json |
8 | 8 | import random
|
9 | 9 | import sys
|
10 | 10 | import ConfigParser
|
|
14 | 14 | import time
|
15 | 15 | import socket
|
16 | 16 |
|
17 |
| -cgitb.enable() |
18 |
| - |
19 | 17 | # Maximum per page is 100. Sorted by number of commits, so most of the time the
|
20 | 18 | # contributor will happen early,
|
21 | 19 | contributors_url = "https://api.github.com/repos/%s/%s/contributors?per_page=100"
|
|
31 | 29 | """
|
32 | 30 | warning_summary = '<img src="http://www.joshmatthews.net/warning.svg" alt="warning" height=20> **Warning** <img src="http://www.joshmatthews.net/warning.svg" alt="warning" height=20>\n\n%s'
|
33 | 31 | unsafe_warning_msg = 'These commits modify **unsafe code**. Please review it carefully!'
|
| 32 | +submodule_warning_msg = 'These commits modify **submodules**.' |
34 | 33 | review_msg = 'r? @%s\n\n(rust_highfive has picked a reviewer for you, use r? to override)'
|
35 | 34 |
|
36 | 35 | reviewer_re = re.compile("[rR]\?[:\- ]*@([a-zA-Z0-9\-]+)")
|
37 | 36 | unsafe_re = re.compile("\\bunsafe\\b|#!?\\[unsafe_")
|
| 37 | +submodule_re = re.compile(".*\+Subproject\scommit\s.*", re.DOTALL|re.MULTILINE) |
38 | 38 |
|
39 | 39 | rustaceans_api_url = "http://www.ncameron.org/rustaceans/user?username={username}"
|
40 | 40 |
|
@@ -287,6 +287,11 @@ def choose_reviewer(repo, owner, diff, exclude):
|
287 | 287 | # return True
|
288 | 288 | # return False
|
289 | 289 |
|
| 290 | +def modifies_submodule(diff): |
| 291 | + if submodule_re.match(diff): |
| 292 | + return True |
| 293 | + return False |
| 294 | + |
290 | 295 | def get_irc_nick(gh_name):
|
291 | 296 | """ returns None if the request status code is not 200,
|
292 | 297 | if the user does not exist on the rustacean database,
|
@@ -328,6 +333,9 @@ def new_pr(payload, user, token):
|
328 | 333 | #if modifies_unsafe(diff):
|
329 | 334 | # warnings += [unsafe_warning_msg]
|
330 | 335 |
|
| 336 | + if modifies_submodule(diff): |
| 337 | + warnings.append(submodule_warning_msgs) |
| 338 | + |
331 | 339 | if warnings:
|
332 | 340 | post_comment(warning_summary % '\n'.join(map(lambda x: '* ' + x, warnings)), owner, repo, issue, user, token)
|
333 | 341 |
|
@@ -360,21 +368,24 @@ def new_comment(payload, user, token):
|
360 | 368 | set_assignee(reviewer, owner, repo, issue, user, token, author)
|
361 | 369 |
|
362 | 370 |
|
363 |
| -print "Content-Type: text/html;charset=utf-8" |
364 |
| -print |
365 |
| - |
366 |
| -config = ConfigParser.RawConfigParser() |
367 |
| -config.read('./config') |
368 |
| -user = config.get('github', 'user') |
369 |
| -token = config.get('github', 'token') |
370 |
| - |
371 |
| -post = cgi.FieldStorage() |
372 |
| -payload_raw = post.getfirst("payload",'') |
373 |
| -payload = json.loads(payload_raw) |
374 |
| -if payload["action"] == "opened": |
375 |
| - new_pr(payload, user, token) |
376 |
| -elif payload["action"] == "created": |
377 |
| - new_comment(payload, user, token) |
378 |
| -else: |
379 |
| - print payload["action"] |
380 |
| - sys.exit(0) |
| 371 | +if __name__ == "__main__": |
| 372 | + print "Content-Type: text/html;charset=utf-8" |
| 373 | + print |
| 374 | + |
| 375 | + cgitb.enable() |
| 376 | + |
| 377 | + config = ConfigParser.RawConfigParser() |
| 378 | + config.read('./config') |
| 379 | + user = config.get('github', 'user') |
| 380 | + token = config.get('github', 'token') |
| 381 | + |
| 382 | + post = cgi.FieldStorage() |
| 383 | + payload_raw = post.getfirst("payload",'') |
| 384 | + payload = json.loads(payload_raw) |
| 385 | + if payload["action"] == "opened": |
| 386 | + new_pr(payload, user, token) |
| 387 | + elif payload["action"] == "created": |
| 388 | + new_comment(payload, user, token) |
| 389 | + else: |
| 390 | + print payload["action"] |
| 391 | + sys.exit(0) |
0 commit comments