[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:09:33 PDT 2022


thieta updated this revision to Diff 422409.
thieta added a comment.

Removed unintentional debug lines


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123657/new/

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:
         """
@@ -208,8 +215,13 @@
         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.422409.patch
Type: text/x-patch
Size: 1524 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220413/dad78b83/attachment.bin>


More information about the llvm-commits mailing list