From 49ad577c0772be38f6691f93c7ac1b5dbb4dc9bf Mon Sep 17 00:00:00 2001 From: Tobias Hieta Date: Fri, 27 May 2022 16:02:15 +0200 Subject: [PATCH] [workflow] Don't fail workflow if we already have a PR for an issue When running /cherry-pick several times you will get an error when it tries to create a new PR since there already is one. This checks if we have PR first. Fixes #54862 Reviewed By: tstellar Differential Revision: https://reviews.llvm.org/D123657 --- llvm/utils/git/github-automation.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py index 7dbcf02a820b..e094fe810f99 100755 --- a/llvm/utils/git/github-automation.py +++ b/llvm/utils/git/github-automation.py @@ -191,6 +191,9 @@ class ReleaseWorkflow: self.issue_remove_cherry_pick_failed_label() return True + def check_if_pull_request_exists(self, repo:github.Repository.Repository, head:str) -> bool: + pulls = repo.get_pulls(head=head) + return pulls != None def create_pull_request(self, owner:str, branch:str) -> bool: """ @@ -208,11 +211,15 @@ class ReleaseWorkflow: release_branch_for_issue = self.release_branch_for_issue if release_branch_for_issue is None: return False + head = f"{owner}:{branch}" + if self.check_if_pull_request_exists(repo, head): + print("PR already exists...") + return True try: - pull = repo.create_pull(title='PR for {}'.format(issue_ref), + pull = repo.create_pull(title=f"PR for {issue_ref}", body='resolves {}'.format(issue_ref), base=release_branch_for_issue, - head='{}:{}'.format(owner, branch), + head=head, maintainer_can_modify=False) except Exception as e: self.issue_notify_pull_request_failure(branch) -- 2.11.4.GIT