Skip to content

Commit

Permalink
Rewrite the thread-locking workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Nov 17, 2024
1 parent 58b2a94 commit 5e91ae5
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions .github/workflows/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,56 @@ name: Lock old threads

on:
schedule:
# Run at midnight daily
- cron: "0 0 * * *"

permissions:
issues: write
pull-requests: write
workflow_dispatch:

jobs:
action:
if: github.repository_owner == 'sphinx-doc'
runs-on: ubuntu-latest
if: github.repository_owner == 'sphinx-doc'
permissions:
# to lock issues and PRs
issues: write
pull-requests: write
steps:
- uses: dessant/lock-threads@v3
with:
github-token: ${{ github.token }}
issue-inactive-days: "30"
pr-inactive-days: "30"
- uses: actions/github-script@v7
with:
retries: 3
# language=JavaScript
script: |
const _FOUR_WEEKS_MILLISECONDS = 28 * 24 * 60 * 60 * 1000;
const _FOUR_WEEKS_DATE = new Date(Date.now() - _FOUR_WEEKS_MILLISECONDS);
const FOUR_WEEKS_AGO = `${_FOUR_WEEKS_DATE.toISOString().substring(0, 10)}T00:00:00Z`;
try {
const {owner, repo} = github.context.repo;
for (const thread_type of ["issue", "pr"]) {
core.debug(`Finding ${thread_type}s to lock`);
const query = thread_type === "issue"
? `repo:${owner}/${repo} updated:<${FOUR_WEEKS_AGO} is:closed is:unlocked is:issue`
: `repo:${owner}/${repo} updated:<${FOUR_WEEKS_AGO} is:closed is:unlocked is:pr`;
core.debug(`Using query '${query}'`);
// https://octokit.github.io/rest.js/v21/#search-issues-and-pull-requests
const {data: {items: results}} = await github.rest.search.issuesAndPullRequests({
q: query,
order: "desc",
sort: "updated",
per_page: 100,
});
for (const item of results) {
if (item.locked) continue;
const thread_num = item.number;
core.debug(`Locking #${thread_num} (${thread_type})`);
// https://octokit.github.io/rest.js/v21/#issues-lock
await github.rest.issues.lock({
owner,
repo,
issue_number: thread_num,
lock_reason: "resolved",
});
}
}
} catch (err) {
core.setFailed(err.message);
}

0 comments on commit 5e91ae5

Please sign in to comment.