Skip to content

Commit ef7d0c2

Browse files
ashleynolanBen Siggery
authored and
Ben Siggery
committed
ci(pie-monorepo): DSW-000 added ds tracker gh workflow to update variables
ci(pie-monorepo): DSW-000 fix query ci(pie-monorepo): DSW-000 temp for testing ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 cast to int ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 debugging ci(pie-monorepo): DSW-000 revert use graphql action update var usage new var for filter new var for filter add logging attempt to update date opened field rebase
1 parent bbba375 commit ef7d0c2

File tree

2 files changed

+219
-0
lines changed

2 files changed

+219
-0
lines changed

.changeset/stupid-wasps-laugh.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"pie-monorepo": minor
3+
---
4+
5+
[Added] - workflow to update DS tracker project variables
+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
name: DS Review Tracker – Update Project Fields
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
update-project-fields:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Get Project Data
12+
uses: octokit/[email protected]
13+
id: get_project_data
14+
with:
15+
query: |
16+
query($org: String!, $number: Int!) {
17+
organization(login: $org){
18+
projectV2(number: $number) {
19+
id
20+
fields(first:20) {
21+
nodes {
22+
... on ProjectV2Field {
23+
id
24+
name
25+
}
26+
... on ProjectV2SingleSelectField {
27+
id
28+
name
29+
options {
30+
id
31+
name
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
variables: |
40+
{
41+
"org": "${{ github.repository_owner }}",
42+
"number": 5
43+
}
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GH_PROJECTS_SECRET }}
46+
47+
- name: Extract Project Field IDs
48+
id: extract_fields
49+
run: |
50+
PROJECT_DATA='${{ steps.get_project_data.outputs.data }}'
51+
echo "PROJECT_ID=$(echo $PROJECT_DATA | jq -r '.organization.projectV2.id')" >> $GITHUB_OUTPUT
52+
53+
echo "Available fields:"
54+
echo "$PROJECT_DATA" | jq -r '.organization.projectV2.fields.nodes[] | .name + ": " + .id'
55+
56+
DATE_FIELD_ID=$(echo "$PROJECT_DATA" | jq -r '.organization.projectV2.fields.nodes[] | select(.name=="Date opened") | .id')
57+
echo "Found Date Field ID: $DATE_FIELD_ID"
58+
59+
# Check if date field was found
60+
if [ -n "$DATE_FIELD_ID" ]; then
61+
echo "HAS_DATE_FIELD=true" >> $GITHUB_OUTPUT
62+
else
63+
echo "HAS_DATE_FIELD=false" >> $GITHUB_OUTPUT
64+
echo "Warning: 'Date opened' field not found in project. Date will not be updated."
65+
fi
66+
67+
echo "PROJECT_ID=$(echo $PROJECT_DATA | jq -r '.organization.projectV2.id')" >> $GITHUB_OUTPUT
68+
echo "DATE_FIELD_ID=$DATE_FIELD_ID" >> $GITHUB_OUTPUT
69+
echo "PRIORITY_FIELD_ID=$(echo $PROJECT_DATA | jq -r '.organization.projectV2.fields.nodes[] | select(.name=="Priority") | .id')" >> $GITHUB_OUTPUT
70+
echo "PRIORITY_OPTION_ID=$(echo $PROJECT_DATA | jq -r '.organization.projectV2.fields.nodes[] | select(.name=="Priority") | .options[] | select(.name=="Medium") | .id')" >> $GITHUB_OUTPUT
71+
echo "SIZE_FIELD_ID=$(echo $PROJECT_DATA | jq -r '.organization.projectV2.fields.nodes[] | select(.name=="Size") | .id')" >> $GITHUB_OUTPUT
72+
echo "SIZE_OPTION_ID=$(echo $PROJECT_DATA | jq -r '.organization.projectV2.fields.nodes[] | select(.name=="Size") | .options[] | select(.name=="M") | .id')" >> $GITHUB_OUTPUT
73+
74+
- name: Add PR to Project
75+
uses: octokit/[email protected]
76+
id: add_pr_to_project
77+
with:
78+
query: |
79+
mutation($project:ID!, $pr:ID!) {
80+
addProjectV2ItemById(input: {projectId: $project, contentId: $pr}) {
81+
item {
82+
id
83+
}
84+
}
85+
}
86+
variables: |
87+
{
88+
"project": "${{ steps.extract_fields.outputs.PROJECT_ID }}",
89+
"pr": "${{ github.event.pull_request.node_id }}"
90+
}
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GH_PROJECTS_SECRET }}
93+
94+
- name: Get Item ID
95+
id: get_item_id
96+
run: |
97+
ITEM_DATA='${{ steps.add_pr_to_project.outputs.data }}'
98+
echo "ITEM_ID=$(echo $ITEM_DATA | jq -r '.addProjectV2ItemById.item.id')" >> $GITHUB_OUTPUT
99+
100+
- name: Update Project Fields
101+
uses: octokit/[email protected]
102+
if: steps.extract_fields.outputs.HAS_DATE_FIELD == 'true'
103+
with:
104+
query: |
105+
mutation (
106+
$project: ID!
107+
$item: ID!
108+
$dateField: ID!
109+
$priorityField: ID!
110+
$sizeField: ID!
111+
$priorityOption: String!
112+
$sizeOption: String!
113+
$date: Date!
114+
) {
115+
dateUpdate: updateProjectV2ItemFieldValue(input: {
116+
projectId: $project
117+
itemId: $item
118+
fieldId: $dateField
119+
value: {
120+
date: $date
121+
}
122+
}) {
123+
projectV2Item {
124+
id
125+
}
126+
}
127+
priorityUpdate: updateProjectV2ItemFieldValue(input: {
128+
projectId: $project
129+
itemId: $item
130+
fieldId: $priorityField
131+
value: {
132+
singleSelectOptionId: $priorityOption
133+
}
134+
}) {
135+
projectV2Item {
136+
id
137+
}
138+
}
139+
sizeUpdate: updateProjectV2ItemFieldValue(input: {
140+
projectId: $project
141+
itemId: $item
142+
fieldId: $sizeField
143+
value: {
144+
singleSelectOptionId: $sizeOption
145+
}
146+
}) {
147+
projectV2Item {
148+
id
149+
}
150+
}
151+
}
152+
variables: |
153+
{
154+
"project": "${{ steps.extract_fields.outputs.PROJECT_ID }}",
155+
"item": "${{ steps.get_item_id.outputs.ITEM_ID }}",
156+
"dateField": "${{ steps.extract_fields.outputs.DATE_FIELD_ID }}",
157+
"priorityField": "${{ steps.extract_fields.outputs.PRIORITY_FIELD_ID }}",
158+
"sizeField": "${{ steps.extract_fields.outputs.SIZE_FIELD_ID }}",
159+
"priorityOption": "${{ steps.extract_fields.outputs.PRIORITY_OPTION_ID }}",
160+
"sizeOption": "${{ steps.extract_fields.outputs.SIZE_OPTION_ID }}",
161+
"date": "${{ github.event.pull_request.created_at }}"
162+
}
163+
env:
164+
GITHUB_TOKEN: ${{ secrets.GH_PROJECTS_SECRET }}
165+
166+
- name: Update Project Fields (Without Date)
167+
uses: octokit/[email protected]
168+
if: steps.extract_fields.outputs.HAS_DATE_FIELD != 'true'
169+
with:
170+
query: |
171+
mutation (
172+
$project: ID!
173+
$item: ID!
174+
$priorityField: ID!
175+
$sizeField: ID!
176+
$priorityOption: String!
177+
$sizeOption: String!
178+
) {
179+
priorityUpdate: updateProjectV2ItemFieldValue(input: {
180+
projectId: $project
181+
itemId: $item
182+
fieldId: $priorityField
183+
value: {
184+
singleSelectOptionId: $priorityOption
185+
}
186+
}) {
187+
projectV2Item {
188+
id
189+
}
190+
}
191+
sizeUpdate: updateProjectV2ItemFieldValue(input: {
192+
projectId: $project
193+
itemId: $item
194+
fieldId: $sizeField
195+
value: {
196+
singleSelectOptionId: $sizeOption
197+
}
198+
}) {
199+
projectV2Item {
200+
id
201+
}
202+
}
203+
}
204+
variables: |
205+
{
206+
"project": "${{ steps.extract_fields.outputs.PROJECT_ID }}",
207+
"item": "${{ steps.get_item_id.outputs.ITEM_ID }}",
208+
"priorityField": "${{ steps.extract_fields.outputs.PRIORITY_FIELD_ID }}",
209+
"sizeField": "${{ steps.extract_fields.outputs.SIZE_FIELD_ID }}",
210+
"priorityOption": "${{ steps.extract_fields.outputs.PRIORITY_OPTION_ID }}",
211+
"sizeOption": "${{ steps.extract_fields.outputs.SIZE_OPTION_ID }}"
212+
}
213+
env:
214+
GITHUB_TOKEN: ${{ secrets.GH_PROJECTS_SECRET }}

0 commit comments

Comments
 (0)