Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Commit

Permalink
Set the assignee if the user posts r? in the commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Oct 2, 2014
1 parent 5c945e6 commit 5dd7ba8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions newpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import ConfigParser
from StringIO import StringIO
import gzip
import re

cgitb.enable()

# Maximum per page is 100. Sorted by number of commits, so most of the time the
Expand All @@ -22,6 +24,8 @@
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'
unsafe_warning_msg = 'These commits modify **unsafe code**. Please review it carefully!'

reviewer_re = re.compile("[rR]\?[:\- ]*@([a-zA-Z0-9\-]+)")


def api_req(method, url, data=None, username=None, token=None, media_type=None):
data = None if not data else json.dumps(data)
Expand Down Expand Up @@ -106,6 +110,12 @@ def is_new_contributor(username, owner, repo, user, token):
return True
url = links['next']

# If the user specified a reviewer, return the username, otherwise returns None.
def find_reviewer(commit_msg):
match = reviewer_re.search(commit_msg)
if not match:
return None
return match.group(1)


print "Content-Type: text/html;charset=utf-8"
Expand Down Expand Up @@ -134,6 +144,11 @@ def is_new_contributor(username, owner, repo, user, token):
to_notify = random.choice(collaborators)
post_comment(welcome_msg % to_notify, owner, repo, issue, user, token)
set_assignee(to_notify, owner, repo, issue, user, token)
else:
msg = payload["pull_request"]['body']
reviewer = find_reviewer(msg)
if reviewer:
set_assignee(reviewer, owner, repo, issue, user, token)

warn_unsafe = False
diff = api_req("GET", payload["pull_request"]["diff_url"])['body']
Expand Down

0 comments on commit 5dd7ba8

Please sign in to comment.