|
| 1 | +// @ts-check |
| 2 | +const { |
| 3 | + labels: { planning }, |
| 4 | +} = require("./support/resources"); |
| 5 | + |
| 6 | +/** @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments */ |
| 7 | +module.exports = async ({ github, context }) => { |
| 8 | + const { repo, owner } = context.repo; |
| 9 | + const DAYS_BEFORE_CLOSE = 14; |
| 10 | + |
| 11 | + console.log(`Checking for issues with the label: "${planning.needsInfo}" that are stale.`); |
| 12 | + |
| 13 | + // Get all issues with the specific label |
| 14 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 15 | + owner: owner, |
| 16 | + repo: repo, |
| 17 | + state: "open", |
| 18 | + labels: planning.needsInfo, |
| 19 | + per_page: 100, |
| 20 | + }); |
| 21 | + |
| 22 | + const now = new Date(); |
| 23 | + |
| 24 | + for (const issue of issues) { |
| 25 | + const lastUpdated = new Date(issue.updated_at); |
| 26 | + const daysSinceUpdate = Math.round((now.getTime() - lastUpdated.getTime()) / (1000 * 60 * 60 * 24)); |
| 27 | + |
| 28 | + //remove this later |
| 29 | + console.log(`Days since update: ${daysSinceUpdate}`); |
| 30 | + |
| 31 | + if (daysSinceUpdate >= DAYS_BEFORE_CLOSE) { |
| 32 | + console.log(`Closing issue #${issue.number} - No updates for ${Math.round(daysSinceUpdate)} days`); |
| 33 | + |
| 34 | + await github.rest.issues.createComment({ |
| 35 | + owner: owner, |
| 36 | + repo: repo, |
| 37 | + issue_number: issue.number, |
| 38 | + body: "Closing this issue due to inactivity. If this is still an issue, it can be reopened once additional information has been provided.", |
| 39 | + }); |
| 40 | + |
| 41 | + await github.rest.issues.update({ |
| 42 | + issue_number: issue.number, |
| 43 | + owner: owner, |
| 44 | + repo: repo, |
| 45 | + state: "closed", |
| 46 | + }); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + console.log("Finished checking for issues without enough information."); |
| 51 | +}; |
0 commit comments