|
| 1 | +require("dotenv").config(); |
| 2 | +const { Octokit } = require("@octokit/rest"); |
| 3 | + |
| 4 | +const octokit = new Octokit({ |
| 5 | + auth: process.env.GITHUB_TOKEN, |
| 6 | +}); |
| 7 | + |
| 8 | +async function closeOldIssues() { |
| 9 | + try { |
| 10 | + const owner = "jihong88"; |
| 11 | + const repo = "suneditor"; |
| 12 | + const issues = await octokit.issues.listForRepo({ |
| 13 | + owner, |
| 14 | + repo, |
| 15 | + state: "open", |
| 16 | + }); |
| 17 | + |
| 18 | + const sixWeeksAgo = new Date(); |
| 19 | + sixWeeksAgo.setDate(sixWeeksAgo.getDate() - 42); // 6 weeks |
| 20 | + |
| 21 | + for (const issue of issues.data) { |
| 22 | + const lastUpdated = new Date(issue.updated_at); |
| 23 | + if (lastUpdated < sixWeeksAgo) { |
| 24 | + const comment = { |
| 25 | + owner, |
| 26 | + repo, |
| 27 | + issue_number: issue.number, |
| 28 | + body: |
| 29 | + "Thank you for your engagement with the project.\n" + |
| 30 | + "Due to a lack of activity for over 6 weeks, this issue has been automatically closed." + |
| 31 | + "\nThis is part of the process to keep the project up-to-date.\n\n" + |
| 32 | + "If a new version has been released recently, please test your scenario with that version to see if the issue persists.\n" + |
| 33 | + "If the problem still exists or if you believe this issue is still relevant, \n" + |
| 34 | + "feel free to reopen it and provide additional comments.\n\n" + |
| 35 | + "I truly appreciate your continuous interest and support for the project. Your feedback is crucial in improving its quality.", |
| 36 | + }; |
| 37 | + await octokit.issues.createComment(comment); |
| 38 | + |
| 39 | + await octokit.issues.update({ |
| 40 | + owner, |
| 41 | + repo, |
| 42 | + issue_number: issue.number, |
| 43 | + state: "closed", |
| 44 | + }); |
| 45 | + } |
| 46 | + } |
| 47 | + } catch (error) { |
| 48 | + console.error(`Error while closing issues: ${error}`); |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +closeOldIssues(); |
0 commit comments