-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(actions): add action to close issues without enough information (#…
…11617) **Related Issue:** #11235 ## Summary - Adds action to run daily at midnight UTC that will check for issues with the `need more info` and close them if it's been 2 weeks or more without any updates. - Tested in personal action testing repo.
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// @ts-check | ||
const { | ||
labels: { planning }, | ||
} = require("./support/resources"); | ||
|
||
/** @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments */ | ||
module.exports = async ({ github, context }) => { | ||
const { repo, owner } = context.repo; | ||
const DAYS_BEFORE_CLOSE = 14; | ||
const MILLISECONDS_IN_A_DAY = 1000 * 60 * 60 * 24; | ||
|
||
console.log(`Checking for issues with the label: "${planning.needsInfo}" that are stale.`); | ||
|
||
const { data: issues } = await github.rest.issues.listForRepo({ | ||
owner: owner, | ||
repo: repo, | ||
state: "open", | ||
labels: planning.needsInfo, | ||
per_page: 100, | ||
}); | ||
|
||
const now = new Date(); | ||
|
||
for (const issue of issues) { | ||
const lastUpdated = new Date(issue.updated_at); | ||
const daysSinceUpdate = Math.round((now.getTime() - lastUpdated.getTime()) / MILLISECONDS_IN_A_DAY); | ||
|
||
if (daysSinceUpdate >= DAYS_BEFORE_CLOSE) { | ||
console.log(`Closing issue #${issue.number} - No updates for ${Math.round(daysSinceUpdate)} days`); | ||
|
||
await github.rest.issues.createComment({ | ||
owner: owner, | ||
repo: repo, | ||
issue_number: issue.number, | ||
body: "Closing this issue due to inactivity. If the issue persists, feel free to reopen it with additional details.", | ||
}); | ||
|
||
await github.rest.issues.update({ | ||
issue_number: issue.number, | ||
owner: owner, | ||
repo: repo, | ||
state: "closed", | ||
}); | ||
} | ||
} | ||
|
||
console.log("Finished checking for issues without enough information."); | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Close Need More Info Issues | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 0 * * 1" # Runs every Monday at midnight UTC | ||
|
||
permissions: | ||
issues: write | ||
|
||
jobs: | ||
close-needs-more-info-issues: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Close issue if more info is not provided | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const action = require('${{ github.workspace }}/.github/scripts/closeNeedMoreInfoIssues.js') | ||
await action({github, context, core}) |