-
Notifications
You must be signed in to change notification settings - Fork 1
127 lines (112 loc) · 4.14 KB
/
Copy pathorg-close-pr-status.yml
File metadata and controls
127 lines (112 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Directly move the closed PR to a close status in the PODAAC project
# to avoid unnecessary clutter and manual triage in the "needs:triage" column.
name: Update Closed PR Status in PODAAC project
on:
pull_request:
types: [closed]
jobs:
update-pr-status:
runs-on: ubuntu-latest
steps:
- name: Set status to closed
uses: actions/github-script@v7
with:
github-token: ${{ secrets.PROJECTS_PAT }}
script: |
const projectNumber = 75;
const org = 'podaac';
const prNumber = context.payload.pull_request.number;
const isMerged = context.payload.pull_request.merged;
console.log(`PR #${prNumber} was ${isMerged ? 'merged' : 'closed without merging'}`);
// Get the project ID and status field information
const projectQuery = `
query($org: String!, $number: Int!) {
organization(login: $org) {
projectV2(number: $number) {
id
fields(first: 20) {
nodes {
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}
`;
const projectData = await github.graphql(projectQuery, {
org: org,
number: projectNumber
});
const project = projectData.organization.projectV2;
const statusField = project.fields.nodes.find(field => field.name === 'Status');
const closedOption = statusField?.options.find(option => option.name === 'closed');
if (!closedOption) {
core.warning('Could not find "closed" status option in project');
return;
}
// Get the PR's project item
const itemQuery = `
query($org: String!, $repo: String!, $number: Int!) {
repository(owner: $org, name: $repo) {
pullRequest(number: $number) {
projectItems(first: 10) {
nodes {
id
project {
id
}
}
}
}
}
}
`;
const itemData = await github.graphql(itemQuery, {
org: org,
repo: context.repo.repo,
number: prNumber
});
const items = itemData.repository.pullRequest.projectItems.nodes;
const projectItem = items.find(item => item.project.id === project.id);
if (!projectItem) {
console.log('PR is not in the project, skipping status update');
return;
}
// Update the status field to "closed"
const updateMutation = `
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $value: String!) {
updateProjectV2ItemFieldValue(
input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: { singleSelectOptionId: $value }
}
) {
projectV2Item {
id
}
}
}
`;
await github.graphql(updateMutation, {
projectId: project.id,
itemId: projectItem.id,
fieldId: statusField.id,
value: closedOption.id
});
console.log(`✅ Successfully set status to "closed" for PR #${prNumber}`);
core.summary
.addHeading(`PR Status Updated`)
.addList([
`PR #${prNumber} was ${isMerged ? 'merged' : 'closed'}`,
`Project status updated to "closed"`
])
.write();