FIX: The Logical Error (since parameter)
- Date Comparison: Changed from using the API since filter to a bash comparison using date +%s. - Safety Check: Added if [ -z "$issue" ]; then continue; fi inside the loop to prevent the crash if jq outputs an empty line. - Logic: The script now checks if the issue is actually older than 30 days before applying the label.
This commit is contained in:
@@ -16,15 +16,35 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Mark stale issues
|
- name: Mark stale issues
|
||||||
run: |
|
run: |
|
||||||
# Issues with no activity for 30 days
|
# Calculate timestamp for 30 days ago (seconds since epoch for comparison)
|
||||||
THIRTY_DAYS_AGO=$(date -u -d '30 days ago' '+%Y-%m-%dT%H:%M:%SZ')
|
THIRTY_DAYS_AGO_SEC=$(date -d '30 days ago' '+%s')
|
||||||
|
|
||||||
# Get all open issues updated before 30 days ago
|
# Get all open issues sorted by oldest update first
|
||||||
ISSUES=$(curl -s -H "Authorization: token $API_TOKEN" "$API_BASE_URL/repos/$REPO/issues?state=open&since=$THIRTY_DAYS_AGO&sort=updated&order=asc" | jq -c '.[]')
|
# REMOVED 'since' because it filters for NEWER issues
|
||||||
|
ISSUES=$(curl -s -H "Authorization: token $API_TOKEN" "$API_BASE_URL/repos/$REPO/issues?state=open&sort=updated&order=asc" | jq -c '.[]')
|
||||||
|
|
||||||
|
# Check if we have issues to process
|
||||||
|
if [ -z "$ISSUES" ]; then
|
||||||
|
echo "No open issues found."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
echo "$ISSUES" | while IFS= read -r issue; do
|
echo "$ISSUES" | while IFS= read -r issue; do
|
||||||
|
# Prevent processing empty lines
|
||||||
|
if [ -z "$issue" ]; then continue; fi
|
||||||
|
|
||||||
ISSUE_NUMBER=$(echo "$issue" | jq -r '.number')
|
ISSUE_NUMBER=$(echo "$issue" | jq -r '.number')
|
||||||
UPDATED_AT=$(echo "$issue" | jq -r '.updated_at')
|
UPDATED_AT=$(echo "$issue" | jq -r '.updated_at')
|
||||||
|
|
||||||
|
# Convert issue update time to seconds
|
||||||
|
UPDATED_AT_SEC=$(date -d "$UPDATED_AT" '+%s')
|
||||||
|
|
||||||
|
# LOGIC CHECK: If the issue is newer than 30 days, stop (since list is sorted asc)
|
||||||
|
if [ "$UPDATED_AT_SEC" -gt "$THIRTY_DAYS_AGO_SEC" ]; then
|
||||||
|
# Found an issue updated recently, so we are done with the old ones
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
HAS_STALE_LABEL=$(echo "$issue" | jq -r '.labels[] | select(.name == "status: stale") | .name')
|
HAS_STALE_LABEL=$(echo "$issue" | jq -r '.labels[] | select(.name == "status: stale") | .name')
|
||||||
|
|
||||||
# Skip if already has stale label
|
# Skip if already has stale label
|
||||||
|
|||||||
Reference in New Issue
Block a user