예제 #1
0
    def from_dict(cls, payload, host=None):
        """Class method to allow instantiation from a GitHub response dict."""
        # Extract the title and the body
        issue = payload['issue']
        full_title = issue.get('title', 'Weird_Title - Inspect')
        labels = issue.get('labels', [])
        issue_body = issue['body']
        domain = full_title.partition(' ')[0]
        public_url = extract_metadata(issue_body).get('public_url', '').strip()
        original_labels = [label['name'] for label in labels]
        html_url = issue.get('html_url')
        # webhook with a milestone already set
        milestone = ''
        if issue.get('milestone'):
            milestone = issue['milestone']['title']
        # webhook with a milestoned action
        milestoned_with = ''
        if payload.get('milestone'):
            milestoned_with = payload.get('milestone')['title']
        host_reported_from = ''
        if host:
            host_reported_from = host

        return cls(action=payload['action'], body=issue_body,
                   domain=domain, number=issue.get('number'),
                   public_url=public_url,
                   repository_url=issue.get('repository_url'),
                   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)
예제 #2
0
 def test_extract_metadata(self):
     """Extract dictionary of metadata for an issue body."""
     expected = {'reported_with': 'web',
                 'extra_labels': 'type-media, type-stylo',
                 'ua_header': ('Mozilla/5.0 (what) Gecko/20100101 '
                               'Firefox/55.0'),
                 'browser': 'Firefox 55.0'}
     actual = helpers.extract_metadata(self.issue_body)
     self.assertEqual(expected, actual)
예제 #3
0
 def test_extract_metadata(self):
     """Extract dictionary of metadata for an issue body."""
     expected = {'reported_with': 'web',
                 'extra_labels': 'type-media, type-stylo',
                 'ua_header': ('Mozilla/5.0 (what) Gecko/20100101 '
                               'Firefox/55.0'),
                 'browser': 'Firefox 55.0'}
     actual = helpers.extract_metadata(self.issue_body)
     self.assertEqual(expected, actual)
예제 #4
0
 def test_extract_metadata(self):
     expected = {
         'reported_with': 'web',
         'extra_label': 'type-media',
         'ua_header': ('Mozilla/5.0 (what) Gecko/20100101 '
                       'Firefox/55.0'),
         'browser': 'Firefox 55.0'
     }
     actual = helpers.extract_metadata(self.issue_body)
     self.assertEqual(expected, actual)