[llvm] [Utils] Add new merge-release-pr.py script. (PR #101630)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 2 01:20:28 PDT 2024
================
@@ -0,0 +1,239 @@
+#!/usr/bin/env python3
+# ===-- merge-release-pr.py ------------------------------------------------===#
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+# ===------------------------------------------------------------------------===#
+#
+# Helper script that will merge a Pull Request into a release branch. It will first
+# do some validations of the PR then rebase and finally push the changes to the
+# release branch.
+#
+# Usage: merge-release-pr.py <PR id>
+# By default it will push to the 'upstream' origin, but you can pass
+# --upstream-origin/-o <origin> if you want to change it.
+#
+# If you want to skip a specific validation, like the status checks you can
+# pass -s status_checks, this argument can be passed multiple times.
+#
+import argparse
+import json
+import subprocess
+import sys
+import time
+from typing import List
+
+
+class PRMerger:
+ def __init__(self, args):
+ self.pr = args.pr
+ self.args = args
+
+ def run_gh(self, gh_cmd: str, args: List[str]) -> str:
+ cmd = ["gh", gh_cmd, "-Rllvm/llvm-project"] + args
+ p = subprocess.run(cmd, capture_output=True)
+ if p.returncode != 0:
+ print(p.stderr)
+ raise RuntimeError("Failed to run gh")
+ return p.stdout
+
+ # Validate the state of the PR, this means making sure that it is
+ # OPEN and not already merged or closed.
+ def validate_state(self, data):
+ state = data["state"]
+ if state != "OPEN":
+ return False, f"state is {state.lower()}, not open"
+ return True
+
+ # Validate that the PR is targetting a release/ branch. We could
+ # validate the exact branch here, but I am not sure how to figure
+ # out what we want except an argument and that might be a bit to
+ # to much overhead.
+ def validate_target_branch(self, data):
+ baseRefName: str = data["baseRefName"]
+ if not baseRefName.startswith("release/"):
+ return False, f"target branch is {baseRefName}, not a release branch"
+ return True
+
+ # Validate the approval decision. This checks that the PR has been
+ # approved.
+ def validate_approval(self, data):
+ if data["reviewDecision"] != "APPROVED":
+ return False, "PR is not approved"
+ return True
+
+ # Check that all the actions / status checks succeeded. Will also
----------------
boomanaiden154 wrote:
Docstring here.
https://github.com/llvm/llvm-project/pull/101630
More information about the llvm-commits
mailing list