Skip to content

Commit ef16bc6

Browse files
Add GitHub Actions workflow for project status labels
1 parent 08d56ac commit ef16bc6

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Add Label on Project Status Change
2+
3+
permissions:
4+
issues: write
5+
projects: read
6+
7+
on:
8+
workflow_dispatch:
9+
projects_v2_item:
10+
types: [edited]
11+
12+
jobs:
13+
add-label:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check project item status and add label
17+
uses: actions/github-script@v7
18+
with:
19+
script: |
20+
try {
21+
const { data: item } = await github.graphql(`
22+
query($id: ID!) {
23+
node(id: $id) {
24+
... on ProjectV2Item {
25+
content {
26+
... on Issue {
27+
number
28+
repository {
29+
name
30+
owner { login }
31+
}
32+
}
33+
}
34+
fieldValues(first: 10) {
35+
nodes {
36+
... on ProjectV2ItemFieldValue {
37+
field { name }
38+
value
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
`, { id: context.payload.projects_v2_item.node_id });
46+
47+
const statusField = item.fieldValues.nodes.find(f => f.field.name === "Status");
48+
console.log("current status:", statusField?.value);
49+
50+
if (
51+
statusField?.value === "Need To Verify" &&
52+
item.content?.number
53+
) {
54+
const issue = item.content;
55+
await github.rest.issues.addLabels({
56+
owner: issue.repository.owner.login,
57+
repo: issue.repository.name,
58+
issue_number: issue.number,
59+
labels: ["kind/need-to-verify"]
60+
});
61+
console.log("✅ Label added:kind/need-to-verify");
62+
} else {
63+
console.log("ℹ️ Not a matching item, skip");
64+
}
65+
} catch (error) {
66+
console.error("❌ Action failed:", error.message);
67+
throw error;
68+
}

0 commit comments

Comments
 (0)