def pull_request(data, _guid):
    """
    Handle a pull request webhook and notify the reviewer on slack.

    This will validate the request making sure it is an action that is written to be handled,
    then will kick off apropriate actions for the hook such as sending slack notifications
    to the requested reviewer.
    """

    if is_valid_pull_request(data):
        notify_recipient(data)
        result = 'Recipient Notified'
    else:
        result = 'Action ({}) ignored'.format(data.get('action'))

    return result
 def test_is_valid_pull_request_different_action(self):
     """ Test with non matched action """
     data = self.valid_request.copy()
     data['action'] = 'generic_action'
     is_valid_request = is_valid_pull_request(data)
     self.assertFalse(is_valid_request)
 def test_is_valid_pull_request_missing_html_url(self):
     """ Test with missing html_url on pull_request dict """
     with self.assertRaises(BadRequest):
         data = self.valid_request.copy()
         data['pull_request'] = {}
         is_valid_pull_request(data)
 def test_is_valid_pull_request_missing_pulL_request(self):
     """ Test with missing pull_request dict """
     with self.assertRaises(BadRequest):
         data = self.valid_request.copy()
         del data['pull_request']
         is_valid_pull_request(data)
 def test_is_valid_pull_request_missing_action(self):
     """ Test with missing action """
     with self.assertRaises(BadRequest):
         data = self.valid_request.copy()
         del data['action']
         is_valid_pull_request(data)
 def test_is_valid_pull_request_good(self):
     """ Test a good is_valid_pull_request. """
     is_valid_request = is_valid_pull_request(self.valid_request)
     self.assertTrue(is_valid_request)
Ejemplo n.º 7
0
 def test_is_valid_pull_request_from_ignored_users(self):
     """ Test with non matched action """
     data = self.valid_request.copy()
     data['sender']['login'] = '******'
     is_valid_request = is_valid_pull_request(data)
     self.assertFalse(is_valid_request)