Skip to content

Commit

Permalink
tooling(actions): adds action to close issues without enough information
Browse files Browse the repository at this point in the history
  • Loading branch information
DitwanP committed Feb 25, 2025
1 parent 6e07900 commit 1e08d93
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/scripts/closeNeedMoreInfoIssues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// @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;

console.log(`Checking for issues with the label: "${planning.needsInfo}" that are stale.`);

// Get all issues with the specific label
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()) / (1000 * 60 * 60 * 24));

//remove this later
console.log(`Days since update: ${daysSinceUpdate}`);

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 this is still an issue, it can be reopened once additional information has been provided.",
});

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 * * *" # Runs daily 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 1e08d93

Please sign in to comment.