Skip to content

Commit

Permalink
Update close-old-issues.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTitusTech committed Feb 7, 2024
1 parent f39deab commit 92fa857
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions .github/workflows/close-old-issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,43 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const octokit = context.octokit;
const octokit = github.getOctokit();
// Get the repository owner and name
const { owner, repo } = context.repo;
const { owner, repo } = github.context.repo;
// Define the inactivity period (14 days)
const inactivityPeriod = new Date();
inactivityPeriod.setDate(inactivityPeriod.getDate() - 14);
// Get all open issues
const { data: issues } = await octokit.rest.issues.listForRepo({
owner,
repo,
state: 'open',
});
// Close issues inactive for more than the inactivity period
for (const issue of issues) {
const lastCommentDate = issue.updated_at;
if (new Date(lastCommentDate) < inactivityPeriod) {
// Close the issue and add a comment
await octokit.rest.issues.update({
owner,
repo,
issue_number: issue.number,
state: 'closed',
});
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: 'Closed due to inactivity',
});
async function run() {
// Get all open issues
const issues = await octokit.issues.listForRepo({
owner,
repo,
state: 'open',
});
// Close issues inactive for more than the inactivity period
for (const issue of issues.data) {
const lastCommentDate = issue.updated_at;
if (new Date(lastCommentDate) < inactivityPeriod) {
// Close the issue and add a comment
await octokit.issues.update({
owner,
repo,
issue_number: issue.number,
state: 'closed',
});
await octokit.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: 'Closed due to inactivity',
});
}
}
}
}
run().catch(error => console.error(error));

0 comments on commit 92fa857

Please sign in to comment.