Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Issue #3445 - Part 4. Create a common close_public_issue method
  • Loading branch information
Mike Taylor committed Aug 18, 2020
commit 9c71b101823307a9f3e06c53d78740c837dd15e1
13 changes: 6 additions & 7 deletions tests/unit/test_webhook_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ def test_closing_public_issues(mock_mr):
json_event, signature = event_data('private_issue_opened.json')
payload = json.loads(json_event)
issue = WebHookIssue.from_dict(payload)
test_functions = [issue.reject_incomplete_issue,
issue.reject_invalid_issue, issue.reject_private_issue]
for fn in test_functions:
fn()
reasons = ['incomplete', 'invalid', 'rejected']
for reason in reasons:
Comment thread
miketaylr marked this conversation as resolved.
issue.close_public_issue(reason=reason)
method, uri, data = mock_mr.call_args[0]
# make sure we sent a patch with the right data to GitHub
assert method == 'patch'
Expand Down Expand Up @@ -322,13 +321,13 @@ def test_process_issue_action_github_api_exception(mock_mr, caplog):
('new_event_valid.json', 'public:opened labels failed',
'tag_as_public'),
('private_milestone_closed.json',
'public rejection failed', 'reject_private_issue'),
'public rejection failed', 'close_public_issue'),
('private_milestone_accepted_invalid.json',
'private:closing public issue as invalid failed',
'reject_invalid_issue'),
'close_public_issue'),
('private_milestone_accepted_incomplete.json',
'private:closing public issue as incomplete failed',
'reject_incomplete_issue')
'close_public_issue')
]
for scenario in scenarios:
issue_payload, expected_log, method = scenario
Expand Down
37 changes: 16 additions & 21 deletions webcompat/webhooks/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,20 @@ def prepare_public_comment(self):
# prepare the payload
return f'[Original issue {public_number}]({self.public_url})'

def reject_incomplete_issue(self):
"""Send a passed-moderation-yet-incomplete PATCH to public issue."""
payload_request = prepare_incomplete_issue(self.title)
public_number = self.get_public_issue_number()
# Preparing the proxy request
path = f'repos/{PUBLIC_REPO}/{public_number}'
make_request('patch', path, payload_request)
def close_public_issue(self, reason='rejected'):
"""Close a public issue for the given reason.

def reject_invalid_issue(self):
"""Send a passed-moderation-yet-invalid PATCH to the public issue."""
payload_request = prepare_invalid_issue(self.title)
public_number = self.get_public_issue_number()
# Preparing the proxy request
path = f'repos/{PUBLIC_REPO}/{public_number}'
make_request('patch', path, payload_request)

def reject_private_issue(self):
"""Send a rejected moderation PATCH on the public issue."""
payload_request = prepare_rejected_issue()
Right now the accepted reasons are:
'incomplete'
'invalid'
'rejected' (default)
"""
if reason == 'incomplete':
payload_request = prepare_incomplete_issue(self.title)
elif reason == 'invalid':
payload_request = prepare_invalid_issue(self.title)
else:
payload_request = prepare_rejected_issue()
public_number = self.get_public_issue_number()
# Preparing the proxy request
path = f'repos/{PUBLIC_REPO}/{public_number}'
Expand Down Expand Up @@ -258,7 +253,7 @@ def process_issue_action(self):
elif (self.action == 'milestoned' and scope == 'private' and
self.milestoned_with == 'accepted: incomplete'):
try:
self.reject_incomplete_issue()
self.close_public_issue(reason='incomplete')
except HTTPError as e:
msg_log(
'private:closing public issue as incomplete failed',
Expand All @@ -272,7 +267,7 @@ def process_issue_action(self):
elif (self.action == 'milestoned' and scope == 'private' and
self.milestoned_with == 'accepted: invalid'):
try:
self.reject_invalid_issue()
self.close_public_issue(reason='invalid')
except HTTPError as e:
msg_log(
'private:closing public issue as invalid failed',
Expand All @@ -287,7 +282,7 @@ def process_issue_action(self):
# private issue has been closed. It is rejected
# We need to patch with a template.
try:
self.reject_private_issue()
self.close_public_issue(reason='rejected')
except HTTPError as e:
msg_log('public rejection failed', self.number)
return oops()
Expand Down