Skip to content

Commit 3182851

Browse files
committed
[llvm][GitHub] Move PR project status to Done once backport PR is made
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 9d5edc9 commit 3182851

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

llvm/utils/git/github-automation.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,99 @@ 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 = {
523+
"node_id" : pr.node_id
524+
}
525+
res_header, res_data = gh._Github__requester.graphql_query(
526+
query=query, variables=variables
527+
)
528+
print(res_header)
529+
530+
for item in res_data['data']['node']['projectItems']['nodes']:
531+
project = item['project']
532+
if project['number'] != 3:
533+
continue
534+
status_field = project['field']
535+
for option in status_field['options']:
536+
if option['name'] != "Done":
537+
continue
538+
variables = {
539+
"project" : project["id"],
540+
"item" : item["id"],
541+
"status_field" : status_field["id"],
542+
"status_value" : option["id"],
543+
}
544+
545+
query = """
546+
mutation($project: ID!, $item: ID!, $status_field: ID!, $status_value: String!) {
547+
set_status:
548+
updateProjectV2ItemFieldValue(input: {
549+
projectId: $project
550+
itemId: $item
551+
fieldId: $status_field
552+
value: {
553+
singleSelectOptionId: $status_value
554+
}
555+
}) {
556+
projectV2Item {
557+
id
558+
}
559+
}
560+
}
561+
"""
562+
563+
res_header, res_data = gh._Github__requester.graphql_query(
564+
query=query, variables=variables
565+
)
566+
print(res_header)
567+
475568
def print_release_branch(self) -> None:
476569
print(self.release_branch_for_issue)
477570

@@ -664,6 +757,7 @@ def create_pull_request(
664757

665758
self.issue_notify_pull_request(pull)
666759
self.issue_remove_cherry_pick_failed_label()
760+
self.update_issue_project_status()
667761

668762
# TODO(tstellar): Do you really want to always return True?
669763
return True

0 commit comments

Comments
 (0)