From 72b4aaf06f1f7d1cb7b07b1d9042ecce6dba5edb Mon Sep 17 00:00:00 2001 From: Fabien Boucher Date: Sep 26 2019 12:58:22 +0000 Subject: Send oldrev as old_commit for git.receive event Some events consumers like Zuul expects to find the previous rev of the tip of the branch. This commit send the oldrev part of the event's message. --- diff --git a/pagure/hooks/default.py b/pagure/hooks/default.py index 023f9b9..f9f8125 100644 --- a/pagure/hooks/default.py +++ b/pagure/hooks/default.py @@ -160,7 +160,9 @@ def send_action_notification( send_webhook_notifications(project, topic, msg) -def send_notifications(session, project, repodir, user, refname, revs, forced): +def send_notifications( + session, project, repodir, user, refname, revs, forced, oldrev +): """ Send out-going notifications about the commits that have just been pushed. """ @@ -187,6 +189,7 @@ def send_notifications(session, project, repodir, user, refname, revs, forced): total_commits=len(revs), start_commit=revs[0], end_commit=revs[-1], + old_commit=oldrev, branch=refname, forced=forced, authors=list(authors), @@ -402,7 +405,14 @@ class DefaultRunner(BaseRunner): # This one is sending fedmsg and web-hook notifications for project # that set them up send_notifications( - session, project, repodir, username, refname, commits, forced + session, + project, + repodir, + username, + refname, + commits, + forced, + oldrev, ) # Now display to the user if this isn't the default branch links to diff --git a/tests/test_pagure_send_notification.py b/tests/test_pagure_send_notification.py index 7ea884b..f0de5b7 100644 --- a/tests/test_pagure_send_notification.py +++ b/tests/test_pagure_send_notification.py @@ -62,6 +62,7 @@ class PagureHooksDefault(tests.SimplePagureTest): @mock.patch("pagure.hooks.default.send_fedmsg_notifications") def test_send_notifications(self, fedmsg): + oldrev = "9e5f51c951c6cab20fe81419320ed740533e2f2f" project, sha = self.init_test_repo() pagure.hooks.default.send_notifications( self.session, @@ -71,12 +72,14 @@ class PagureHooksDefault(tests.SimplePagureTest): "master", [sha], False, + oldrev, ) (_, args, kwargs) = fedmsg.mock_calls[0] self.assertEqual(args[1], "git.receive") self.assertEqual(args[2]["repo"]["name"], "test") self.assertEqual(args[2]["start_commit"], sha) self.assertEqual(args[2]["forced"], False) + self.assertEqual(args[2]["old_commit"], oldrev) if __name__ == "__main__":