2024-02-06 14:02:58 -06:00
|
|
|
name: Close Inactive Issues
|
|
|
|
|
|
|
|
on:
|
|
|
|
schedule:
|
|
|
|
- cron: '0 0 * * *' # Run daily
|
2024-02-21 11:12:49 -06:00
|
|
|
workflow_dispatch: # This line enables manual triggering
|
2024-02-06 14:02:58 -06:00
|
|
|
jobs:
|
|
|
|
close-issues:
|
|
|
|
runs-on: ubuntu-latest
|
2024-02-21 11:12:49 -06:00
|
|
|
permissions:
|
|
|
|
issues: write # Ensure necessary permissions for issues
|
2024-02-06 14:02:58 -06:00
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Close inactive issues
|
|
|
|
uses: actions/github-script@v7
|
|
|
|
with:
|
|
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
script: |
|
2024-02-21 11:12:49 -06:00
|
|
|
const octokit = github;
|
2024-02-06 14:02:58 -06:00
|
|
|
|
|
|
|
// Get the repository owner and name
|
2024-02-21 11:12:49 -06:00
|
|
|
const { owner, repo } = context.repo;
|
2024-02-06 14:02:58 -06:00
|
|
|
|
|
|
|
// Define the inactivity period (14 days)
|
|
|
|
const inactivityPeriod = new Date();
|
|
|
|
inactivityPeriod.setDate(inactivityPeriod.getDate() - 14);
|
|
|
|
|
2024-02-21 11:12:49 -06:00
|
|
|
try {
|
|
|
|
// Get all open issues with pagination
|
|
|
|
for await (const response of octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
|
2024-02-07 17:03:51 -06:00
|
|
|
owner,
|
|
|
|
repo,
|
|
|
|
state: 'open',
|
2024-02-21 11:12:49 -06:00
|
|
|
})) {
|
|
|
|
const issues = response.data;
|
2024-02-07 17:03:51 -06:00
|
|
|
|
2024-02-21 11:12:49 -06:00
|
|
|
// Close issues inactive for more than the inactivity period
|
|
|
|
for (const issue of issues) {
|
|
|
|
const lastCommentDate = issue.updated_at;
|
|
|
|
if (new Date(lastCommentDate) < inactivityPeriod) {
|
|
|
|
try {
|
|
|
|
// Close the issue
|
|
|
|
await octokit.rest.issues.update({
|
|
|
|
owner,
|
|
|
|
repo,
|
|
|
|
issue_number: issue.number,
|
|
|
|
state: 'closed',
|
|
|
|
});
|
2024-02-07 17:03:51 -06:00
|
|
|
|
2024-02-21 11:12:49 -06:00
|
|
|
// Add a comment
|
|
|
|
await octokit.rest.issues.createComment({
|
|
|
|
owner,
|
|
|
|
repo,
|
|
|
|
issue_number: issue.number,
|
|
|
|
body: 'Closed due to inactivity',
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Error updating or commenting on issue #${issue.number}: ${error}`);
|
|
|
|
}
|
|
|
|
}
|
2024-02-07 17:03:51 -06:00
|
|
|
}
|
2024-02-06 14:02:58 -06:00
|
|
|
}
|
2024-02-21 11:12:49 -06:00
|
|
|
} catch (error) {
|
|
|
|
console.error(`Error fetching issues: ${error}`);
|
2024-02-07 17:03:51 -06:00
|
|
|
}
|