|
| 1 | +name: Mark Stale Issues |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * *' # Runs daily at midnight |
| 6 | + |
| 7 | +env: |
| 8 | + AWAITING-RESPONSE_LABEL: stat:awaiting-response |
| 9 | + STALE_LABEL: stale |
| 10 | + DAYS_BEFORE_STALE: 60 # 2 months |
| 11 | + |
| 12 | +jobs: |
| 13 | + mark_stale: |
| 14 | + name: Check and Mark Stale Issues |
| 15 | + if: ${{ !github.event.issue.pull_request }} && ${{ github.event.issue.state == 'open' }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + issues: write |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Get Issues with Awaiting Response |
| 22 | + id: get_issues |
| 23 | + run: | |
| 24 | + # Get all open issues with awaiting-response label |
| 25 | + ISSUES=$(gh issue list --label "${{ env.AWAITING-RESPONSE_LABEL }}" --json number,labels,updatedAt --jq '.[]') |
| 26 | + |
| 27 | + echo "ISSUES=$ISSUES" >> $GITHUB_ENV |
| 28 | +
|
| 29 | + - name: Process Issues |
| 30 | + run: | |
| 31 | + current_time=$(date +%s) |
| 32 | + |
| 33 | + echo "$ISSUES" | while read -r issue; do |
| 34 | + # Extract issue details |
| 35 | + number=$(echo "$issue" | jq -r .number) |
| 36 | + updated_at=$(echo "$issue" | jq -r .updatedAt) |
| 37 | + has_stale=$(echo "$issue" | jq -r '.labels[].name | select(. == "stale")' || echo "") |
| 38 | + |
| 39 | + # Convert updated_at to timestamp |
| 40 | + updated_time=$(date -d "$updated_at" +%s) |
| 41 | + |
| 42 | + # Calculate days difference |
| 43 | + days_diff=$(( (current_time - updated_time) / 86400 )) |
| 44 | + |
| 45 | + # Check if issue should be marked stale |
| 46 | + if [[ $days_diff -ge ${{ env.DAYS_BEFORE_STALE }} && -z "$has_stale" ]]; then |
| 47 | + echo "Marking issue #$number as stale" |
| 48 | + gh issue edit "$number" --add-label "${{ env.STALE_LABEL }}" \ |
| 49 | + --body-file <( |
| 50 | + echo "This issue has been automatically marked as stale because it has been awaiting response for over 2 months without any activity." |
| 51 | + echo "" |
| 52 | + echo "Please update the issue with any new information or it may be closed in the future." |
| 53 | + ) |
| 54 | + fi |
| 55 | + done |
| 56 | + env: |
| 57 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + GH_REPO: ${{ github.repository }} |
| 59 | + |
0 commit comments