@@ -14,30 +14,42 @@ jobs:
1414 - name : Install jq
1515 run : sudo apt-get update && sudo apt-get install -y jq
1616
17- - name : Debug - List project items
17+ - name : Authenticate GitHub CLI
18+ env :
19+ GH_TOKEN : ${{ secrets.UPDATE_PROJECT_V2_PAT }}
20+ run : echo "${GH_TOKEN}" | gh auth login --with-token
21+
22+ - name : Debug - List projects linked to this issue
1823 env :
1924 GH_TOKEN : ${{ secrets.UPDATE_PROJECT_V2_PAT }}
2025 run : |
21- echo "Listing all project items in Microsoft Project 183 for debugging..."
22- gh project item-list 183 --owner microsoft --format json | jq .
26+ echo "🔍 Listing all projects linked to issue ${{ github.event.issue.number }}..."
27+ gh issue view ${{ github.event.issue.number }} \
28+ --repo ${{ github.repository }} \
29+ --json projectsV2 \
30+ | jq .
2331
24- - name : Set Remaining Days to 0 in Microsoft Project 183
32+ - name : Set Remaining Days to 0 if issue is in Project 183
2533 env :
2634 GH_TOKEN : ${{ secrets.UPDATE_PROJECT_V2_PAT }}
2735 run : |
28- # Find the project item ID for the issue that triggered the workflow
29- ITEM_ID=$(gh project item-list 183 --owner microsoft --format json \
30- | jq -r ".[] | select(.content.url==\"${{ github.event.issue.html_url }}\") | .id")
36+ echo "🔍 Checking if issue ${{ github.event.issue.number }} belongs to Project 183..."
37+
38+ # Find the project item ID for project 183 among the issue’s linked projects
39+ ITEM_ID=$(gh issue view ${{ github.event.issue.number }} \
40+ --repo ${{ github.repository }} \
41+ --json projectsV2 \
42+ | jq -r '.projectsV2[] | select(.number==183) | .item.id')
3143
3244 if [ -z "$ITEM_ID" ]; then
33- echo "❌ No project item found for issue: ${{ github.event.issue.html_url }} "
34- exit 1
45+ echo "ℹ️ Issue is not in Project 183. Nothing to update. "
46+ exit 0
3547 fi
3648
37- echo "✅ Found Project Item ID: $ITEM_ID"
49+ echo "✅ Found Project Item ID in Project 183 : $ITEM_ID"
3850
3951 # Find the field ID for "Remaining Days"
40- FIELD_ID=$(gh project field-list 183 --owner microsoft --format json \
52+ FIELD_ID=$(gh project field-list --owner microsoft --number 183 --format json \
4153 | jq -r '.[] | select(.name=="Remaining Days") | .id')
4254
4355 if [ -z "$FIELD_ID" ]; then
4860 echo "✅ Found Field ID for Remaining Days: $FIELD_ID"
4961
5062 # Update the field value to 0
51- gh project item-update 183 --owner microsoft --id "$ITEM_ID" --field-id "$FIELD_ID" --value "0"
63+ gh project item-update --owner microsoft --number 183 \
64+ --id "$ITEM_ID" --field-id "$FIELD_ID" --value "0"
5265
5366 echo "🎉 Successfully set Remaining Days = 0 for issue ${{ github.event.issue.number }}"
0 commit comments