Browse Source

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.
Fabien Boucher 4 năm trước cách đây
mục cha
commit
72b4aaf06f
2 tập tin đã thay đổi với 15 bổ sung2 xóa
  1. 12 2
      pagure/hooks/default.py
  2. 3 0
      tests/test_pagure_send_notification.py

+ 12 - 2
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

+ 3 - 0
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__":