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

Ignore new comments #258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
41 changes: 2 additions & 39 deletions highfive/newpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
submodule_warning_msg = 'These commits modify **submodules**.'
surprise_branch_warning = "Pull requests are usually filed against the %s branch for this repo, but this one is against %s. Please double check that you specified the right target!"

review_with_reviewer = 'r? @%s\n\n(rust_highfive has picked a reviewer for you, use r? to override)'
review_without_reviewer = '@%s: no appropriate reviewer found, use r? to override'
review_with_reviewer = '@%s has been chosen as the reviewer.\n\n(We\'ve picked a reviewer for you, use `r? @user` to override)'
review_without_reviewer = '@%s: no appropriate reviewer found, use `r? @user` to set one.'

reviewer_re = re.compile("\\b[rR]\?[:\- ]*@([a-zA-Z0-9\-]+)")
submodule_re = re.compile(".*\+Subproject\scommit\s.*", re.DOTALL | re.MULTILINE)
Expand Down Expand Up @@ -68,9 +68,6 @@ def run(self, event):
elif event == "pull_request" and self.payload["action"] == "opened":
self.new_pr()
return 'OK\n'
elif event == "issue_comment" and self.payload["action"] == "created":
self.new_comment()
return 'OK\n'
else:
return 'Unsupported webhook event.\n'

Expand Down Expand Up @@ -398,37 +395,3 @@ def new_pr(self):

if self.repo_config.get("new_pr_labels"):
self.add_labels(owner, repo, issue)

def new_comment(self):
# Check the issue is a PR and is open.
if self.payload['issue', 'state'] != 'open' \
or 'pull_request' not in self.payload['issue']:
return

commenter = self.payload['comment', 'user', 'login']
# Ignore our own comments.
if commenter == self.integration_user:
return

owner = self.payload['repository', 'owner', 'login']
repo = self.payload['repository', 'name']

# Check the commenter is the submitter of the PR or the previous assignee.
author = self.payload['issue', 'user', 'login']
if not (author == commenter or (
self.payload['issue', 'assignee'] \
and commenter == self.payload['issue', 'assignee', 'login']
)):
# Check if commenter is a collaborator.
if not self.is_collaborator(commenter, owner, repo):
return

# Check for r? and set the assignee.
msg = self.payload['comment', 'body']
reviewer = self.find_reviewer(msg)
if reviewer:
issue = str(self.payload['issue', 'number'])
self.set_assignee(
reviewer, owner, repo, issue, self.integration_user,
author, None
)
6 changes: 0 additions & 6 deletions highfive/tests/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ def get_global_configs():


class Payload(object):
@staticmethod
def new_comment():
with open(get_fake_filename('create-comment.payload'), 'r') as fin:
p = json.load(fin)
return payload.Payload(p)

@staticmethod
def new_pr(
number=7, pr_body='The PR comment.', pr_url='https://the.url/',
Expand Down
190 changes: 0 additions & 190 deletions highfive/tests/fakes/create-comment.payload

This file was deleted.

46 changes: 2 additions & 44 deletions highfive/tests/test_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_new_pr_contributor(self):
(
(
'POST', newpr.post_comment_url % ('rust-lang', 'rust', '7'),
{'body': 'r? @nrc\n\n(rust_highfive has picked a reviewer for you, use r? to override)'}
{'body': '@nrc has been chosen as the reviewer.\n\n(We\'ve picked a reviewer for you, use `r? @user` to override)'}
),
{'body': {}},
),
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_new_pr_contributor_with_labels(self):
(
(
'POST', newpr.post_comment_url % ('rust-lang', 'rust', '7'),
{'body': 'r? @nrc\n\n(rust_highfive has picked a reviewer for you, use r? to override)'}
{'body': '@nrc has been chosen as the reviewer.\n\n(We\'ve picked a reviewer for you, use `r? @user` to override)'}
),
{'body': {}},
),
Expand Down Expand Up @@ -258,45 +258,3 @@ def make_mocks(cls, patcherize):
config_mock = mock.Mock()
config_mock.get.side_effect = ('integration-user', 'integration-token')
cls.mocks['ConfigParser'].RawConfigParser.return_value = config_mock

def test_author_is_commenter(self):
payload = fakes.Payload.new_comment()
handler = newpr.HighfiveHandler(payload, dummy_config())
api_req_mock = ApiReqMocker([
(
(
'PATCH', newpr.issue_url % ('rust-lang', 'rust', '1'),
{'assignee': 'davidalber'}
),
{'body': {}},
),
])
handler.new_comment()
api_req_mock.verify_calls()

def test_author_not_commenter_is_collaborator(self):
payload = fakes.Payload.new_comment()
payload._payload['issue']['user']['login'] = 'foouser'

handler = newpr.HighfiveHandler(payload, dummy_config())
api_req_mock = ApiReqMocker([
(
(
"GET",
newpr.user_collabo_url % (
'rust-lang', 'rust', 'davidalber'
),
None
),
{'body': {}},
),
(
(
'PATCH', newpr.issue_url % ('rust-lang', 'rust', '1'),
{'assignee': 'davidalber'}
),
{'body': {}},
),
])
handler.new_comment()
api_req_mock.verify_calls()
Loading