mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-29 01:11:30 -06:00
Update Github Actions Auto Close Issues (#1801)
* Update Github Actions Auto Close Issues * Add try-catch & Error Logging in Github Actions Auto Close Issues * Add a Break Statement To Skip Checking The Remaining Labels of an Issue in Github Actions Auto Close Issues
This commit is contained in:
parent
72f6ca17e5
commit
50090efcef
29
.github/workflows/close-old-issues.yaml
vendored
29
.github/workflows/close-old-issues.yaml
vendored
@ -25,6 +25,8 @@ jobs:
|
||||
const inactivityPeriod = new Date();
|
||||
inactivityPeriod.setDate(inactivityPeriod.getDate() - 14);
|
||||
|
||||
const labelKeepIssue = 'Keep Issue Open';
|
||||
|
||||
try {
|
||||
// Get all open issues with pagination
|
||||
for await (const response of octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
|
||||
@ -36,6 +38,33 @@ jobs:
|
||||
|
||||
// Close issues inactive for more than the inactivity period
|
||||
for (const issue of issues) {
|
||||
const closeIssue = true;
|
||||
|
||||
// Get all Labels of issue, and compared each label with the labelKeepIssue const variable
|
||||
try {
|
||||
const respondIssueLabels = await octokit.request("GET /repos/{owner}/{repo}/issues/{issue_number}/labels", {
|
||||
owner: owner,
|
||||
repo: repo,
|
||||
issue_number: issue.number
|
||||
});
|
||||
const labels = respondIssueLabels.data;
|
||||
|
||||
for (let i = 0; i < labels.length; i++) {
|
||||
const label = labels[i]
|
||||
if (label.name === labelKeepIssue) {
|
||||
console.log(`Issue #${issue.number} will not be closed`);
|
||||
closeIssue = false;
|
||||
break; // Break from the loop, no need to check the remaining Labels.
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error while Fetching Labels for Issue #${issue.number}, Error: ${error}`);
|
||||
}
|
||||
|
||||
if (!closeIssue) {
|
||||
continue; // Skip the next bit of code
|
||||
}
|
||||
|
||||
const lastCommentDate = issue.updated_at;
|
||||
if (new Date(lastCommentDate) < inactivityPeriod) {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user