Skip to content

Commit e335844

Browse files
authored
Fix sprint date parsing for ISO 8601 format (#1423)
GitHub Projects API returns dates in ISO 8601 format (2026-04-21T00:00:00Z). The previous string comparison failed because it compared '2026-04-21' with '2026-04-21T00:00:00Z'. Changes: - Extract date portion using split("T")[0] before comparison - Handle both .duration.endDate and .endDate field names - Add debug output to show raw iteration data Fixes #1420
1 parent 46b37f7 commit e335844

1 file changed

Lines changed: 42 additions & 21 deletions

File tree

.github/workflows/label_sprint_issues.yml

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
echo "Ensuring label '$LABEL_NAME' exists..."
3636
gh label create "$LABEL_NAME" --color "0E8A16" --description "Issue is part of the current sprint" 2>/dev/null || echo "Label already exists"
3737
38-
# Get all project items with their iteration info
38+
# Get all project items
3939
echo "Fetching project items from project $PROJECT_NUMBER..."
4040
gh project item-list $PROJECT_NUMBER \
4141
--owner $ORG \
@@ -50,33 +50,56 @@ jobs:
5050
5151
# Get today's date for iteration comparison
5252
TODAY=$(date +%Y-%m-%d)
53-
echo "Today: $TODAY"
53+
echo -e "\nToday: $TODAY"
5454
55-
# Find current sprint (active iteration) - one where today is between start and end date
56-
CURRENT_SPRINT=$(cat project_items.json | jq -r --arg today "$TODAY" '
57-
[.items[].iteration | select(. != null)] |
58-
unique |
59-
.[] |
60-
select(.startDate <= $today and .duration.endDate >= $today) |
61-
.id
62-
' | head -1)
55+
# Find current sprint using shell-based date math (more reliable than jq)
56+
echo -e "\nSearching for current sprint..."
57+
58+
# Extract all sprints and check each one using shell date commands
59+
cat project_items.json | jq -r '.items[].sprint | select(. != null) | "\(.iterationId)|\(.startDate)|\(.duration)|\(.title)"' | sort -u > /tmp/sprints.txt
60+
61+
CURRENT_SPRINT=""
62+
while IFS='|' read -r id start_date duration title; do
63+
if [ -z "$id" ] || [ -z "$start_date" ] || [ -z "$duration" ]; then
64+
continue
65+
fi
66+
67+
# Calculate end date: start_date + duration days
68+
end_date=$(date -d "$start_date + $duration days" +%Y-%m-%d 2>/dev/null || echo "")
69+
70+
if [ -n "$end_date" ]; then
71+
echo "Checking sprint: $title ($start_date to $end_date)"
72+
73+
# Check if today is within the sprint range (POSIX-compliant)
74+
if [ "$TODAY" = "$start_date" ] || [ "$TODAY" \> "$start_date" ]; then
75+
if [ "$TODAY" \< "$end_date" ]; then
76+
echo " -> Current sprint found!"
77+
CURRENT_SPRINT="$id"
78+
break
79+
fi
80+
fi
81+
fi
82+
done < /tmp/sprints.txt
6383
6484
if [ -z "$CURRENT_SPRINT" ]; then
65-
echo "WARNING: No active sprint found for today ($TODAY)"
66-
echo "Checking all iterations in project..."
67-
cat project_items.json | jq -r '[.items[].iteration | select(. != null)] | unique | .[] | "\(.id): \(.title) (\(.startDate) to \(.duration.endDate))"' || true
68-
echo "Exiting - no active sprint to process"
85+
echo -e "WARNING: No active sprint found for today ($TODAY)\n"
86+
echo "All sprints in project:"
87+
cat /tmp/sprints.txt | while IFS='|' read -r id start_date duration title; do
88+
end_date=$(date -d "$start_date + $duration days" +%Y-%m-%d 2>/dev/null || echo "unknown")
89+
echo " - $title: $start_date to $end_date (ID: $id)"
90+
done
91+
echo -e "\nExiting - no active sprint to process"
6992
exit 0
7093
fi
7194
72-
echo "Current sprint ID: $CURRENT_SPRINT"
95+
echo -e "Current sprint ID: $CURRENT_SPRINT\n"
7396
7497
# Get issues in current sprint
7598
echo "Finding issues in current sprint..."
7699
cat project_items.json | jq -r \
77100
--arg sprint "$CURRENT_SPRINT" \
78-
'.items[] | select(.iteration.id == $sprint and .content.type == "Issue") | .content.number' \
79-
| sort -n | uniq > current_sprint_issues.txt
101+
'.items[] | select(.sprint.iterationId == $sprint and .content.type == "Issue") | .content.number' \
102+
| sort -n | uniq > current_sprint_issues.txt 2>/dev/null || touch current_sprint_issues.txt
80103
81104
ISSUES_IN_SPRINT=$(wc -l < current_sprint_issues.txt | tr -d ' ')
82105
echo "Found $ISSUES_IN_SPRINT issues in current sprint"
@@ -89,7 +112,7 @@ jobs:
89112
fi
90113
91114
# Get all open issues with the sprint label
92-
echo "Fetching issues with label '$LABEL_NAME'..."
115+
echo -e "\nFetching issues with label '$LABEL_NAME'..."
93116
gh search issues \
94117
--repo ${{ github.repository }} \
95118
--label "$LABEL_NAME" \
@@ -137,9 +160,7 @@ jobs:
137160
fi
138161
done < labeled_issues.txt
139162
140-
echo ""
141-
echo "=== Sprint Label Sync Complete ==="
163+
echo -e "\n=== Sprint Label Sync Complete ==="
142164
echo "Added label to: $ADDED_COUNT issues"
143165
echo "Removed label from: $REMOVED_COUNT issues"
144166
echo "Issues in sprint: $ISSUES_IN_SPRINT"
145-
echo "Total labeled after sync: $((ISSUES_IN_SPRINT))"

0 commit comments

Comments
 (0)