Skip to content

Close Abandoned Issues #19

Close Abandoned Issues

Close Abandoned Issues #19

name: Close Abandoned Issues
on:
schedule:
- cron: "0 */24 * * *"
jobs:
close-labeler:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Close the abandoned issue
uses: actions/github-script@v6
env:
daysInterval: ${{ vars.MONITORING_INTERVAL_DAYS }}
with:
script: |
const { owner, repo } = context.repo;
const abandonedLabel = "Status: Abandoned";
const parsedDays = parseFloat("${{ env.daysInterval }}");
const timeThreshold = parsedDays * 24 * 60 * 60 * 1000;
const issuesResponse = await github.rest.issues.listForRepo({
owner,
repo,
labels: abandonedLabel,
state: "open",
});
for (const issue of issuesResponse.data) {
const updatedAt = new Date(issue.updated_at).getTime();
const currentTime = new Date().getTime();
const updateMessage = `Greetings,
It's been more than ${parsedDays} days since this issue was identified as abandoned.
We have closed this issue due to inactivity, please feel free to re-open it if you have more information to share.`;
if (currentTime - updatedAt > timeThreshold) {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: issue.number,
name: abandonedLabel,
});
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: updateMessage,
});
await github.rest.issues.update({
owner,
repo,
issue_number: issue.number,
state: "closed",
});
}
}