Skip to content

Commit cf473a3

Browse files
authored
Update update-roadmap-project-dates.yml
1 parent e750873 commit cf473a3

File tree

1 file changed

+74
-131
lines changed

1 file changed

+74
-131
lines changed
Lines changed: 74 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,99 @@
1-
name: Update Project Custom Fields
1+
name: Update Project Fields on Label and Status Change
22

33
on:
44
pull_request:
55
types:
66
- labeled
7-
- unlabeled
7+
workflow_dispatch:
88

99
jobs:
10-
update-fields:
10+
update-project-dates:
1111
runs-on: ubuntu-latest
12-
1312
steps:
14-
# Step 1: Set "Start Date" when PR is labeled "awaiting_tech_review"
15-
- name: Set Start Date
16-
if: contains(github.event.label.name, 'awaiting_tech_review') # Trigger only if the label is "awaiting_tech_review"
17-
env:
18-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19-
PROJECT_NUMBER: 4 # Replace with your project number
20-
START_DATE_FIELD_NAME: "Start Date"
21-
run: |
22-
# GraphQL Query to find the project item ID and "Start Date" field ID
23-
QUERY=$(cat <<EOF
24-
query {
25-
organization(login: "ArmDeveloperEcosystem") {
26-
projectV2(number: $PROJECT_NUMBER) {
27-
id
28-
items(first: 100) {
29-
nodes {
30-
id
31-
content {
32-
... on PullRequest {
13+
- name: Check out code
14+
uses: actions/checkout@v3
15+
16+
- name: Run GitHub Script
17+
uses: actions/github-script@v7
18+
with:
19+
github-token: ${{ secrets.PROJECT_TOKEN }} # replace with your token secret name
20+
script: |
21+
const projectId = "PVT_kwDOBVR2-M4A2QVf"; // Replace with your actual project node ID
22+
const fieldStartId = "PVTF_lADOBVR2-M4A2QVfzgrvSF4"; // Replace with Start Date field node ID
23+
const fieldPublishId = "PVTF_lADOBVR2-M4A2QVfzgrvSMA"; // Replace with Publish Date field node ID
24+
25+
const label = context.payload.label.name;
26+
const prNodeId = context.payload.pull_request.node_id;
27+
28+
// Get the project item for this PR
29+
const { repository } = await github.graphql(`
30+
query($owner: String!, $repo: String!, $prNumber: Int!) {
31+
repository(owner: $owner, name: $repo) {
32+
pullRequest(number: $prNumber) {
33+
projectItems(first: 10) {
34+
nodes {
3335
id
34-
url
36+
fieldValues(first: 10) {
37+
nodes {
38+
field {
39+
name
40+
}
41+
value
42+
}
43+
}
3544
}
3645
}
3746
}
3847
}
39-
fields(first: 20) {
40-
nodes {
41-
id
42-
name
43-
}
44-
}
4548
}
46-
}
47-
}
48-
EOF
49-
)
49+
`, {
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
prNumber: context.issue.number,
53+
});
5054
51-
# Execute the query
52-
RESPONSE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
53-
-X POST -d "{\"query\": \"$QUERY\"}" \
54-
https://api.github.com/graphql)
55-
56-
# Extract the project item ID and field ID for "Start Date"
57-
PROJECT_ITEM_ID=$(echo $RESPONSE | jq -r \
58-
".data.organization.projectV2.items.nodes[] | select(.content.url == \"${{ github.event.issue.html_url }}\") | .id")
59-
START_DATE_FIELD_ID=$(echo $RESPONSE | jq -r \
60-
".data.organization.projectV2.fields.nodes[] | select(.name == \"$START_DATE_FIELD_NAME\") | .id")
61-
62-
# Update "Start Date" field with the current date
63-
CURRENT_DATE=$(date +%Y-%m-%d)
64-
UPDATE_MUTATION=$(cat <<EOF
65-
mutation {
66-
updateProjectV2ItemFieldValue(
67-
input: {
68-
projectId: "${{ secrets.PROJECT_ID }}"
69-
itemId: "$PROJECT_ITEM_ID"
70-
fieldId: "$START_DATE_FIELD_ID"
71-
value: "$CURRENT_DATE"
72-
}
73-
) {
74-
projectV2Item {
75-
id
76-
}
55+
const item = repository.pullRequest.projectItems.nodes[0];
56+
if (!item) {
57+
console.log("No project item found for this PR.");
58+
return;
7759
}
78-
}
79-
EOF
80-
)
8160
82-
curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
83-
-X POST -d "{\"query\": \"$UPDATE_MUTATION\"}" \
84-
https://api.github.com/graphql
61+
const itemId = item.id;
8562
86-
# Step 2: Set "Publish Date" when PR is labeled "Done"
87-
- name: Set Publish Date
88-
if: contains(github.event.label.name, 'Done') # Trigger only if the label is "Done"
89-
env:
90-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91-
PROJECT_NUMBER: 4 # Replace with your project number
92-
PUBLISH_DATE_FIELD_NAME: "Publish Date"
93-
run: |
94-
# GraphQL Query to find the project item ID and "Publish Date" field ID
95-
QUERY=$(cat <<EOF
96-
query {
97-
organization(login: "ArmDeveloperEcosystem") {
98-
projectV2(number: $PROJECT_NUMBER) {
99-
id
100-
items(first: 100) {
101-
nodes {
102-
id
103-
content {
104-
... on PullRequest {
105-
id
106-
url
107-
}
63+
const today = new Date().toISOString().split("T")[0]; // e.g., "2025-04-10"
64+
65+
if (label === "awaiting_tech_review") {
66+
console.log("Setting Start Date...");
67+
await github.graphql(`
68+
mutation {
69+
updateProjectV2ItemFieldValue(input: {
70+
projectId: "${projectId}",
71+
itemId: "${itemId}",
72+
fieldId: "${fieldStartId}",
73+
value: { date: "${today}" }
74+
}) {
75+
projectV2Item {
76+
id
10877
}
10978
}
11079
}
111-
fields(first: 20) {
112-
nodes {
113-
id
114-
name
115-
}
116-
}
117-
}
80+
`);
11881
}
119-
}
120-
EOF
121-
)
122-
123-
# Execute the query
124-
RESPONSE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
125-
-X POST -d "{\"query\": \"$QUERY\"}" \
126-
https://api.github.com/graphql)
127-
128-
# Extract the project item ID and field ID for "Publish Date"
129-
PROJECT_ITEM_ID=$(echo $RESPONSE | jq -r \
130-
".data.organization.projectV2.items.nodes[] | select(.content.url == \"${{ github.event.issue.html_url }}\") | .id")
131-
PUBLISH_DATE_FIELD_ID=$(echo $RESPONSE | jq -r \
132-
".data.organization.projectV2.fields.nodes[] | select(.name == \"$PUBLISH_DATE_FIELD_NAME\") | .id")
13382
134-
# Update "Publish Date" field with the current date
135-
CURRENT_DATE=$(date +%Y-%m-%d)
136-
UPDATE_MUTATION=$(cat <<EOF
137-
mutation {
138-
updateProjectV2ItemFieldValue(
139-
input: {
140-
projectId: "${{ secrets.PROJECT_ID }}"
141-
itemId: "$PROJECT_ITEM_ID"
142-
fieldId: "$PUBLISH_DATE_FIELD_ID"
143-
value: "$CURRENT_DATE"
144-
}
145-
) {
146-
projectV2Item {
147-
id
148-
}
83+
if (label === "publish") {
84+
console.log("Setting Publish Date...");
85+
await github.graphql(`
86+
mutation {
87+
updateProjectV2ItemFieldValue(input: {
88+
projectId: "${projectId}",
89+
itemId: "${itemId}",
90+
fieldId: "${fieldPublishId}",
91+
value: { date: "${today}" }
92+
}) {
93+
projectV2Item {
94+
id
95+
}
96+
}
97+
}
98+
`);
14999
}
150-
}
151-
EOF
152-
)
153-
154-
curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
155-
-X POST -d "{\"query\": \"$UPDATE_MUTATION\"}" \
156-
https://api.github.com/graphql

0 commit comments

Comments
 (0)