Skip to content

Stale P3 Issue

Stale P3 Issue #17

name: Stale P3 Issue
on:
# Run weekly on Mondays before 9am Seattle time, so discussion needed labels are added before the working day.
# Run at non-zero minute so we're not running at the same time as everyone else who runs at the zero minute.
schedule:
- cron: '29 15 * * 1'
workflow_dispatch:
inputs:
batch_size:
description: 'Number of issues to process per run'
required: false
default: '100'
inactivity_days:
description: 'Only process issues inactive for at least this many days (Default: 2 years)'
required: false
default: '730' # 730 days = 2 years, adjust as needed
dry_run:
description: 'Dry run (no changes made)'
required: false
default: 'false'
type: boolean
jobs:
mark-stale-p3:
permissions:
issues: write
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
BATCH_SIZE: ${{ github.event.inputs.batch_size || '100' }}
INACTIVITY_DAYS: ${{ github.event.inputs.inactivity_days || '730' }}
DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }}
steps:
- name: Mark stale P3 issues as inactive
run: |
echo "πŸ” Finding Priority:3 issues with <5 upvotes and no activity in $INACTIVITY_DAYS+ days..."
echo "πŸ“¦ Batch size: $BATCH_SIZE"
echo "πŸ§ͺ Dry run: $DRY_RUN"
echo "REPO: $REPO"
echo ""
# Validate numeric inputs
if ! [[ "$BATCH_SIZE" =~ ^[0-9]+$ ]]; then
echo "❌ Error: batch_size must be a positive integer, got: '$BATCH_SIZE'"
exit 1
fi
if ! [[ "$INACTIVITY_DAYS" =~ ^[0-9]+$ ]]; then
echo "❌ Error: inactivity_days must be a positive integer, got: '$INACTIVITY_DAYS'"
exit 1
fi
CUTOFF_DATE=$(date -d "$INACTIVITY_DAYS days ago" -u +%Y-%m-%d)
echo "⏰ Cutoff date: $CUTOFF_DATE"
marked=0
echo "πŸ”Ž Searching for Priority:3 issues with <5 reactions, last updated before $CUTOFF_DATE, without Status:Inactive"
issues=$(gh search issues \
--repo "$REPO" \
--limit "$BATCH_SIZE" \
--json number \
--jq '.[].number' \
-- \
is:open \
label:Priority:3 \
-label:Status:Inactive \
reactions:\<5 \
updated:\<$CUTOFF_DATE \
sort:reactions-asc)
if [ -z "$issues" ]; then
echo "βœ… No eligible P3 issues found."
exit 0
fi
total=$(echo "$issues" | wc -l | tr -d ' ')
echo "πŸ“‹ Found $total eligible issues to mark as inactive."
echo ""
for ISSUE in $issues; do
if [ "$marked" -ge "$BATCH_SIZE" ]; then
echo "πŸ“¦ Batch limit of $BATCH_SIZE reached."
break
fi
if [ "$DRY_RUN" = "true" ]; then
echo " πŸ§ͺ [DRY RUN] Would mark Issue #$ISSUE as Status:Inactive"
else
echo " 🏷️ Marking Issue #$ISSUE as Status:Inactive"
gh issue edit "$ISSUE" -R "$REPO" --add-label "Status:Inactive"
fi
marked=$((marked + 1))
echo ""
# Small delay to avoid rate limiting
sleep 1
done
echo "================================"
echo "βœ… Done! Marked $marked issues as Status:Inactive."