Beispiel #1
0
    def close_public_issue(self, reason='rejected'):
        """Close a public issue for the given reason.

        Right now the accepted reasons are:
        'incomplete'
        'invalid'
        'autoclosed'
        'rejected' (default)
        """
        if reason == 'incomplete':
            payload_request = self.prepare_accepted_issue('incomplete')
        elif reason == 'invalid':
            payload_request = self.prepare_accepted_issue('invalid')
        elif reason == 'autoclosed':
            payload_request = prepare_rejected_issue(reason)
            # We add the private issue link to the body of the public issue,
            # and it will be used to make a request during ml data fetching
            # as public issue will no longer have relevant issue data
            payload_request['body'] += prepare_private_url(self.html_url)
        else:
            payload_request = prepare_rejected_issue()
        public_number = self.get_public_issue_number()
        # Preparing the proxy request
        path = f'repos/{PUBLIC_REPO}/{public_number}'
        make_request('patch', path, payload_request)
Beispiel #2
0
    def tag_as_public(self):
        """Set the core actions on new opened issues.

        When a new issue is opened, we set a couple of things.

        - Browser label
        - Priority label
        - Issue milestone
        - Any "extra" labels, set from GET params

        Then Send a GitHub PATCH to set labels and milestone for the issue.

        PATCH /repos/:owner/:repo/issues/:number
        {
            "milestone": 2,
            "labels": ['Label1', 'Label2']
        }
        """
        # Grabs the labels already set so they will not be erased
        # Gets the labels from the body
        labels = get_issue_labels(self.body)
        labels.extend(self.original_labels)
        self.milestone = app.config['STATUSES']['needstriage']['id']
        # Preparing the proxy request to the public repo
        path = f'repos/{PUBLIC_REPO}/{self.number}'
        payload_request = {'labels': labels, 'milestone': self.milestone}
        make_request('patch', path, payload_request)
Beispiel #3
0
 def comment_outreach_generator_uri(self):
     """Publish a comment on the public issue with outreach uri."""
     comment = self.prepare_outreach_comment()
     payload = {'body': comment}
     # Preparing the proxy request
     path = f'repos/{PUBLIC_REPO}/{self.number}/comments'
     make_request('post', path, payload)
Beispiel #4
0
 def comment_public_uri(self):
     """Publish a comment on the private issue with the public uri."""
     comment = self.prepare_public_comment()
     payload = {'body': comment}
     # Preparing the proxy request
     path = f'repos/{PRIVATE_REPO}/{self.number}/comments'
     make_request('post', path, payload)
Beispiel #5
0
 def comment_closed_reason(self, reason):
     """Publish a comment on the public issue about why it was closed."""
     if reason in ['invalid', 'incomplete']:
         comment = moderation_template(reason).get('body')
     else:
         raise ValueError("reason must be one of invalid or incomplete")
     payload = {'body': comment}
     issue_number = self.get_public_issue_number()
     path = f'repos/{PUBLIC_REPO}/{issue_number}/comments'
     make_request('post', path, payload)
Beispiel #6
0
 def close_private_issue(self):
     """Mark the private issue as closed."""
     path = f'repos/{PRIVATE_REPO}/{self.number}'
     try:
         make_request('patch', path, {'state': 'closed'})
     except HTTPError as e:
         # pass the error up to process_issue_action
         raise e
     else:
         self.state = 'closed'
Beispiel #7
0
    def classify(self):
        """Make a request to bugbug and add a milestone to the issue.

        Gets issue classification from bugbug and adds a milestone
        to the issue if probability is high
        """
        data = get_issue_classification(self.number)
        needsdiagnosis_false = data.get('class')
        proba = data.get('prob')

        if needsdiagnosis_false and proba and proba[1] > THRESHOLD:
            path = f'repos/{PRIVATE_REPO}/{self.number}'
            payload_request = {'milestone': AUTOCLOSED_MILESTONE_ID}
            make_request('patch', path, payload_request)
Beispiel #8
0
    def classify(self):
        """Make a request to bugbug and label the issue.

        Gets issue classification from bugbug and labels
        the issue if probability is high
        """
        data = get_issue_classification(self.number)
        needsdiagnosis_false = data.get('class')
        proba = data.get('prob')

        if needsdiagnosis_false and proba and proba[1] > THRESHOLD:
            payload = {'labels': ['bugbug-probability-high']}
            path = f'repos/{PRIVATE_REPO}/{self.number}/labels'
            make_request('post', path, payload)
Beispiel #9
0
    def close_public_issue(self, reason='rejected'):
        """Close a public issue for the given reason.

        Right now the accepted reasons are:
        'incomplete'
        'invalid'
        'rejected' (default)
        """
        if reason == 'incomplete':
            payload_request = self.prepare_accepted_issue('incomplete')
        elif reason == 'invalid':
            payload_request = self.prepare_accepted_issue('invalid')
        else:
            payload_request = prepare_rejected_issue()
        public_number = self.get_public_issue_number()
        # Preparing the proxy request
        path = f'repos/{PUBLIC_REPO}/{public_number}'
        make_request('patch', path, payload_request)
Beispiel #10
0
    def moderate_private_issue(self):
        """Write the private issue in public.

        Send a GitHub PATCH to set labels and milestone for the issue.

        PATCH /repos/:owner/:repo/issues/:number
        {
            "title": "a string for the title",
            "body": "the full body",
            "labels": ['Label1', 'Label2'],
        }

        Milestone should be already set on needstriage

        we get the destination through the public_url.
        """
        payload_request = self.prepare_accepted_issue()
        public_number = self.get_public_issue_number()
        # Preparing the proxy request
        path = f'repos/{PUBLIC_REPO}/{public_number}'
        make_request('patch', path, payload_request)