From cde00966f8d1b20085a1c375547c86d146e5ad8e Mon Sep 17 00:00:00 2001 From: Ksenia Berezina Date: Tue, 26 Jan 2021 14:54:55 -0500 Subject: [PATCH] Fixes #3522: Fix outreach comment for auth reports --- ...ic_milestone_needscontact_auth_report.json | 48 +++++++++++++++++++ tests/unit/test_webhook_model.py | 10 ++++ webcompat/webhooks/model.py | 4 +- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/webhooks/public_milestone_needscontact_auth_report.json diff --git a/tests/fixtures/webhooks/public_milestone_needscontact_auth_report.json b/tests/fixtures/webhooks/public_milestone_needscontact_auth_report.json new file mode 100644 index 000000000..3bb259082 --- /dev/null +++ b/tests/fixtures/webhooks/public_milestone_needscontact_auth_report.json @@ -0,0 +1,48 @@ +{ + "action": "milestoned", + "issue": { + "url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/2598", + "repository_url": "https://api.github.com/repos/webcompat/webcompat-tests", + "labels_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/2598/labels{/name}", + "comments_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/2598/comments", + "events_url": "https://api.github.com/repos/webcompat/webcompat-tests/issues/2598/events", + "html_url": "https://github.com/webcompat/webcompat-tests/issues/2598", + "id": 735747598, + "node_id": "MDU6SXNzdWU3MzU3NDc1OTg=", + "number": 2598, + "title": "bugzilla.mozilla.org - see bug description", + "state": "open", + "locked": false, + "assignee": null, + "assignees": [ + + ], + "milestone": { + "url": "https://api.github.com/repos/webcompat/webcompat-tests/milestones/3", + "html_url": "https://github.com/webcompat/webcompat-tests/milestone/3", + "labels_url": "https://api.github.com/repos/webcompat/webcompat-tests/milestones/3/labels", + "id": 2744176, + "node_id": "MDk6TWlsZXN0b25lMjc0NDE3Ng==", + "number": 3, + "title": "needscontact", + "description": "We are looking for an appropriate contact", + "open_issues": 62, + "closed_issues": 3, + "state": "open", + "created_at": "2017-09-05T03:40:35Z", + "updated_at": "2020-11-07T03:21:44Z", + "due_on": null, + "closed_at": null + }, + "comments": 0, + "created_at": "2020-11-04T01:41:16Z", + "updated_at": "2020-11-07T03:21:44Z", + "closed_at": null, + "author_association": "NONE", + "active_lock_reason": null, + "body": "\n\n\n\n**URL**: https://www.optimum.net/\n\n**Browser / Version**: Firefox 87.0\n**Operating System**: Mac OS X 10.14\n**Tested Another Browser**: Yes Chrome\n\n**Problem type**: Desktop site instead of mobile site\n**Description**: Desktop site instead of mobile site\n**Steps to Reproduce**:\nertytrw345rty v2345ty45rty 4rtytet5\n\n
\nBrowser Configuration\n\n
\n\n_From [webcompat.com](https://webcompat.com/) with ❤️_", "performed_via_github_app": null + }, + "milestone": { + "title": "needscontact" + } +} diff --git a/tests/unit/test_webhook_model.py b/tests/unit/test_webhook_model.py index 5fefaa1b9..3db79bc82 100644 --- a/tests/unit/test_webhook_model.py +++ b/tests/unit/test_webhook_model.py @@ -190,6 +190,16 @@ def test_prepare_outreach_comment(): expected_payload).get('body') +def test_prepare_outreach_comment_for_auth_report(): + """Test we prepare the right comment body.""" + expected_payload = '{"body": "[Generate outreach template](https://webcompat.com/outreach/2598)"}' # noqa + json_event, signature = event_data('public_milestone_needscontact_auth_report.json') # noqa + payload = json.loads(json_event) + issue = WebHookIssue.from_dict(payload, "https://webcompat.com/") + assert issue.prepare_outreach_comment() == json.loads( + expected_payload).get('body') + + def test_get_public_issue_number(): """Test the extraction of the issue number from the public_url.""" json_event, signature = event_data('private_issue_opened.json') diff --git a/webcompat/webhooks/model.py b/webcompat/webhooks/model.py index abe64c2b1..3562382b3 100644 --- a/webcompat/webhooks/model.py +++ b/webcompat/webhooks/model.py @@ -174,13 +174,11 @@ def prepare_public_comment(self): def prepare_outreach_comment(self): """Build the comment with a link to the outreach generator page.""" - # public issue data - public_number = self.get_public_issue_number() host = self.host_reported_from if not host: host = "https://webcompat.com/" # prepare the payload - return f'[Generate outreach template]({host}outreach/{public_number})' + return f'[Generate outreach template]({host}outreach/{self.number})' def close_public_issue(self, reason='rejected'): """Close a public issue for the given reason.