From ff1fdadf2742d4b7bd6d61a22ac8ecb95b76b52f Mon Sep 17 00:00:00 2001 From: Michal Konečný Date: Jan 11 2023 15:29:26 +0000 Subject: Change the method to retrieve the first commit from git branch This method is used by scm_request_processor and the previous `git rev-list` implementation failed in one case, where there was one than one commit without parents in the same branch. This will rather use the `git log` and picks the hash of the oldest commit. This commit also further enhances the error message posted by bot. Signed-off-by: Michal Konečný --- diff --git a/tests/utils/test_git.py b/tests/utils/test_git.py index 6492751..136798a 100644 --- a/tests/utils/test_git.py +++ b/tests/utils/test_git.py @@ -66,14 +66,16 @@ class TestGitRepoFirstCommit: """ branch = "branch" - result = "hash" - self.repo.repo.git.rev_list.return_value = result + result = "hash1\nhash2" + self.repo.repo.git.log.return_value = result commit = self.repo.first_commit(branch) - self.repo.repo.git.rev_list.assert_called_with("--max-parents=0", branch) + self.repo.repo.git.log.assert_called_with( + "--reverse", "--pretty=format='%H'", branch + ) - assert commit == "hash" + assert commit == "hash1" def test_first_commit_no_commit(self): """ @@ -83,10 +85,12 @@ class TestGitRepoFirstCommit: branch = "branch" result = "" - self.repo.repo.git.rev_list.return_value = result + self.repo.repo.git.log.return_value = result commit = self.repo.first_commit(branch) - self.repo.repo.git.rev_list.assert_called_with("--max-parents=0", branch) + self.repo.repo.git.log.assert_called_with( + "--reverse", "--pretty=format='%H'", branch + ) assert commit is None diff --git a/toddlers/plugins/scm_request_processor.py b/toddlers/plugins/scm_request_processor.py index 8663eea..660b8aa 100644 --- a/toddlers/plugins/scm_request_processor.py +++ b/toddlers/plugins/scm_request_processor.py @@ -198,17 +198,13 @@ class SCMRequestProcessor(ToddlerBase): try: self.process_ticket(issue) - except BaseException as e: + except BaseException: self.pagure_io.add_comment_to_issue( issue["id"], namespace=PROJECT_NAMESPACE, comment=( - "Error happened during processing:\n" - "{0}\n\n" - "```\n" - "{1}\n" - "```\n" - ).format(str(e), traceback.format_exc()), + "Error happened during processing:\n" "```\n" "{0}\n" "```\n" + ).format(traceback.format_exc()), ) def process_ticket(self, issue: dict): diff --git a/toddlers/utils/git.py b/toddlers/utils/git.py index 29b2e54..00902af 100644 --- a/toddlers/utils/git.py +++ b/toddlers/utils/git.py @@ -53,12 +53,12 @@ class GitRepo: Returns: Hash of commit. """ - # This will return only the root commit of the branch - commit = self.repo.git.rev_list("--max-parents=0", branch) # type: ignore + # This will return only commit hashes for commits + commits = self.repo.git.log("--reverse", "--pretty=format='%H'", branch) # type: ignore result = None - if commit: - result = commit + if commits: + result = commits.split("\n")[0] return result diff --git a/toddlers/utils/pagure.py b/toddlers/utils/pagure.py index ba30cac..afa2e5f 100644 --- a/toddlers/utils/pagure.py +++ b/toddlers/utils/pagure.py @@ -383,15 +383,11 @@ class Pagure: raise PagureError( ( - "Couldn't create branch in project '{0}/{1}'\n" - "Request to `{2}`:\n" - "```\n" - "{3}\n" - "```\n" + "Couldn't create branch in project '{0}/{1}'\n\n" + "Request to '{2}':\n" + "{3}\n\n" "Response:\n" - "```\n" - "{4}\n" - "```\n" + "{4}\n\n" "Status code: {5}" ).format( namespace,