Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions handlers/monthly_update/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from eventhandler import EventHandler

import re

REPLY = "monthly update"

REACTION = "eyes"

MSG = ('Someone thinks this change could be added to the monthly blog '
'post! To help with this, we need someone to answer the following '
'qurstions: :smile:\n\n'
'1. Who is most impacted by this change: users, '
'Servo developers, embedders, or some other group?\n'
'1. What observable difference does this change make?\n'
'1. What preferences (if any) need to be enabled to observe '
'this difference?\n'
'1. What (if any) specific URLs are affected?\n\n'
'If this change is part of a broader feature/project please '
'make sure the PR description contains a `Fixes: #12345` or '
'`Part of: #12345` issue reference.\n\n'
'Please add `@%s %s` when answering these '
'questions so the bot notices your answer (or just quote this '
'comment).\n\n'
'Thanks for helping us prepare the monthly blog post! :heart:')


class MonthlyUpdateHandler(EventHandler):
def on_issue_labeled(self, api, payload):
if payload['label']['name'].lower() == 'monthly update':
api.post_comment(MSG % (api.user, REPLY))

def on_new_comment(self, api, payload):
if payload['issue']['state'] != 'open':
return

user = payload['comment']['user']['login']
if user == api.user: # ignore comments from self
return # (since `MSG` already has `REPLY`)

msg = payload['comment']['body']

if re.search(r'@%s[: ]*%s' % (api.user, REPLY), str(msg)):
api.add_reaction(payload['comment']['id'], REACTION)


handler_interface = MonthlyUpdateHandler
21 changes: 21 additions & 0 deletions handlers/monthly_update/tests/label_monthly_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"initial": {},
"expected": {
"comments": 1
},
"payload": {
"repository": {
"owner": {
"login": "servo"
},
"name": "highfive"
},
"label": {
"name": "monthly update"
},
"action": "labeled",
"issue": {
"number": 130
}
}
}
26 changes: 26 additions & 0 deletions handlers/monthly_update/tests/reply.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"initial": {},
"expected": {
"reactions": 1
},
"payload": {
"repository": {
"owner": {
"login": "servo"
},
"name": "highfive"
},
"action": "created",
"issue": {
"number": 130,
"state": "open"
},
"comment": {
"user": {
"login": "someone"
},
"body": "@highfive monthly update answers!",
"id": 12
}
}
}
11 changes: 11 additions & 0 deletions newpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class GithubAPIProvider(APIProvider):
BASE_URL = "https://api.github.com/repos/"
contributors_url = BASE_URL + "%s/%s/contributors?per_page=400"
post_comment_url = BASE_URL + "%s/%s/issues/%s/comments"
add_reaction_url = BASE_URL + "%s/%s/issues/comments/%s/reactions"
collaborators_url = BASE_URL + "%s/%s/collaborators"
issue_url = BASE_URL + "%s/%s/issues/%s"
get_label_url = BASE_URL + "%s/%s/issues/%s/labels"
Expand Down Expand Up @@ -170,6 +171,16 @@ def is_new_contributor(self, username):
return True
url = links['next']

def add_reaction(self, comment_id, reaction):
url = self.add_reaction_url % (self.owner, self.repo, comment_id)
try:
self.api_req("POST", url, {"content": reaction})
except error.HTTPError as e:
if e.code == 201:
pass
else:
raise e

def post_comment(self, body):
url = self.post_comment_url % (self.owner, self.repo, self.issue)
try:
Expand Down
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, payload, user, new_contributor, labels, assignee,
self.diff = diff
self.pull_request = pull_request
self.repo = str(self.repo) # workaround for testing
self.reactions = []

def is_new_contributor(self, username):
return self.new_contributor
Expand All @@ -32,6 +33,9 @@ def post_comment(self, body):
def add_label(self, label):
self.labels += [label]

def add_reaction(self, comment_id, reaction):
self.reactions += [reaction]

def remove_label(self, label):
self.labels.remove(label)

Expand Down Expand Up @@ -107,6 +111,9 @@ def run_tests(tests, warn=True, overwrite=False):
if 'assignee' in expected:
assert api.assignee == expected['assignee'], \
"%s == %s" % (api.assignee, expected['assignee'])
if 'reactions' in expected:
assert len(api.reactions) == expected['reactions'], \
"%s == %s" % (len(api.reactions), expected['reactions'])

# If this is the last test in the file, then it's time for cleanup
if test['clean']:
Expand Down
Loading