forked from NVIDIA-NeMo/Curator
-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (134 loc) · 5.78 KB
/
Copy pathproject-default-fields.yml
File metadata and controls
154 lines (134 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Set default fields on new project items
on:
schedule:
- cron: '0 */2 * * *'
workflow_dispatch:
inputs:
lookback_hours:
description: 'Hours to look back (default: 3)'
required: false
default: '3'
jobs:
set-defaults:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.PAT }}
PROJECT_ID: "PVT_kwDODLylHc4A8S01"
# Field IDs
CONTAINER_VERSION_FIELD_ID: "PVTSSF_lADODLylHc4A8S01zgwVmS4"
SWQA_FIELD_ID: "PVTSSF_lADODLylHc4A8S01zgxJjL4"
DOCUMENTATION_STAGE_FIELD_ID: "PVTSSF_lADODLylHc4A8S01zgxJjRA"
VDR_FIELD_ID: "PVTSSF_lADODLylHc4A8S01zhAFQUA"
# Default option IDs
CONTAINER_BACKLOG_OPTION_ID: "9cc7169c"
SWQA_DEFAULT_OPTION_ID: "ec62cb4d"
DOCS_NOT_STARTED_OPTION_ID: "36e5dca1"
VDR_DEFAULT_OPTION_ID: "894a1a7c"
steps:
- name: Find recently added items with unset fields and set defaults
env:
LOOKBACK_HOURS: ${{ github.event.inputs.lookback_hours || '3' }}
run: |
set_field() {
local item_id="$1" field_id="$2" option_id="$3"
gh api graphql -f query="
mutation {
updateProjectV2ItemFieldValue(input: {
projectId: \"$PROJECT_ID\", itemId: \"$item_id\",
fieldId: \"$field_id\",
value: { singleSelectOptionId: \"$option_id\" }
}) { projectV2Item { id } }
}
"
}
# Only process items added in the lookback window (default 3 hours covers 2-hour cron with buffer)
HOURS="${LOOKBACK_HOURS:-3}"
CUTOFF=$(date -u -d "$HOURS hours ago" '+%Y-%m-%dT%H:%M:%SZ')
echo "Processing items created after $CUTOFF"
# Fetch all project items with their field values, paginating through results
CURSOR=""
ALL_ITEMS="[]"
while true; do
if [ -z "$CURSOR" ]; then
AFTER_ARG=""
else
AFTER_ARG=", after: \"$CURSOR\""
fi
RESULT=$(gh api graphql -f query="
query {
node(id: \"$PROJECT_ID\") {
... on ProjectV2 {
items(first: 100${AFTER_ARG}) {
pageInfo { hasNextPage endCursor }
nodes {
id
createdAt
containerVersion: fieldValueByName(name: \"Container Version\") {
... on ProjectV2ItemFieldSingleSelectValue { optionId }
}
swqa: fieldValueByName(name: \"SWQA\") {
... on ProjectV2ItemFieldSingleSelectValue { optionId }
}
docs: fieldValueByName(name: \"Documentation Stage\") {
... on ProjectV2ItemFieldSingleSelectValue { optionId }
}
vdr: fieldValueByName(name: \"VDR\") {
... on ProjectV2ItemFieldSingleSelectValue { optionId }
}
}
}
}
}
}
")
NODES=$(echo "$RESULT" | jq '.data.node.items.nodes')
ALL_ITEMS=$(echo "$ALL_ITEMS $NODES" | jq -s '.[0] + .[1]')
HAS_NEXT=$(echo "$RESULT" | jq -r '.data.node.items.pageInfo.hasNextPage')
if [ "$HAS_NEXT" != "true" ]; then
break
fi
CURSOR=$(echo "$RESULT" | jq -r '.data.node.items.pageInfo.endCursor')
done
TOTAL=$(echo "$ALL_ITEMS" | jq 'length')
echo "Fetched $TOTAL total project items"
# Filter to only recently created items
RECENT_ITEMS=$(echo "$ALL_ITEMS" | jq -c --arg cutoff "$CUTOFF" '[.[] | select(.createdAt > $cutoff)]')
RECENT_COUNT=$(echo "$RECENT_ITEMS" | jq 'length')
echo "Found $RECENT_COUNT items created after $CUTOFF"
if [ "$RECENT_COUNT" -eq 0 ]; then
echo "Nothing to update"
exit 0
fi
# Process each recent item — only set fields that are currently null
UPDATED=0
while read -r ITEM; do
ITEM_ID=$(echo "$ITEM" | jq -r '.id')
CV=$(echo "$ITEM" | jq '.containerVersion')
SWQA_VAL=$(echo "$ITEM" | jq '.swqa')
DOCS=$(echo "$ITEM" | jq '.docs')
VDR_VAL=$(echo "$ITEM" | jq '.vdr')
# Skip items where all fields are already set
if [ "$CV" != "null" ] && [ "$SWQA_VAL" != "null" ] && [ "$DOCS" != "null" ] && [ "$VDR_VAL" != "null" ]; then
continue
fi
echo "Item $ITEM_ID — cv=$CV swqa=$SWQA_VAL docs=$DOCS vdr=$VDR_VAL"
# Set each null field individually to avoid overwriting existing values
if [ "$CV" = "null" ]; then
echo " Setting Container Version to Backlog"
set_field "$ITEM_ID" "$CONTAINER_VERSION_FIELD_ID" "$CONTAINER_BACKLOG_OPTION_ID"
fi
if [ "$SWQA_VAL" = "null" ]; then
echo " Setting SWQA default"
set_field "$ITEM_ID" "$SWQA_FIELD_ID" "$SWQA_DEFAULT_OPTION_ID"
fi
if [ "$DOCS" = "null" ]; then
echo " Setting Documentation Stage to Not Started"
set_field "$ITEM_ID" "$DOCUMENTATION_STAGE_FIELD_ID" "$DOCS_NOT_STARTED_OPTION_ID"
fi
if [ "$VDR_VAL" = "null" ]; then
echo " Setting VDR default"
set_field "$ITEM_ID" "$VDR_FIELD_ID" "$VDR_DEFAULT_OPTION_ID"
fi
UPDATED=$((UPDATED + 1))
done < <(echo "$RECENT_ITEMS" | jq -c '.[]')
echo "Done. Updated $UPDATED items with missing defaults."