[PATCH] D123657: [workflow] Don't fail workflow if we already have a PR for an issue
Tobias Hieta via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 13 00:07:15 PDT 2022
thieta created this revision.
thieta added a reviewer: tstellar.
Herald added a project: All.
thieta requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D123657
Files:
llvm/utils/git/github-automation.py
Index: llvm/utils/git/github-automation.py
===================================================================
--- llvm/utils/git/github-automation.py
+++ 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),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123657.422408.patch
Type: text/x-patch
Size: 1980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220413/6c59fa87/attachment.bin>
More information about the llvm-commits
mailing list