Skip to content

Commit

Permalink
ci(actions): add action to close issues without enough information (#…
Browse files Browse the repository at this point in the history
…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
DitwanP authored Feb 25, 2025
1 parent c568454 commit 958f213
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/scripts/closeNeedMoreInfoIssues.js
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.");
};
1 change: 1 addition & 0 deletions .github/scripts/support/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const resources = {
planning: {
needsTriage: "needs triage",
needsMilestone: "needs milestone",
needsInfo: "needs more info",
spike: "spike",
spikeComplete: "spike complete",
noChangelogEntry: "no changelog entry",
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/close-needs-more-info-issues.yml
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})

0 comments on commit 958f213

Please sign in to comment.