diff --git a/.github/workflows/lock-issue.yaml b/.github/workflows/lock-issue.yaml index 704108ecb..376584f96 100644 --- a/.github/workflows/lock-issue.yaml +++ b/.github/workflows/lock-issue.yaml @@ -1,8 +1,12 @@ name: Lock closed issues on: + issues: + types: [closed] + pull_request: + types: [closed] schedule: - - cron: "0 0 * * *" # Run daily at midnight + - cron: "0 0 * * *" # Run daily at midnight for backlog workflow_dispatch: permissions: @@ -13,38 +17,52 @@ concurrency: group: lock-threads jobs: - lock: + # Lock immediately when issue/PR is closed (new issues get comment) + lock-on-close: + if: github.event_name == 'issues' || github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Lock issue/PR after close + uses: actions/github-script@v7 + with: + script: | + const createdAt = new Date(context.payload.issue?.created_at || context.payload.pull_request?.created_at); + const cutoffDate = new Date('2026-01-27T00:00:00Z'); + const isNew = createdAt >= cutoffDate; + const number = context.payload.issue?.number || context.payload.pull_request?.number; + const isIssue = !!context.payload.issue; + + // Add comment only for new issues/PRs + if (isNew) { + const comment = isIssue + ? 'This issue has been automatically locked. Please open a new issue for related bugs and reference this issue if needed.' + : 'This pull request has been automatically locked. Please open a new issue for related bugs.'; + + await github.rest.issues.createComment({ + ...context.repo, + issue_number: number, + body: comment + }); + } + + // Lock the issue/PR + await github.rest.issues.lock({ + ...context.repo, + issue_number: number, + lock_reason: 'resolved' + }); + + # Scheduled run for backlog (old issues without comment) + lock-backlog: + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest steps: - # Lock old issues (before 2026-01-27) without comment - uses: dessant/lock-threads@v6 with: github-token: ${{ github.token }} issue-inactive-days: 1 issue-lock-reason: "resolved" - exclude-issue-created-after: "2026-01-27T00:00:00Z" issue-comment: "" pr-inactive-days: 1 pr-lock-reason: "resolved" - exclude-pr-created-after: "2026-01-27T00:00:00Z" pr-comment: "" - - # Lock new issues (from 2026-01-27) with comment - - uses: dessant/lock-threads@v6 - with: - github-token: ${{ github.token }} - issue-inactive-days: 1 - issue-lock-reason: "resolved" - exclude-issue-created-before: "2026-01-27T00:00:00Z" - issue-comment: > - This issue has been automatically locked since there - has not been any recent activity after it was closed. - Please open a new issue for related bugs and reference - this issue if needed. - pr-inactive-days: 1 - pr-lock-reason: "resolved" - exclude-pr-created-before: "2026-01-27T00:00:00Z" - pr-comment: > - This pull request has been automatically locked since there - has not been any recent activity after it was closed. - Please open a new issue for related bugs.