From 58567240e59c397ec1e3e11921214422ee269e73 Mon Sep 17 00:00:00 2001 From: Nikola Forró Date: Nov 18 2024 21:47:41 +0000 Subject: Reverse the list of revs before determining changed files Signed-off-by: Nikola Forró --- diff --git a/pagure/hooks/default.py b/pagure/hooks/default.py index d149dba..7390cef 100644 --- a/pagure/hooks/default.py +++ b/pagure/hooks/default.py @@ -191,13 +191,14 @@ def send_notifications( authors.append(author) if revs: + revs.reverse() + changed_files = pagure.lib.git.get_changed_files( revs[-1], oldrev, repodir, ) - revs.reverse() print("* Publishing information for %i commits" % len(revs)) topic = "git.receive" diff --git a/tests/__init__.py b/tests/__init__.py index f23f7de..24fd97e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -768,7 +768,9 @@ def _clone_and_top_commits(folder, branch, branch_ref=False): return (repo, newfolder, parents) -def add_content_git_repo(folder, branch="master", append=None): +def add_content_git_repo( + folder, branch="master", append=None, extra_commit=False +): """Create some content for the specified git repo.""" repo, newfolder, parents = _clone_and_top_commits(folder, branch) @@ -829,6 +831,31 @@ def add_content_git_repo(folder, branch="master", append=None): parents, ) + if extra_commit: + if commit: + parents = [commit.hex] + + # Create another file in that git repo + with open(os.path.join(newfolder, "test"), "w") as stream: + stream.write("test") + repo.index.add("test") + repo.index.write() + + # Commit the file added + tree = repo.index.write_tree() + author = pygit2.Signature("Alice Author", "alice@authors.tld") + committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld") + commit = repo.create_commit( + "refs/heads/%s" % branch, # the name of the reference to update + author, + committer, + "Add one more file for more testing", + # binary string representing the tree object ID + tree, + # list of binary strings representing parents of the new commit + parents, + ) + # Push to origin ori_remote = repo.remotes[0] master_ref = repo.lookup_reference( diff --git a/tests/test_pagure_send_notification.py b/tests/test_pagure_send_notification.py index 973cd8f..1fccde3 100644 --- a/tests/test_pagure_send_notification.py +++ b/tests/test_pagure_send_notification.py @@ -36,13 +36,13 @@ class PagureHooksDefault(tests.SimplePagureTest): self.folder = os.path.join(self.path, "repos", "test.git") def init_test_repo(self): - tests.add_content_git_repo(self.projects[0]) + tests.add_content_git_repo(self.projects[0], extra_commit=True) repo = pygit2.Repository(self.projects[0]) commit = repo.references["refs/heads/master"].peel() sha = commit.hex - oldsha = commit.parents[0].hex + history = [c.hex for c in repo.walk(sha)] project = pagure.lib.query.get_authorized_project(self.session, "test") - return project, sha, oldsha + return project, sha, history @mock.patch("pagure.hooks.default.send_fedmsg_notifications") def test_send_action_notification(self, fedmsg): @@ -64,29 +64,30 @@ class PagureHooksDefault(tests.SimplePagureTest): @mock.patch("pagure.hooks.default.send_fedmsg_notifications") def test_send_notifications(self, fedmsg): - project, sha, oldsha = self.init_test_repo() + project, _, history = self.init_test_repo() pagure.hooks.default.send_notifications( self.session, project, self.folder, "pingou", "master", - [sha], + history[:-1], False, - oldsha, + history[-1], None, ) (_, 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]["start_commit"], history[1]) self.assertEqual(args[2]["forced"], False) - self.assertEqual(args[2]["old_commit"], oldsha) + self.assertEqual(args[2]["old_commit"], history[-1]) self.assertEqual( args[2]["changed_files"], { "folder1/folder2/file": "A", "folder1/folder2/fileŠ": "A", + "test": "A", }, ) self.assertIsNone(args[2]["pull_request_id"])