From 8ed510d99c9fbe3736c96b751d567891cbad343a Mon Sep 17 00:00:00 2001 From: Nikola Forró Date: Mar 27 2024 01:04:52 +0000 Subject: Add pull request ID to push notification payload Signed-off-by: Nikola Forró --- diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index c31e935..24544dc 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -62,7 +62,15 @@ class BaseRunner(object): @classmethod def runhook( - cls, session, username, hooktype, project, repotype, repodir, changes + cls, + session, + username, + hooktype, + project, + repotype, + repodir, + changes, + pull_request, ): """Run a specific hook on a project. @@ -81,6 +89,8 @@ class BaseRunner(object): changes (dict): A dict with keys being the ref to update, values being a tuple of (from, to). For example: {'refs/heads/master': (hash_from, hash_to), ...} + pull_request (model.PullRequest or None): The pull request whose + merge is initiating this hook run. """ if hooktype == "pre-receive": cls.pre_receive( @@ -90,6 +100,7 @@ class BaseRunner(object): repotype=repotype, repodir=repodir, changes=changes, + pull_request=pull_request, ) elif hooktype == "update": cls.update( @@ -99,6 +110,7 @@ class BaseRunner(object): repotype=repotype, repodir=repodir, changes=changes, + pull_request=pull_request, ) elif hooktype == "post-receive": @@ -109,12 +121,15 @@ class BaseRunner(object): repotype=repotype, repodir=repodir, changes=changes, + pull_request=pull_request, ) else: raise ValueError('Invalid hook type "%s"' % hooktype) @staticmethod - def pre_receive(session, username, project, repotype, repodir, changes): + def pre_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the pre-receive tasks of a hook. For args, see BaseRunner.runhook. @@ -122,7 +137,9 @@ class BaseRunner(object): pass @staticmethod - def update(session, username, project, repotype, repodir, changes): + def update( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the update tasks of a hook. For args, see BaseRunner.runhook. @@ -131,7 +148,9 @@ class BaseRunner(object): pass @staticmethod - def post_receive(session, username, project, repotype, repodir, changes): + def post_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the post-receive tasks of a hook. For args, see BaseRunner.runhook. @@ -384,6 +403,7 @@ def run_project_hooks( repotype=repotype, repodir=repodir, changes=changes, + pull_request=pull_request, ) except Exception as e: if hooktype != "pre-receive" or debug: diff --git a/pagure/hooks/default.py b/pagure/hooks/default.py index 2074f1e..fbda401 100644 --- a/pagure/hooks/default.py +++ b/pagure/hooks/default.py @@ -163,7 +163,7 @@ def send_action_notification( def send_notifications( - session, project, repodir, user, refname, revs, forced, oldrev + session, project, repodir, user, refname, revs, forced, oldrev, pr_id ): """Send out-going notifications about the commits that have just been pushed. @@ -212,6 +212,7 @@ def send_notifications( repo=project.to_json(public=True) if not isinstance(project, six.string_types) else project, + pull_request_id=pr_id, ) # Send blink notification to any 3rd party plugins, if there are any @@ -313,7 +314,9 @@ class DefaultRunner(BaseRunner): """Runner for the default hook.""" @staticmethod - def post_receive(session, username, project, repotype, repodir, changes): + def post_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the default post-receive hook. For args, see BaseRunner.runhook. @@ -442,6 +445,7 @@ class DefaultRunner(BaseRunner): commits, forced, oldrev, + pull_request.id if pull_request else None, ) # Now display to the user if this isn't the default branch links to diff --git a/pagure/hooks/mail.py b/pagure/hooks/mail.py index 5e215e7..f7c503f 100644 --- a/pagure/hooks/mail.py +++ b/pagure/hooks/mail.py @@ -70,7 +70,9 @@ class MailForm(FlaskForm): class MailRunner(BaseRunner): @staticmethod - def post_receive(session, username, project, repotype, repodir, changes): + def post_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the multimail post-receive hook. For args, see BaseRunner.runhook. diff --git a/pagure/hooks/mirror_hook.py b/pagure/hooks/mirror_hook.py index d4dffb1..f0bd47d 100644 --- a/pagure/hooks/mirror_hook.py +++ b/pagure/hooks/mirror_hook.py @@ -67,7 +67,9 @@ class MirrorRunner(BaseRunner): """Runner for the mirror hook.""" @staticmethod - def post_receive(session, username, project, repotype, repodir, changes): + def post_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the default post-receive hook. For args, see BaseRunner.runhook. diff --git a/pagure/hooks/pagure_force_commit.py b/pagure/hooks/pagure_force_commit.py index a8a818e..313021a 100644 --- a/pagure/hooks/pagure_force_commit.py +++ b/pagure/hooks/pagure_force_commit.py @@ -63,7 +63,9 @@ class PagureForceCommitRunner(BaseRunner): """Runner for the hook blocking force push.""" @staticmethod - def pre_receive(session, username, project, repotype, repodir, changes): + def pre_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the pre-receive tasks of a hook. For args, see BaseRunner.runhook. diff --git a/pagure/hooks/pagure_hook.py b/pagure/hooks/pagure_hook.py index 7e9f3f2..c401a71 100644 --- a/pagure/hooks/pagure_hook.py +++ b/pagure/hooks/pagure_hook.py @@ -214,7 +214,9 @@ class PagureRunner(BaseRunner): """Runner for the pagure's specific git hook.""" @staticmethod - def post_receive(session, username, project, repotype, repodir, changes): + def post_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the default post-receive hook. For args, see BaseRunner.runhook. diff --git a/pagure/hooks/pagure_no_new_branches.py b/pagure/hooks/pagure_no_new_branches.py index 3c02754..dadc8fb 100644 --- a/pagure/hooks/pagure_no_new_branches.py +++ b/pagure/hooks/pagure_no_new_branches.py @@ -59,7 +59,9 @@ class PagureNoNewBranchRunner(BaseRunner): """Runner for the hook blocking new branches from being created.""" @staticmethod - def pre_receive(session, username, project, repotype, repodir, changes): + def pre_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the pre-receive tasks of a hook. For args, see BaseRunner.runhook. diff --git a/pagure/hooks/pagure_request_hook.py b/pagure/hooks/pagure_request_hook.py index c3533a4..646dc51 100644 --- a/pagure/hooks/pagure_request_hook.py +++ b/pagure/hooks/pagure_request_hook.py @@ -64,7 +64,9 @@ class PagureRequestRunner(BaseRunner): """ @staticmethod - def post_receive(session, username, project, repotype, repodir, changes): + def post_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the default post-receive hook. For args, see BaseRunner.runhook. diff --git a/pagure/hooks/pagure_ticket_hook.py b/pagure/hooks/pagure_ticket_hook.py index 085b75f..69dec93 100644 --- a/pagure/hooks/pagure_ticket_hook.py +++ b/pagure/hooks/pagure_ticket_hook.py @@ -65,7 +65,9 @@ class PagureTicketRunner(BaseRunner): """Runner for the git hook updating the DB of tickets on push.""" @staticmethod - def post_receive(session, username, project, repotype, repodir, changes): + def post_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the post-receive tasks of a hook. For args, see BaseRunner.runhook. diff --git a/pagure/hooks/pagure_unsigned_commits.py b/pagure/hooks/pagure_unsigned_commits.py index 09b89da..99ba714 100644 --- a/pagure/hooks/pagure_unsigned_commits.py +++ b/pagure/hooks/pagure_unsigned_commits.py @@ -64,7 +64,9 @@ class PagureUnsignerRunner(BaseRunner): """Runner for the hook blocking unsigned commits.""" @staticmethod - def pre_receive(session, username, project, repotype, repodir, changes): + def pre_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Run the pre-receive tasks of a hook. For args, see BaseRunner.runhook. diff --git a/pagure/hooks/rtd.py b/pagure/hooks/rtd.py index e313d2b..75b9be9 100644 --- a/pagure/hooks/rtd.py +++ b/pagure/hooks/rtd.py @@ -101,7 +101,9 @@ will have to provide below. class RtdRunner(BaseRunner): @staticmethod - def post_receive(session, username, project, repotype, repodir, changes): + def post_receive( + session, username, project, repotype, repodir, changes, pull_request + ): """Perform the RTD Post Receive hook. For arguments, see BaseRunner.runhook. diff --git a/tests/test_pagure_send_notification.py b/tests/test_pagure_send_notification.py index 0b04c0b..973cd8f 100644 --- a/tests/test_pagure_send_notification.py +++ b/tests/test_pagure_send_notification.py @@ -74,6 +74,7 @@ class PagureHooksDefault(tests.SimplePagureTest): [sha], False, oldsha, + None, ) (_, args, kwargs) = fedmsg.mock_calls[0] self.assertEqual(args[1], "git.receive") @@ -88,6 +89,7 @@ class PagureHooksDefault(tests.SimplePagureTest): "folder1/folder2/fileŠ": "A", }, ) + self.assertIsNone(args[2]["pull_request_id"]) if __name__ == "__main__":