Skip to content

Commit 0fe9ca2

Browse files
authored
Update update-roadmap-project-dates.yml
1 parent cc5bd21 commit 0fe9ca2

File tree

1 file changed

+125
-26
lines changed

1 file changed

+125
-26
lines changed
Lines changed: 125 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,156 @@
1-
name: Update Arm Learning Path Roadmap Project Dates
1+
name: Update Project Custom Fields
22

33
on:
4-
workflow_dispatch:
54
pull_request:
65
types:
7-
- edited # Triggered when an issue is edited
6+
- labeled
7+
- unlabeled
88

99
jobs:
10-
update-dates:
10+
update-fields:
1111
runs-on: ubuntu-latest
12+
1213
steps:
13-
- name: Update Start Date
14-
if: |
15-
contains(github.event.changes.fields['Status'].from, 'To Do') &&
16-
contains(github.event.changes.fields['Status'].to, 'In Progress')
14+
# Step 1: Set "Start Date" when PR is labeled "In Progress"
15+
- name: Set Start Date
16+
if: contains(github.event.label.name, 'In Progress') # Trigger only if the label is "In Progress"
1717
env:
1818
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
PROJECT_NUMBER: 4 # Replace with your project number
20+
START_DATE_FIELD_NAME: "Start Date"
1921
run: |
20-
gh api graphql -f query='
21-
mutation($id: ID!, $date: String!) {
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 {
33+
id
34+
url
35+
}
36+
}
37+
}
38+
}
39+
fields(first: 20) {
40+
nodes {
41+
id
42+
name
43+
}
44+
}
45+
}
46+
}
47+
}
48+
EOF
49+
)
50+
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 {
2266
updateProjectV2ItemFieldValue(
2367
input: {
24-
projectId: "PVT_kwDOBVR2-M4A2QVf", # Replace with your actual project ID
25-
itemId: $id,
26-
fieldId: "PVTF_lADOBVR2-M4A2QVfzgrvSF4", # Replace with your Start Date field ID
27-
value: $date
68+
projectId: "${{ secrets.PROJECT_ID }}"
69+
itemId: "$PROJECT_ITEM_ID"
70+
fieldId: "$START_DATE_FIELD_ID"
71+
value: "$CURRENT_DATE"
2872
}
2973
) {
3074
projectV2Item {
3175
id
3276
}
3377
}
34-
}' -f id="${{ github.event.issue.node_id }}" -f date="$(date -u +%Y-%m-%d)"
78+
}
79+
EOF
80+
)
81+
82+
curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
83+
-X POST -d "{\"query\": \"$UPDATE_MUTATION\"}" \
84+
https://api.github.com/graphql
3585
36-
- name: Update Publish Date
37-
if: |
38-
contains(github.event.changes.fields['Status'].from, 'In Progress') &&
39-
contains(github.event.changes.fields['Status'].to, 'Done')
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"
4089
env:
4190
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
PROJECT_NUMBER: 4 # Replace with your project number
92+
PUBLISH_DATE_FIELD_NAME: "Publish Date"
4293
run: |
43-
gh api graphql -f query='
44-
mutation($id: ID!, $date: String!) {
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+
}
108+
}
109+
}
110+
}
111+
fields(first: 20) {
112+
nodes {
113+
id
114+
name
115+
}
116+
}
117+
}
118+
}
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")
133+
134+
# Update "Publish Date" field with the current date
135+
CURRENT_DATE=$(date +%Y-%m-%d)
136+
UPDATE_MUTATION=$(cat <<EOF
137+
mutation {
45138
updateProjectV2ItemFieldValue(
46139
input: {
47-
projectId: "PVT_kwDOBVR2-M4A2QVf", # Replace with your actual project ID
48-
itemId: $id,
49-
fieldId: "PVTF_lADOBVR2-M4A2QVfzgrvSMA", # Replace with your Publish Date (end date) field ID
50-
value: $date
140+
projectId: "${{ secrets.PROJECT_ID }}"
141+
itemId: "$PROJECT_ITEM_ID"
142+
fieldId: "$PUBLISH_DATE_FIELD_ID"
143+
value: "$CURRENT_DATE"
51144
}
52145
) {
53146
projectV2Item {
54147
id
55148
}
56149
}
57-
}' -f id="${{ github.event.issue.node_id }}" -f date="$(date -u +%Y-%m-%d)"
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)