Skip to content

Commit

Permalink
Merge pull request #3200 from karlcow/3197/1
Browse files Browse the repository at this point in the history
fixes #3197 - Adds fencing on accepted issues being closed in private
  • Loading branch information
Mike Taylor committed Feb 12, 2020
2 parents 94d0eec + bb6720f commit 136607e
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 6 deletions.
19 changes: 18 additions & 1 deletion tests/fixtures/webhooks/private_milestone_accepted.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,24 @@
"description": "issue in the process of being moderated"
}
],
"state": "open"
"state": "open",
"milestone": {
"url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/2",
"html_url": "https://github.com/webcompat/webcompat-tests-private/milestone/2",
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/2/labels",
"id": 5092463,
"node_id": "MDk6TWlsZXN0b25lNTA5MjQ2Mw==",
"number": 2,
"title": "accepted",
"description": "This is when a bug has been accepted for moderation",
"open_issues": 0,
"closed_issues": 2,
"state": "open",
"created_at": "2020-02-11T00:37:18Z",
"updated_at": "2020-02-11T18:34:04Z",
"due_on": null,
"closed_at": null
}
},
"milestone": {
"title": "accepted"
Expand Down
47 changes: 47 additions & 0 deletions tests/fixtures/webhooks/private_milestone_accepted_closed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"action": "closed",
"issue": {
"url": "https://api.github.com/repos/webcompat/webcompat-tests-private/issues/600",
"repository_url": "https://api.github.com/repos/webcompat/webcompat-tests-private",
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests-private/issues/600/labels{/name}",
"comments_url": "https://api.github.com/repos/webcompat/webcompat-tests-private/issues/600/comments",
"events_url": "https://api.github.com/repos/webcompat/webcompat-tests-private/issues/600/events",
"html_url": "https://github.com/webcompat/webcompat-tests-private/issues/600",
"id": 563394454,
"node_id": "MDU6SXNzdWU1NjMzOTQ0NTQ=",
"number": 600,
"title": "www.netflix.com - test private issue accepted",
"labels": [

],
"state": "closed",
"locked": false,
"assignee": null,
"assignees": [

],
"milestone": {
"url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/2",
"html_url": "https://github.com/webcompat/webcompat-tests-private/milestone/2",
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/2/labels",
"id": 5092463,
"node_id": "MDk6TWlsZXN0b25lNTA5MjQ2Mw==",
"number": 2,
"title": "accepted",
"description": "This is when a bug has been accepted for moderation",
"open_issues": 0,
"closed_issues": 2,
"state": "open",
"created_at": "2020-02-11T00:37:18Z",
"updated_at": "2020-02-11T18:34:04Z",
"due_on": null,
"closed_at": null
},
"comments": 0,
"created_at": "2020-02-11T18:28:46Z",
"updated_at": "2020-02-11T18:34:04Z",
"closed_at": "2020-02-11T18:34:04Z",
"author_association": "COLLABORATOR",
"body": "<!-- @browser: Firefox 55.0 -->\n<!-- @ua_header: Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0 -->\n<!-- @reported_with: web -->\n<!-- @public_url: https://github.com/webcompat/webcompat-tests/issues/1 -->\n\n**URL**: https://www.netflix.com/"
}
}
35 changes: 31 additions & 4 deletions tests/fixtures/webhooks/private_milestone_closed.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,36 @@
"description": "issue in the process of being moderated"
}
],
"state": "closed"
},
"milestone": {
"title": "needstriage"
"state": "closed",
"milestone": {
"url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/1",
"html_url": "https://github.com/webcompat/webcompat-tests-private/milestone/1",
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/1/labels",
"id": 4995253,
"node_id": "MDk6TWlsZXN0b25lNDk5NTI1Mw==",
"number": 1,
"title": "unmoderated",
"description": "The default milestone. These issues may not be made public until they are determined to not violate terms of use.",
"creator": {
"login": "miketaylr",
"id": 67283,
"node_id": "MDQ6VXNlcjY3Mjgz",
"avatar_url": "https://avatars1.githubusercontent.com/u/67283?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/miketaylr",
"html_url": "https://github.com/miketaylr",
"followers_url": "https://api.github.com/users/miketaylr/followers",
"following_url": "https://api.github.com/users/miketaylr/following{/other_user}",
"gists_url": "https://api.github.com/users/miketaylr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/miketaylr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/miketaylr/subscriptions",
"organizations_url": "https://api.github.com/users/miketaylr/orgs",
"repos_url": "https://api.github.com/users/miketaylr/repos",
"events_url": "https://api.github.com/users/miketaylr/events{/privacy}",
"received_events_url": "https://api.github.com/users/miketaylr/received_events",
"type": "User",
"site_admin": false
}
}
}
}
29 changes: 29 additions & 0 deletions tests/unit/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def setUp(self):
'action': 'milestoned',
'state': 'open',
'milestoned_with': 'accepted',
'milestone': 'accepted',
'body': '<!-- @browser: Firefox 55.0 -->\n'
'<!-- @ua_header: Mozilla/5.0 (X11; Linux x86_64; rv:55.0) '
'Gecko/20100101 Firefox/55.0 -->\n'
Expand Down Expand Up @@ -542,6 +543,34 @@ def test_patch_not_acceptable_issue(self, mock_proxy):
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.content_type, 'text/plain')

@patch('webcompat.webhooks.helpers.private_issue_rejected')
def test_patch_acceptable_issue_closed(self, mock_proxy):
"""Test for accepted issues being closed.
payload: 'Not an interesting hook'
status: 403
content-type: text/plain
An accepted issue, which is being closed, should
not modify the public issue.
"""
json_event, signature = event_data(
'private_milestone_accepted_closed.json')
headers = {
'X-GitHub-Event': 'issues',
'X-Hub-Signature': signature,
}
with webcompat.app.test_client() as c:
mock_proxy.return_value.status_code = 200
rv = c.post(
'/webhooks/labeler',
data=json_event,
headers=headers
)
self.assertEqual(rv.data, b'Not an interesting hook')
self.assertEqual(rv.status_code, 403)
self.assertEqual(rv.content_type, 'text/plain')

@patch('webcompat.webhooks.helpers.private_issue_moderation')
def test_patch_wrong_repo_for_moderation(self, mock_proxy):
"""Test for issues in the wrong repo.
Expand Down
7 changes: 6 additions & 1 deletion webcompat/webhooks/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ def get_issue_info(payload):
# If labels on the original issue, we need them.
original_labels = [label['name'] for label in labels]
issue_info['original_labels'] = original_labels
# webhook with a milestone already set
if issue.get('milestone'):
issue_info['milestone'] = issue['milestone']['title']
# webhook with a milestoned action
if payload.get('milestone'):
issue_info['milestoned_with'] = payload.get('milestone')['title']
Expand Down Expand Up @@ -272,7 +275,9 @@ def process_issue_action(issue_info):
else:
msg_log('private:moving to public failed', issue_number)
return ('ooops', 400, {'Content-Type': 'text/plain'})
elif (scope == 'private' and issue_info['state'] == 'closed'):
elif (scope == 'private' and
issue_info['state'] == 'closed' and
not issue_info['milestone'] == 'accepted'):
# private issue has been closed. It is rejected
# We need to patch with a template.
response = private_issue_rejected(issue_info)
Expand Down

0 comments on commit 136607e

Please sign in to comment.