Skip to content

Commit 67353dc

Browse files
tstellarIcohedron
authored andcommitted
[llvm][GitHub] Move PR project status to Done once backport PR is made (llvm#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.
1 parent f5fbf54 commit 67353dc

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

llvm/utils/git/github-automation.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,98 @@ def release_branch_for_issue(self) -> Optional[str]:
472472
return m.group(1)
473473
return None
474474

475+
def update_issue_project_status(self) -> None:
476+
"""
477+
A common workflow is to merge a PR and then use the /cherry-pick
478+
command in a pull request comment to backport the change to the
479+
release branch. In this case, once the new PR for the backport has
480+
been created, we want to mark the project status for the original PR
481+
as Done. This is becuase we can track progress now on the new PR
482+
which is targeting the release branch.
483+
484+
"""
485+
486+
pr = self.issue.as_pull_request()
487+
if not pr:
488+
return
489+
490+
if pr.state != "closed":
491+
return
492+
493+
gh = github.Github(login_or_token=self.token)
494+
query = """
495+
query($node_id: ID!) {
496+
node(id: $node_id) {
497+
... on PullRequest {
498+
url
499+
projectItems(first:100){
500+
nodes {
501+
id
502+
project {
503+
id
504+
number
505+
field(name: "Status") {
506+
... on ProjectV2SingleSelectField {
507+
id
508+
name
509+
options {
510+
id
511+
name
512+
}
513+
}
514+
}
515+
}
516+
}
517+
}
518+
}
519+
}
520+
}
521+
"""
522+
variables = {"node_id": pr.node_id}
523+
res_header, res_data = gh._Github__requester.graphql_query(
524+
query=query, variables=variables
525+
)
526+
print(res_header)
527+
528+
llvm_release_status_project_number = 3
529+
for item in res_data["data"]["node"]["projectItems"]["nodes"]:
530+
project = item["project"]
531+
if project["number"] != llvm_release_status_project_number:
532+
continue
533+
status_field = project["field"]
534+
for option in status_field["options"]:
535+
if option["name"] != "Done":
536+
continue
537+
variables = {
538+
"project": project["id"],
539+
"item": item["id"],
540+
"status_field": status_field["id"],
541+
"status_value": option["id"],
542+
}
543+
544+
query = """
545+
mutation($project: ID!, $item: ID!, $status_field: ID!, $status_value: String!) {
546+
set_status:
547+
updateProjectV2ItemFieldValue(input: {
548+
projectId: $project
549+
itemId: $item
550+
fieldId: $status_field
551+
value: {
552+
singleSelectOptionId: $status_value
553+
}
554+
}) {
555+
projectV2Item {
556+
id
557+
}
558+
}
559+
}
560+
"""
561+
562+
res_header, res_data = gh._Github__requester.graphql_query(
563+
query=query, variables=variables
564+
)
565+
print(res_header)
566+
475567
def print_release_branch(self) -> None:
476568
print(self.release_branch_for_issue)
477569

@@ -664,6 +756,7 @@ def create_pull_request(
664756

665757
self.issue_notify_pull_request(pull)
666758
self.issue_remove_cherry_pick_failed_label()
759+
self.update_issue_project_status()
667760

668761
# TODO(tstellar): Do you really want to always return True?
669762
return True

0 commit comments

Comments
 (0)