-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe08cf0
commit e186779
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Auto Close Inactive Issues | ||
|
||
on: | ||
schedule: | ||
# Runs at 00:00 UTC every day | ||
- cron: '0 0 * * *' | ||
|
||
jobs: | ||
close-inactive-issues: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Close inactive issues | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const { Octokit } = require("@octokit/core"); | ||
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }); | ||
const owner = context.repo.owner; | ||
const repo = context.repo.repo; | ||
const label = "awaiting user"; // Label to filter issues | ||
const inactiveDays = 90; // 3 months | ||
const closingComment = "Closed due to inactivity."; | ||
const issues = await octokit.request('GET /repos/{owner}/{repo}/issues', { | ||
owner, | ||
repo, | ||
labels: label, | ||
state: 'open', | ||
per_page: 100, | ||
}); | ||
const now = new Date(); | ||
for (const issue of issues.data) { | ||
const lastUpdated = new Date(issue.updated_at); | ||
const differenceInDays = Math.floor((now - lastUpdated) / (1000 * 3600 * 24)); | ||
if (differenceInDays >= inactiveDays) { | ||
// Post a comment before closing the issue | ||
await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { | ||
owner, | ||
repo, | ||
issue_number: issue.number, | ||
body: closingComment, | ||
}); | ||
// Close the issue | ||
await octokit.request('PATCH /repos/{owner}/{repo}/issues/{issue_number}', { | ||
owner, | ||
repo, | ||
issue_number: issue.number, | ||
state: 'closed', | ||
}); | ||
} | ||
} | ||
env: | ||
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' |