Close inactive issues #247
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Close inactive issues | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "30 1 * * *" | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| close-issues: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Get date 30 days ago | |
| id: last-month | |
| run: echo "date=$(node .github/workflows/getPreviousMonth.js)" >> $GITHUB_OUTPUT | |
| - name: Get inactive issues and close them | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| # Get the date from previous step | |
| CUTOFF_DATE="${{ steps.last-month.outputs.date }}" | |
| echo "Looking for issues updated before: $CUTOFF_DATE" | |
| # Get all issues updated before the cutoff date | |
| ISSUE_LIST=$(gh issue list --limit 100 --search "updated:<$CUTOFF_DATE" --json number,title,updatedAt --jq '.[] | "\(.number) \(.title)"') | |
| if [ -z "$ISSUE_LIST" ]; then | |
| echo "No inactive issues found" | |
| exit 0 | |
| fi | |
| echo "Found inactive issues:" | |
| echo "$ISSUE_LIST" | |
| # Process each issue | |
| gh issue list --limit 100 --search "updated:<$CUTOFF_DATE" --json number --jq '.[].number' | while read issue_number; do | |
| if [ ! -z "$issue_number" ]; then | |
| echo "Processing issue #$issue_number" | |
| ISSUE_LABELS=$(gh issue view $issue_number --json labels --jq '.labels[].name' | tr '\n' ' ') | |
| if [[ "$ISSUE_LABELS" =~ "triage-needed" ]]; then | |
| echo "Issue #$issue_number has triage-needed label, skipping" | |
| continue | |
| fi | |
| # Close the issue | |
| gh issue close $issue_number --comment "Due to lack of details for further investigation, we will archive the issue for now. In case you still have following-up questions on this issue, please always feel free to reopen the issue by clicking 'reopen issue' button below the comment box. We will get back to you as soon as possible." | |
| echo "Closed issue #$issue_number" | |
| fi | |
| done | |
| - name: Triage active issues | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| echo "Checking active issues for triage..." | |
| # Get all open issues | |
| gh issue list --state open --json number,title | jq -r '.[] | .number' | while read issue_number; do | |
| if [ ! -z "$issue_number" ]; then | |
| echo "Checking issue #$issue_number" | |
| # Get the last comment for this issue | |
| LAST_COMMENT=$(gh issue view $issue_number --json comments --jq '.comments | if length > 0 then .[-1].author.login else empty end') | |
| # If there are no comments, check the issue author | |
| if [ -z "$LAST_COMMENT" ]; then | |
| LAST_COMMENT=$(gh issue view $issue_number --json author --jq '.author.login') | |
| fi | |
| echo "Last comment/interaction by: $LAST_COMMENT" | |
| # Check if last comment author is not Siglud | |
| if [ "$LAST_COMMENT" != "Siglud" ] && [ ! -z "$LAST_COMMENT" ]; then | |
| echo "Issue #$issue_number needs triage (last interaction by $LAST_COMMENT)" | |
| # Get current labels | |
| CURRENT_LABELS=$(gh issue view $issue_number --json labels --jq '.labels[].name' | tr '\n' ' ') | |
| echo "Current labels: $CURRENT_LABELS" | |
| # Add triage-needed label if not already present | |
| if [[ ! "$CURRENT_LABELS" =~ "triage-needed" ]]; then | |
| echo "Adding triage-needed label to issue #$issue_number" | |
| gh issue edit $issue_number --repo ${{ github.repository }} --add-label "triage-needed" | |
| fi | |
| # Remove info-needed label if present | |
| if [[ "$CURRENT_LABELS" =~ "info-needed" ]]; then | |
| echo "Removing info-needed label from issue #$issue_number" | |
| gh issue edit $issue_number --repo ${{ github.repository }} --remove-label "info-needed" | |
| fi | |
| else | |
| echo "Issue #$issue_number last interaction by Siglud, skipping" | |
| fi | |
| fi | |
| done | |
| echo "Triage check completed" |