[llvm] 17d4796 - github: Fix release automation /branch command with new repo

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 26 15:09:55 PDT 2022


Author: Tom Stellard
Date: 2022-07-26T15:05:05-07:00
New Revision: 17d4796cc84618e9b15f9484e5576127c431bc60

URL: https://github.com/llvm/llvm-project/commit/17d4796cc84618e9b15f9484e5576127c431bc60
DIFF: https://github.com/llvm/llvm-project/commit/17d4796cc84618e9b15f9484e5576127c431bc60.diff

LOG: github: Fix release automation /branch command with new repo

We started using the llvm/llvm-project-release-prs repo for
backport pull requests, but since this repo is not a fork of
llvm/llvm-project it will reject pull requests from other repos. In
order to fix this, when ever someone uses the /branch command to request
a branch be merged into the release branch, we first copy the branch to
the llvm-project-release-prs repo and then create the pull request.

Reviewed By: thieta

Differential Revision: https://reviews.llvm.org/D126940

Added: 
    

Modified: 
    llvm/utils/git/github-automation.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 232a12ed36c6c..3862ade65221e 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -14,6 +14,7 @@
 import os
 import re
 import sys
+import time
 from typing import *
 
 class IssueSubscriber:
@@ -224,7 +225,29 @@ def create_pull_request(self, owner:str, branch:str) -> bool:
         release_branch_for_issue = self.release_branch_for_issue
         if release_branch_for_issue is None:
             return False
-        head = f"{owner}:{branch}"
+        head_branch = branch
+        if not repo.fork:
+            # If the target repo is not a fork of llvm-project, we need to copy
+            # the branch into the target repo.  GitHub only supports cross-repo pull
+            # requests on forked repos.
+            head_branch = f'{owner}-{branch}'
+            local_repo = Repo(self.llvm_project_dir)
+            push_done = False
+            for i in range(0,5):
+                try:
+                    local_repo.git.fetch(f'https://github.com/{owner}/llvm-project', f'{branch}:{branch}')
+                    local_repo.git.push(self.push_url, f'{branch}:{head_branch}', force=True)
+                    push_done = True
+                    break
+                except Exception as e:
+                    print(e)
+                    time.sleep(30)
+                    continue
+            if not push_done:
+                raise Exception("Failed to mirror branch into {}".format(self.push_url))
+            owner = repo.owner.login
+
+        head = f"{owner}:{head_branch}"
         if self.check_if_pull_request_exists(repo, head):
             print("PR already exists...")
             return True


        


More information about the llvm-commits mailing list