def test_one_label(self):
     payload = {
         "action": "opened",
         "issue": {
             "title": "New Issue",
             "assignee": {
                 "login": "******"
             },
             "labels": [
                 {
                     "name": "boog"
                 }
             ]
         },
         "sender": {
             "login": "******"
         }
     }
     event = {
         "X-Github-Event": "issues",
         "payload": payload
     }
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Issue \"New Issue\" opened by mary (Assigned to: steven, Labels: boog) <No URL Specified>"  # NOQA
     self.assertEqual(gh.irc_message, expected)
Exemplo n.º 2
0
 def test_empty_payload(self):
     payload = {}
     event = {"payload": payload}
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     self.assertEqual(gh.irc_message, "")
 def test_non_empty_url(self):
     payload = {
         "action": "opened",
         "issue": {
             "title": "New Issue",
             "assignee": {
                 "login": "******"
             },
             "html_url": "http://news.com",
             "labels": [
                 {
                     "name": "boog"
                 },
                 {
                     "name": "important"
                 }
             ]
         },
         "sender": {
             "login": "******"
         }
     }
     event = {
         "X-Github-Event": "issues",
         "payload": payload
     }
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Issue \"New Issue\" opened by mary (Assigned to: steven, Labels: boog,important) http://news.com"  # NOQA
     self.assertEqual(gh.irc_message, expected)
Exemplo n.º 4
0
 def test_process_non_gh_event(self):
     payload = {"foo": "bar"}
     event = {"payload": payload}
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     self.assertEqual(gh.irc_message, "")
Exemplo n.º 5
0
 def test_non_empty_url(self):
     payload = {
         "action": "opened",
         "issue": {
             "title": "New Issue",
             "assignee": {
                 "login": "******"
             },
             "html_url": "http://news.com",
             "labels": [{
                 "name": "boog"
             }, {
                 "name": "important"
             }]
         },
         "sender": {
             "login": "******"
         }
     }
     event = {"X-Github-Event": "issues", "payload": payload}
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Issue \"New Issue\" opened by mary (Assigned to: steven, Labels: boog,important) http://news.com"  # NOQA
     self.assertEqual(gh.irc_message, expected)
Exemplo n.º 6
0
 def test_empty_secondary_objects(self):
     payload = {"action": "", "issue": {}, "sender": {}}
     event = {"X-Github-Event": "issues", "payload": payload}
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Issue \"No Title\"  by Nobody (Assigned to: Nobody, Labels: None) <No URL Specified>"  # NOQA
     self.assertEqual(gh.irc_message, expected)
 def test_empty_payload(self):
     payload = {}
     event = {
         "payload": payload
     }
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     self.assertEqual(gh.irc_message, "")
 def test_process_non_gh_event(self):
     payload = {
         "foo": "bar"
     }
     event = {
         "payload": payload
     }
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     self.assertEqual(gh.irc_message, "")
 def test_empty_secondary_objects(self):
     payload = {
         "action": "",
         "number": "",
         "pull_request": {},
         "sender": {}
     }
     event = {"X-Github-Event": "pull_request", "payload": payload}
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Pull Request \"[No Title]\"  by Nobody <No URL Specified>"  # NOQA
     self.assertEqual(gh.irc_message, expected)
 def test_empty_secondary_objects(self):
     payload = {
         "action": "",
         "issue": {},
         "sender": {}
     }
     event = {
         "X-Github-Event": "issues",
         "payload": payload
     }
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Issue \"No Title\"  by Nobody (Assigned to: Nobody, Labels: None) <No URL Specified>"  # NOQA
     self.assertEqual(gh.irc_message, expected)
Exemplo n.º 11
0
def handle_event(event, context, resource_path):
    logger.debug("Received a request on the %s endpoint" % resource_path)
    hook = None
    if resource_path == "/github":
        hook = GithubWebhook(event, context)
    elif resource_path == "/atlas":
        hook = AtlasWebhook(event, context)
    else:
        return
    hook.process_event()
    irc_msg = hook.irc_message
    if not irc_msg:
        return
    logger.info(irc_msg)
    event.update({'irc-message': irc_msg})
    send_sns_msg(event, context)
 def test_non_empty_user(self):
     payload = {
         "action": "opened",
         "pull_request": {
             "title": "New PR"
         },
         "sender": {
             "login": "******"
         }
     }
     event = {"X-Github-Event": "pull_request", "payload": payload}
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Pull Request \"New PR\" opened by mary <No URL Specified>"  # NOQA
     self.assertEqual(gh.irc_message, expected)
Exemplo n.º 13
0
 def test_non_empty_user(self):
     payload = {
         "action": "opened",
         "issue": {
             "title": "New Issue"
         },
         "sender": {
             "login": "******"
         }
     }
     event = {"X-Github-Event": "issues", "payload": payload}
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Issue \"New Issue\" opened by mary (Assigned to: Nobody, Labels: None) <No URL Specified>"  # NOQA
     self.assertEqual(gh.irc_message, expected)
 def test_non_empty_url(self):
     payload = {
         "action": "closed",
         "pull_request": {
             "title": "New PR",
             "html_url": "http://news.com"
         },
         "sender": {
             "login": "******"
         }
     }
     event = {"X-Github-Event": "pull_request", "payload": payload}
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Pull Request \"New PR\" closed by mary http://news.com"  # NOQA
     self.assertEqual(gh.irc_message, expected)
 def test_non_empty_user(self):
     payload = {
         "action": "opened",
         "issue": {
             "title": "New Issue"
         },
         "sender": {
             "login": "******"
         }
     }
     event = {
         "X-Github-Event": "issues",
         "payload": payload
     }
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Issue \"New Issue\" opened by mary (Assigned to: Nobody, Labels: None) <No URL Specified>"  # NOQA
     self.assertEqual(gh.irc_message, expected)
Exemplo n.º 16
0
 def test_one_label(self):
     payload = {
         "action": "opened",
         "issue": {
             "title": "New Issue",
             "assignee": {
                 "login": "******"
             },
             "labels": [{
                 "name": "boog"
             }]
         },
         "sender": {
             "login": "******"
         }
     }
     event = {"X-Github-Event": "issues", "payload": payload}
     gh = GithubWebhook(event, {})
     self.assertEqual(gh.irc_message, "")
     gh.process_event()
     expected = "GitHub Issue \"New Issue\" opened by mary (Assigned to: steven, Labels: boog) <No URL Specified>"  # NOQA
     self.assertEqual(gh.irc_message, expected)