From 38ee9175859168a13258adf19f3e1b4e58329ce2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 12 2020 13:27:20 +0000 Subject: Forward the username when updating the pull-request This way the update of the PR is linked to the person who made the push which solves the bug we had where when a PR was rebased it was shown as having been rebased by the author of the PR rather than the person who actually rebased the PR. Fixes https://pagure.io/pagure/issue/4569 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/default.py b/pagure/hooks/default.py index 9fae328..9c56032 100644 --- a/pagure/hooks/default.py +++ b/pagure/hooks/default.py @@ -224,7 +224,7 @@ def send_notifications( def inform_pull_request_urls( - session, project, commits, refname, default_branch + session, project, commits, refname, default_branch, username ): """ Inform the user about the URLs to open a new pull-request or visit the existing one. @@ -260,7 +260,9 @@ def inform_pull_request_urls( seen = len(prs) != 0 for pr in prs: # Refresh the PR in the db and everywhere else where needed - pagure.lib.tasks.update_pull_request.delay(pr.uid) + pagure.lib.tasks.update_pull_request.delay( + pr.uid, username=username + ) # Link tickets with pull-requests if the commit mentions it pagure.lib.tasks.link_pr_to_ticket.delay(pr.uid) @@ -429,7 +431,12 @@ class DefaultRunner(BaseRunner): # open a new pr or review the existing one pr_uids.extend( inform_pull_request_urls( - session, project, commits, refname, default_branch + session, + project, + commits, + refname, + default_branch, + username, ) ) diff --git a/tests/test_pagure_flask_rebase.py b/tests/test_pagure_flask_rebase.py index 984c44f..c7cd980 100644 --- a/tests/test_pagure_flask_rebase.py +++ b/tests/test_pagure_flask_rebase.py @@ -227,9 +227,9 @@ class PagureRebasetests(tests.Modeltests): output_text = output.get_data(as_text=True) self.assertIn("rebased onto", output_text) repo = pagure.lib.query._get_project(self.session, "test") - # This should be pingou, but we have some bug that adds the - # rebase message as PR author instead of rebaser - self.assertEqual(repo.requests[0].comments[0].user.username, "foo") + self.assertEqual( + repo.requests[0].comments[0].user.username, "pingou" + ) def test_rebase_api_ui_logged_in_different_user(self): """ Test the rebase PR API endpoint when logged in from the UI and @@ -295,9 +295,7 @@ class PagureRebasetests(tests.Modeltests): output_text = output.get_data(as_text=True) self.assertIn("rebased onto", output_text) repo = pagure.lib.query._get_project(self.session, "test") - # This should be bar, but we have some bug that adds the - # rebase message as PR author instead of rebaser - self.assertEqual(repo.requests[0].comments[0].user.username, "foo") + self.assertEqual(repo.requests[0].comments[0].user.username, "bar") def test_rebase_api_ui_logged_in_pull_request_author(self): """ Test the rebase PR API endpoint when logged in from the UI and @@ -623,9 +621,9 @@ class PagureRebaseNotAllowedtests(tests.Modeltests): output_text = output.get_data(as_text=True) self.assertIn("rebased onto", output_text) repo = pagure.lib.query._get_project(self.session, "test") - # This should be pingou, but we have some bug that adds the - # rebase message as PR author instead of rebaser - self.assertEqual(repo.requests[0].comments[0].user.username, "foo") + self.assertEqual( + repo.requests[0].comments[0].user.username, "pingou" + ) def test_rebase_api_ui_logged_in_different_user(self): """ Test the rebase PR API endpoint when logged in from the UI and @@ -713,9 +711,7 @@ class PagureRebaseNotAllowedtests(tests.Modeltests): output_text = output.get_data(as_text=True) self.assertIn("rebased onto", output_text) repo = pagure.lib.query._get_project(self.session, "test") - # This should be bar, but we have some bug that adds the - # rebase message as PR author instead of rebaser - self.assertEqual(repo.requests[0].comments[0].user.username, "foo") + self.assertEqual(repo.requests[0].comments[0].user.username, "bar") def test_rebase_api_api_logged_in(self): """ Test the rebase PR API endpoint when using an API token and