Skip to content

Commit a4f5664

Browse files
committed
ci: sync issue closed/reopened status to project board
1 parent 2e235ef commit a4f5664

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Sync issue status to project
2+
3+
on:
4+
issues:
5+
types: [closed, reopened]
6+
7+
jobs:
8+
update-project:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Update project item status
12+
uses: actions/github-script@v7
13+
with:
14+
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
15+
script: |
16+
const issue = context.payload.issue;
17+
const projectId = "PVT_kwDOBa9-UM4ApBgm";
18+
const statusFieldId = "PVTSSF_lADOBa9-UM4ApBgmzgggAKY";
19+
const statusOptions = {
20+
"Backlog": "558f5162",
21+
"Todo": "6b029af1",
22+
"In Progress": "2c5afb50",
23+
"In Review": "6c721920",
24+
"Blocked": "90d338b2",
25+
"Done": "21877bf4",
26+
};
27+
28+
let targetStatus;
29+
if (issue.state === "closed") {
30+
targetStatus = "Done";
31+
} else {
32+
// Reopened — move back to Backlog
33+
targetStatus = "Backlog";
34+
}
35+
36+
const query = `query($id: ID!) {
37+
node(id: $id) {
38+
... on ProjectV2 {
39+
items(first: 100) {
40+
nodes {
41+
id
42+
content {
43+
... on Issue { number repository { name owner { login } } }
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}`;
50+
const result = await github.graphql(query, { id: projectId });
51+
const item = result.node.items.nodes.find(n =>
52+
n.content?.number === issue.number &&
53+
n.content?.repository?.name === context.repo.repo &&
54+
n.content?.repository?.owner?.login === context.repo.owner
55+
);
56+
if (!item) {
57+
console.log("Issue not found in project, skipping");
58+
return;
59+
}
60+
61+
const mutation = `mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
62+
updateProjectV2ItemFieldValue(input: {
63+
projectId: $projectId
64+
itemId: $itemId
65+
fieldId: $fieldId
66+
value: { singleSelectOptionId: $optionId }
67+
}) { projectV2Item { id } }
68+
}`;
69+
await github.graphql(mutation, {
70+
projectId,
71+
itemId: item.id,
72+
fieldId: statusFieldId,
73+
optionId: statusOptions[targetStatus],
74+
});
75+
console.log("Updated issue #" + issue.number + " to " + targetStatus);

0 commit comments

Comments
 (0)