From e3551794872472864dd66adba3e587a9abd156b6 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Nov 05 2022 17:31:29 +0000 Subject: Fix object of "rebased onto" comment When you rebase a pull request, you get an automatic comment that says "rebased onto ". However, the commit ID is always the first commit of the pull request, not the commit ID it was actually rebased onto. e.g. in https://pagure.io/fedora-qa/relval/pull-request/21 right now the most recent message is "rebased onto 0fe88a2", and the first commit in the PR series is "Cleanup unreachble code for coverage reasons.", 0fe88a2. I think this should make it correct. Signed-off-by: Adam Williamson --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 5c41441..913de33 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -2271,7 +2271,7 @@ def diff_pull_request( _log.debug("pagure.lib.git.diff_pull_request, started") diff = None diff_commits = [] - diff, diff_commits, _ = get_diff_info( + diff, diff_commits, orig_commit = get_diff_info( repo_obj, orig_repo, request.branch_from, @@ -2317,7 +2317,10 @@ def diff_pull_request( and request.commit_start != first_commit.oid.hex ): pr_action = "rebased" - commenttext = "rebased onto %s" % first_commit.oid.hex + if orig_commit: + commenttext = "rebased onto %s" % orig_commit.oid.hex + else: + commenttext = "rebased onto unknown target" request.commit_start = first_commit.oid.hex request.commit_stop = diff_commits[0].oid.hex session.add(request) diff --git a/tests/test_pagure_flask_rebase.py b/tests/test_pagure_flask_rebase.py index ca40101..307ddb5 100644 --- a/tests/test_pagure_flask_rebase.py +++ b/tests/test_pagure_flask_rebase.py @@ -18,6 +18,7 @@ import os import json import pagure_messages +import pygit2 from fedora_messaging import api, testing from mock import ANY, patch, MagicMock @@ -249,7 +250,12 @@ class PagureRebasetests(PagureRebaseBasetests): output = self.app.get("/test/pull-request/1") self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) - self.assertIn("rebased onto", output_text) + orig_repo_obj = pygit2.Repository( + os.path.join(self.path, "repos", "test.git") + ) + orig_commit = orig_repo_obj.lookup_branch("master").peel().hex + expected = f'rebased onto