Skip to content

Commit f99e54d

Browse files
authored
Refactor workflow to add 'in-progress' label
1 parent 0d8cd24 commit f99e54d

File tree

1 file changed

+20
-69
lines changed

1 file changed

+20
-69
lines changed
Lines changed: 20 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,21 @@
1-
name: Auto-add 'in-progress' label when status changes
1+
name: Add 'in-progress' label
2+
uses: alex-page/github-project-automation-plus@v0.8.1
3+
with:
4+
project: "Your Project Name" # Must match exactly (org-level)
5+
column: "In Progress"
6+
repo-token: ${{ secrets.GITHUB_TOKEN }}
7+
script: |
8+
const { data: issue } = await github.issues.get({
9+
owner: context.payload.repository.owner.login,
10+
repo: context.payload.project_card.content_url.split('/')[4], // Extract repo name
11+
issue_number: context.payload.project_card.content_url.split('/').pop()
12+
});
213
3-
on:
4-
project_card:
5-
types: [moved]
6-
7-
jobs:
8-
add-label:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- name: Add 'in-progress' label when status is 'In Progress'
12-
uses: actions/github-script@v6
13-
with:
14-
script: |
15-
// 1. Get the project card details
16-
const card = await github.graphql(`
17-
query($cardId: ID!) {
18-
node(id: $cardId) {
19-
... on ProjectCard {
20-
column {
21-
name
22-
}
23-
content {
24-
... on Issue {
25-
id
26-
number
27-
repository {
28-
name
29-
owner {
30-
login
31-
}
32-
}
33-
labels(first: 10) {
34-
nodes {
35-
name
36-
}
37-
}
38-
}
39-
}
40-
}
41-
}
42-
}
43-
`, {
44-
cardId: context.payload.project_card.node_id
45-
});
46-
47-
const cardData = card.node;
48-
const columnName = cardData.column.name;
49-
const issue = cardData.content;
50-
51-
// 2. Check if the card is in "In Progress" and the issue exists
52-
if (columnName === "In Progress" && issue) {
53-
const hasLabel = issue.labels.nodes.some(label => label.name === "in-progress");
54-
55-
// 3. Add the label if missing
56-
if (!hasLabel) {
57-
await github.graphql(`
58-
mutation($issueId: ID!) {
59-
addLabelsToLabelable(input: {
60-
labelableId: $issueId,
61-
labelIds: ["in-progress"] # Replace with your label's node ID
62-
}) {
63-
clientMutationId
64-
}
65-
}
66-
`, {
67-
issueId: issue.id
68-
});
69-
}
70-
}
14+
if (!issue.labels.some(label => label.name === 'in-progress')) {
15+
await github.issues.addLabels({
16+
owner: context.payload.repository.owner.login,
17+
repo: context.payload.project_card.content_url.split('/')[4],
18+
issue_number: issue.number,
19+
labels: ['in-progress']
20+
});
21+
}

0 commit comments

Comments
 (0)