def test_deletion(self): git_obj = github_parse( {"X-GitHub-Event": "delete"}, self.deletion ) self.assertIsInstance(git_obj, Deletion) self.assertEqual(git_obj.branch, "deleted")
def run(self): self.start_webserver() self.start_ircbot() while True: (headers, body) = self.hooks_queue.get() hook = json.loads(body) try: git_obj = None if 'X-GitHub-Event' in headers.keys(): git_obj = github_parse(headers, hook) else: git_obj = gitlab_parse(hook) if git_obj is not None: self.text_queue.put(("prnt", { "message": git_obj.render_irccolors() })) except: if self.config.report_errors: for line in format_exc().split('\n'): if line: self.text_queue.put(("prnt", { "message": line, "chans": [self.config.report_errors] }))
def run(self): self.start_webserver() self.start_ircbot() while True: (headers, body) = self.hooks_queue.get() hook = json.loads(body) try: git_obj = None if 'X-GitHub-Event' in headers.keys(): git_obj = github_parse(headers, hook) else: git_obj = gitlab_parse(hook) if git_obj is not None: self.text_queue.put(( "prnt", {"message": git_obj.render_irccolors()} )) except: if self.config.report_errors: for line in format_exc().split('\n'): if line: self.text_queue.put(( "prnt", { "message": line, "chans": [self.config.report_errors] } ))
def test_creation(self): git_obj = github_parse( {"X-GitHub-Event": "create"}, self.creation ) self.assertIsInstance(git_obj, Creation) self.assertEqual(git_obj.branch, "new") self.assertEqual( git_obj.url, "https://github.com/baxterthehacker/public-repo/tree/new" )
def test_wiki(self): git_obj = github_parse( {"X-GitHub-Event": "gollum"}, self.wiki ) self.assertIsInstance(git_obj, Wiki) self.assertEqual(len(git_obj.wiki_pages), 1) page = git_obj.wiki_pages[0] self.assertIsInstance(page, WikiPage) self.assertEqual(page.title, "Home") self.assertEqual(page.page_name, "Home") self.assertEqual(page.action, "created")
def test_issue(self): git_obj = github_parse( {"X-GitHub-Event": "issues"}, self.issue ) self.assertIsInstance(git_obj, Issue) self.assertEqual(git_obj.id, 73464126) self.assertEqual(git_obj.title, "Spelling error in the README file") self.assertEqual(git_obj.action, "opened") self.assertEqual( git_obj.url, "https://api.github.com/repos/baxterthehacker/public-repo/issues/2" )
def test_push(self): git_obj = github_parse( {"X-GitHub-Event": "push"}, self.push ) self.assertIsInstance(git_obj, Push) self.assertEqual(git_obj.branch, "changes") self.assertEqual( git_obj.url, "https://github.com/baxterthehacker/public-repo/compare/" "9049f1265b7d...0d1a26e67d8f" ) self.assertEqual(len(git_obj.commits), 1)
def test_merge_request(self): git_obj = github_parse( {"X-GitHub-Event": "pull_request"}, self.merge_request ) self.assertIsInstance(git_obj, MergeRequest) self.assertEqual(git_obj.id, 34778301) self.assertEqual( git_obj.title, "Update the README with new information" ) self.assertEqual(git_obj.action, "opened") self.assertEqual( git_obj.url, "https://github.com/baxterthehacker/public-repo/pull/1" )
("pull_request", "merge_request.json")] def demo_from_inputs(namespace, inputs, parser): for name, filename in inputs: data = None with open(os.path.join(DATA_DIR, namespace, filename), "r") as file: data = json.load(file) print("=> {}".format(name)) git_obj = parser(name, data) print(git_obj.render_simple(), end="\n\n") if __name__ == "__main__": # GitLab print("====================") print("=== GitLab Hooks ===") print("====================") print("") demo_from_inputs("gitlab", GITLAB_INPUTS, lambda name, hook: gitlab_parse(hook)) # GitHub print("====================") print("=== GitHub Hooks ===") print("====================") print("") demo_from_inputs( "github", GITHUB_INPUTS, lambda name, hook: github_parse({"X-GitHub-Event": name}, hook))