-
Notifications
You must be signed in to change notification settings - Fork 3
145 lines (124 loc) · 5.53 KB
/
label_sprint_issues.yml
File metadata and controls
145 lines (124 loc) · 5.53 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
name: Label Current Sprint Issues
on:
schedule:
# Run twice daily: 8 AM and 3 PM UTC
- cron: "0 8 * * *"
- cron: "0 15 * * *"
workflow_dispatch: # Manual trigger for testing
jobs:
sync-sprint-labels:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Sync sprint labels
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PROJECT_NUMBER: 24
ORG: qbicsoftware
LABEL_NAME: "sprint:current"
run: |
set -e
echo "=== Sprint Label Sync Started ==="
echo "Project: $PROJECT_NUMBER"
echo "Label: $LABEL_NAME"
# Create label if it doesn't exist
echo "Ensuring label '$LABEL_NAME' exists..."
gh label create "$LABEL_NAME" --color "0E8A16" --description "Issue is part of the current sprint" 2>/dev/null || echo "Label already exists"
# Get all project items with their iteration info
echo "Fetching project items from project $PROJECT_NUMBER..."
gh project item-list $PROJECT_NUMBER \
--owner $ORG \
--format json \
--limit 1000 > project_items.json
# Check if we got any data
if [ ! -s project_items.json ]; then
echo "ERROR: Failed to fetch project items or project is empty"
exit 1
fi
# Get today's date for iteration comparison
TODAY=$(date +%Y-%m-%d)
echo "Today: $TODAY"
# Find current sprint (active iteration) - one where today is between start and end date
CURRENT_SPRINT=$(cat project_items.json | jq -r --arg today "$TODAY" '
[.items[].iteration | select(. != null)] |
unique |
.[] |
select(.startDate <= $today and .duration.endDate >= $today) |
.id
' | head -1)
if [ -z "$CURRENT_SPRINT" ]; then
echo "WARNING: No active sprint found for today ($TODAY)"
echo "Checking all iterations in project..."
cat project_items.json | jq -r '[.items[].iteration | select(. != null)] | unique | .[] | "\(.id): \(.title) (\(.startDate) to \(.duration.endDate))"' || true
echo "Exiting - no active sprint to process"
exit 0
fi
echo "Current sprint ID: $CURRENT_SPRINT"
# Get issues in current sprint
echo "Finding issues in current sprint..."
cat project_items.json | jq -r \
--arg sprint "$CURRENT_SPRINT" \
'.items[] | select(.iteration.id == $sprint and .content.type == "Issue") | .content.number' \
| sort -n | uniq > current_sprint_issues.txt
ISSUES_IN_SPRINT=$(wc -l < current_sprint_issues.txt | tr -d ' ')
echo "Found $ISSUES_IN_SPRINT issues in current sprint"
if [ "$ISSUES_IN_SPRINT" -eq 0 ]; then
echo "No issues found in current sprint"
else
echo "Issues in sprint:"
cat current_sprint_issues.txt
fi
# Get all open issues with the sprint label
echo "Fetching issues with label '$LABEL_NAME'..."
gh search issues \
--repo ${{ github.repository }} \
--label "$LABEL_NAME" \
--state open \
--json number \
--jq '.[].number' 2>/dev/null | sort -n | uniq > labeled_issues.txt || touch labeled_issues.txt
ISSUES_LABELED=$(wc -l < labeled_issues.txt | tr -d ' ')
echo "Found $ISSUES_LABELED issues with sprint label"
if [ "$ISSUES_LABELED" -gt 0 ]; then
echo "Currently labeled issues:"
cat labeled_issues.txt
fi
# Add label to issues in sprint that don't have it
ADDED_COUNT=0
while read -r issue_number; do
if [ -z "$issue_number" ]; then
continue
fi
if ! grep -q "^${issue_number}$" labeled_issues.txt 2>/dev/null; then
echo "Adding label '$LABEL_NAME' to issue #$issue_number"
if gh issue edit "$issue_number" --add-label "$LABEL_NAME"; then
ADDED_COUNT=$((ADDED_COUNT + 1))
else
echo "WARNING: Failed to add label to issue #$issue_number"
fi
fi
done < current_sprint_issues.txt
# Remove label from issues not in current sprint
REMOVED_COUNT=0
while read -r issue_number; do
if [ -z "$issue_number" ]; then
continue
fi
if ! grep -q "^${issue_number}$" current_sprint_issues.txt 2>/dev/null; then
echo "Removing label '$LABEL_NAME' from issue #$issue_number (not in current sprint)"
if gh issue edit "$issue_number" --remove-label "$LABEL_NAME"; then
REMOVED_COUNT=$((REMOVED_COUNT + 1))
else
echo "WARNING: Failed to remove label from issue #$issue_number"
fi
fi
done < labeled_issues.txt
echo ""
echo "=== Sprint Label Sync Complete ==="
echo "Added label to: $ADDED_COUNT issues"
echo "Removed label from: $REMOVED_COUNT issues"
echo "Issues in sprint: $ISSUES_IN_SPRINT"
echo "Total labeled after sync: $((ISSUES_IN_SPRINT))"