Skip to content

Commit

Permalink
Merge pull request #3686 from webcompat/issue/3685/1
Browse files Browse the repository at this point in the history
Fixes #3685 - Automatically add labels for issues reopened after ML triage
  • Loading branch information
karlcow authored Apr 6, 2022
2 parents 48693e2 + 30db905 commit 301e687
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 4 additions & 2 deletions tests/unit/test_webhook_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
outreach_comment_added = ('outreach generator url added', 200, {'Content-Type': 'text/plain'}) # noqa

issue_info1 = {
'action': 'opened', 'state': 'open', 'milestoned_with': '',
'action': 'opened', 'state': 'open',
'milestoned_with': '', 'labeled_with': '',
'milestone': '', '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/', # noqa
'domain': 'www.netflix.com', 'number': 600,
'original_labels': ['action-needsmoderation'],
Expand All @@ -49,7 +50,8 @@
}

issue_info2 = {
'action': 'milestoned', 'state': 'open', 'milestoned_with': 'accepted',
'action': 'milestoned', 'state': 'open',
'milestoned_with': 'accepted', 'labeled_with': '',
'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<!-- @reported_with: web -->\n<!-- @public_url: https://github.com/webcompat/webcompat-tests/issues/1 -->\n\n**URL**: https://www.netflix.com/', # noqa
'domain': 'www.netflix.com', 'number': 600,
'original_labels': ['action-needsmoderation'],
Expand Down
34 changes: 33 additions & 1 deletion webcompat/webhooks/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class WebHookIssue:
original_labels: List[str]
milestone: str
milestoned_with: str
labeled_with: str
host_reported_from: str
html_url: str

Expand All @@ -67,6 +68,12 @@ def from_dict(cls, payload, host=None):
milestoned_with = ''
if payload.get('milestone'):
milestoned_with = payload.get('milestone')['title']

# labeled/unlabeled action
labeled_with = ''
if payload.get('label'):
labeled_with = payload.get('label')['name']

host_reported_from = ''
if host:
host_reported_from = host
Expand All @@ -78,7 +85,8 @@ def from_dict(cls, payload, host=None):
state=issue.get('state'), title=full_title,
original_labels=original_labels,
milestone=milestone, milestoned_with=milestoned_with,
host_reported_from=host_reported_from, html_url=html_url)
host_reported_from=host_reported_from, html_url=html_url,
labeled_with=labeled_with)

def close_private_issue(self):
"""Mark the private issue as closed."""
Expand Down Expand Up @@ -259,6 +267,11 @@ def classify(self):
payload_request = {'milestone': AUTOCLOSED_MILESTONE_ID}
make_request('patch', path, payload_request)

def add_bugbug_tracking_label(self, label_name):
payload = {'labels': [label_name]}
path = f'repos/{PUBLIC_REPO}/{self.number}/labels'
make_request('post', path, payload)

def process_issue_action(self):
"""Route the actions and provide different responses.
Expand Down Expand Up @@ -300,6 +313,25 @@ def process_issue_action(self):
return oops()
else:
return make_response('outreach generator url added', 200)
elif (self.action == 'milestoned' and scope == 'public' and
self.milestoned_with in ('needsdiagnosis', 'moved')):
try:
if 'bugbug-reopened' in self.original_labels:
self.add_bugbug_tracking_label('bugbug-valid')
except HTTPError as e:
msg_log(f'bugbug-valid labeling failed ({e})', self.number)
return oops()
else:
return make_response('bugbug-valid label added', 200)
elif (self.action == 'unlabeled' and scope == 'public' and
self.labeled_with == 'bugbug-probability-high'):
try:
self.add_bugbug_tracking_label('bugbug-reopened')
except HTTPError as e:
msg_log(f'bugbug-reopen labeling failed ({e})', self.number)
return oops()
else:
return make_response('bugbug-reopen label added', 200)
elif self.action == 'opened' and scope == 'private':
# webcompat-bot needs to comment public URL of the issue
# and we try to classify the issue using bugbug
Expand Down

0 comments on commit 301e687

Please sign in to comment.