diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py --- a/llvm/utils/git/github-automation.py +++ b/llvm/utils/git/github-automation.py @@ -11,6 +11,8 @@ import argparse from git import Repo # type: ignore import github +import github.Repository +import github.PullRequest import os import re import sys @@ -191,6 +193,11 @@ self.issue_remove_cherry_pick_failed_label() return True + def check_if_pull_request_exists(self, repo:github.Repository.Repository, title:str) -> Optional[github.PullRequest.PullRequest]: + for pr in repo.get_pulls(): + if pr.title == title: + return pr + return None def create_pull_request(self, owner:str, branch:str) -> bool: """ @@ -202,14 +209,21 @@ https://docs.github.com/en/get-started/quickstart/github-glossary#base-branch https://docs.github.com/en/get-started/quickstart/github-glossary#compare-branch """ + print(owner, branch, self.branch_repo_name) repo = github.Github(self.token).get_repo(self.branch_repo_name) issue_ref = '{}#{}'.format(self.repo_name, self.issue_number) pull = None + print(self.release_branch_for_issue) release_branch_for_issue = self.release_branch_for_issue if release_branch_for_issue is None: return False + pull_title = f"PR for {issue_ref}" + pull = self.check_if_pull_request_exists(repo, pull_title) + if pull: + print("Have PR already: " + pull.url) + return True try: - pull = repo.create_pull(title='PR for {}'.format(issue_ref), + pull = repo.create_pull(title=pull_title, body='resolves {}'.format(issue_ref), base=release_branch_for_issue, head='{}:{}'.format(owner, branch),