[llvm] cd26c11 - [llvm][GitHub] Move PR project status to Done once backport PR is made (#126374)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 10 13:06:55 PST 2025
Author: Tom Stellard
Date: 2025-02-10T13:06:51-08:00
New Revision: cd26c112b224180bfc9ff23fbe04deb3322a18d8
URL: https://github.com/llvm/llvm-project/commit/cd26c112b224180bfc9ff23fbe04deb3322a18d8
DIFF: https://github.com/llvm/llvm-project/commit/cd26c112b224180bfc9ff23fbe04deb3322a18d8.diff
LOG: [llvm][GitHub] Move PR project status to Done once backport PR is made (#126374)
It's common to use the /cherry-pick command on a PR to create a backport
request. However, this creates a lot of clutter in the LLVM Release
Status project, because we end up with two items in the project, one for
the original PR and one for the new PR.
This change will set the status of the original PR to Done once the new
PR (for the release branch) is created. This will save release managers
a lot of work of having to manually updated the status for PRs that
contain backport requests.
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 6978da51ac64574..db789c26d96ddd7 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -472,6 +472,98 @@ def release_branch_for_issue(self) -> Optional[str]:
return m.group(1)
return None
+ def update_issue_project_status(self) -> None:
+ """
+ A common workflow is to merge a PR and then use the /cherry-pick
+ command in a pull request comment to backport the change to the
+ release branch. In this case, once the new PR for the backport has
+ been created, we want to mark the project status for the original PR
+ as Done. This is becuase we can track progress now on the new PR
+ which is targeting the release branch.
+
+ """
+
+ pr = self.issue.as_pull_request()
+ if not pr:
+ return
+
+ if pr.state != "closed":
+ return
+
+ gh = github.Github(login_or_token=self.token)
+ query = """
+ query($node_id: ID!) {
+ node(id: $node_id) {
+ ... on PullRequest {
+ url
+ projectItems(first:100){
+ nodes {
+ id
+ project {
+ id
+ number
+ field(name: "Status") {
+ ... on ProjectV2SingleSelectField {
+ id
+ name
+ options {
+ id
+ name
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ """
+ variables = {"node_id": pr.node_id}
+ res_header, res_data = gh._Github__requester.graphql_query(
+ query=query, variables=variables
+ )
+ print(res_header)
+
+ llvm_release_status_project_number = 3
+ for item in res_data["data"]["node"]["projectItems"]["nodes"]:
+ project = item["project"]
+ if project["number"] != llvm_release_status_project_number:
+ continue
+ status_field = project["field"]
+ for option in status_field["options"]:
+ if option["name"] != "Done":
+ continue
+ variables = {
+ "project": project["id"],
+ "item": item["id"],
+ "status_field": status_field["id"],
+ "status_value": option["id"],
+ }
+
+ query = """
+ mutation($project: ID!, $item: ID!, $status_field: ID!, $status_value: String!) {
+ set_status:
+ updateProjectV2ItemFieldValue(input: {
+ projectId: $project
+ itemId: $item
+ fieldId: $status_field
+ value: {
+ singleSelectOptionId: $status_value
+ }
+ }) {
+ projectV2Item {
+ id
+ }
+ }
+ }
+ """
+
+ res_header, res_data = gh._Github__requester.graphql_query(
+ query=query, variables=variables
+ )
+ print(res_header)
+
def print_release_branch(self) -> None:
print(self.release_branch_for_issue)
@@ -664,6 +756,7 @@ def create_pull_request(
self.issue_notify_pull_request(pull)
self.issue_remove_cherry_pick_failed_label()
+ self.update_issue_project_status()
# TODO(tstellar): Do you really want to always return True?
return True
More information about the llvm-commits
mailing list