示例#1
0
 def test_get_milestoned_issue_info(self):
     """Extract the right information for a milestoned issue."""
     json_event, signature = event_data('private_milestone_accepted.json')
     payload = json.loads(json_event)
     expected = self.issue_info2
     actual = helpers.get_issue_info(payload)
     self.assertDictEqual(expected, actual)
示例#2
0
 def test_get_issue_info(self):
     """Extract the right information from an issue."""
     json_event, signature = event_data('new_event_invalid.json')
     payload = json.loads(json_event)
     expected = self.issue_info1
     actual = helpers.get_issue_info(payload)
     self.assertDictEqual(expected, actual)
示例#3
0
def hooklistener():
    """Listen for the "issues" webhook event.

    By default, we return a 403 HTTP response.
    """
    if not is_github_hook(request):
        return ('Nothing to see here', 401, {'Content-Type': 'text/plain'})
    payload = json.loads(request.data)
    event_type = request.headers.get('X-GitHub-Event')

    # Treating events related to issues
    if event_type == 'issues':
        issue = get_issue_info(payload)
        # A new issue has been created.
        # In the future we can add new type of actions.
        if issue['action'] == 'opened':
            # we are setting labels on each new open issues
            response = new_opened_issue(payload)
            if response.status_code == 200:
                return ('gracias, amigo.', 200, {'Content-Type': 'text/plain'})
            else:
                log = app.logger
                log.setLevel(logging.INFO)
                msg = 'failed to set labels on issue {issue}'.format(
                    issue=issue['number'])
                log.info(msg)
                return ('ooops', 400, {'Content-Type': 'text/plain'})
    elif event_type == 'ping':
        return ('pong', 200, {'Content-Type': 'text/plain'})
    # If nothing worked as expected, the default response is 403.
    return ('Not an interesting hook', 403, {'Content-Type': 'text/plain'})
示例#4
0
 def test_get_issue_info(self):
     """Extract the right information from an issue."""
     json_event, signature = event_data('new_event_invalid.json')
     payload = json.loads(json_event)
     expected = {'number': 600,
                 'action': 'foobar',
                 'domain': 'www.chia-anime.tv'}
     actual = helpers.get_issue_info(payload)
     self.assertDictEqual(expected, actual)
示例#5
0
 def test_get_issue_info(self):
     """Extract the right information from an issue."""
     json_event, signature = event_data('new_event_invalid.json')
     payload = json.loads(json_event)
     expected = {'number': 600,
                 'action': 'foobar',
                 'domain': 'www.chia-anime.tv'}
     actual = helpers.get_issue_info(payload)
     self.assertDictEqual(expected, actual)
示例#6
0
 def test_tag_new_public_issue(self):
     """Test the core actions on new opened issues for WebHooks."""
     # A 200 response
     json_event, signature = event_data('new_event_valid.json')
     payload = json.loads(json_event)
     issue_info = helpers.get_issue_info(payload)
     with patch('webcompat.webhooks.helpers.proxy_request') as proxy:
         proxy.return_value.status_code = 200
         response = helpers.tag_new_public_issue(issue_info)
         self.assertEqual(response.status_code, 200)
         # A 401 response
         proxy.return_value.status_code = 401
         proxy.return_value.content = '{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}'  # noqa
         with patch.dict('webcompat.webhooks.helpers.app.config',
                         {'OAUTH_TOKEN': ''}):
             response = helpers.tag_new_public_issue(issue_info)
             self.assertEqual(response.status_code, 401)
             self.assertTrue('Bad credentials' in response.content)
示例#7
0
def hooklistener():
    """Listen for the "issues" webhook event.

    By default, we return a 403 HTTP response.
    """
    # webcompat/webcompat-tests/issues
    if not is_github_hook(request):
        return ('Nothing to see here', 401, {'Content-Type': 'text/plain'})
    payload = json.loads(request.data)
    event_type = request.headers.get('X-GitHub-Event')
    # Treating events related to issues
    if event_type == 'issues':
        issue_info = get_issue_info(payload)
        # we process the action
        response = process_issue_action(issue_info)
        return response
    elif event_type == 'ping':
        return ('pong', 200, {'Content-Type': 'text/plain'})
    # If nothing worked as expected, the default response is 403.
    return ('Not an interesting hook', 403, {'Content-Type': 'text/plain'})