Lock closed issues and pull requests #7
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
| # @license MIT | |
| # @copyright 2026 Mickaël Canouil | |
| # @author Mickaël Canouil | |
| name: Lock closed issues and pull requests | |
| on: | |
| schedule: | |
| - cron: "0 3 * * *" | |
| workflow_dispatch: | |
| inputs: | |
| days: | |
| description: "Lock threads closed more than this many days ago." | |
| type: number | |
| required: false | |
| default: 7 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: lock-closed-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| lock: | |
| name: Lock stale closed threads | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| steps: | |
| - name: Create GitHub App token | |
| id: app-token | |
| uses: actions/create-github-app-token@v3 | |
| with: | |
| client-id: ${{ vars.APP_ID }} | |
| private-key: ${{ secrets.APP_KEY }} | |
| - name: Compute threshold date | |
| id: threshold | |
| env: | |
| DAYS: ${{ inputs.days || 7 }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| date=$(date -u -d "${DAYS} days ago" +%Y-%m-%d) | |
| echo "date=${date}" >> "${GITHUB_OUTPUT}" | |
| echo "Locking issues and pull requests closed before ${date}." | |
| - name: Lock stale threads | |
| id: lock | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| REPO: ${{ github.repository }} | |
| THRESHOLD: ${{ steps.threshold.outputs.date }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| LOCKED_FILE="$(mktemp)" | |
| lock_kind() { | |
| local kind="$1" subcommand="$2" number | |
| while IFS= read -r number; do | |
| [[ -n "$number" ]] || continue | |
| gh api --method PUT "repos/${REPO}/issues/${number}/lock" \ | |
| -f lock_reason=resolved | |
| echo "${kind} #${number}" >> "${LOCKED_FILE}" | |
| echo "Locked ${kind} #${number}." | |
| done < <(gh search "${subcommand}" \ | |
| --repo "${REPO}" \ | |
| --closed "<${THRESHOLD}" \ | |
| --locked=false \ | |
| --limit 1000 \ | |
| --json number --jq '.[].number') | |
| } | |
| lock_kind "issue" "issues" | |
| lock_kind "pull request" "prs" | |
| count=$(wc -l < "${LOCKED_FILE}" | tr -d ' ') | |
| echo "count=${count}" >> "${GITHUB_OUTPUT}" | |
| echo "locked-file=${LOCKED_FILE}" >> "${GITHUB_OUTPUT}" | |
| - name: Summary | |
| if: always() | |
| env: | |
| THRESHOLD: ${{ steps.threshold.outputs.date }} | |
| COUNT: ${{ steps.lock.outputs.count }} | |
| LOCKED_FILE: ${{ steps.lock.outputs.locked-file }} | |
| shell: bash | |
| run: | | |
| { | |
| echo "## Locked threads" | |
| echo "" | |
| echo "Threshold: closed before \`${THRESHOLD:-n/a}\`." | |
| echo "" | |
| echo "Locked ${COUNT:-0} thread(s)." | |
| if [[ -n "${LOCKED_FILE:-}" && -s "${LOCKED_FILE}" ]]; then | |
| echo "" | |
| while IFS= read -r line; do | |
| echo "- ${line}" | |
| done < "${LOCKED_FILE}" | |
| fi | |
| } >> "${GITHUB_STEP_SUMMARY}" |