Add try-catch & Error Logging in Github Actions Auto Close Issues

This commit is contained in:
Mr.k 2024-04-04 16:20:18 +03:00
parent 9d1fae7917
commit 9978758327
No known key found for this signature in database

View File

@ -41,19 +41,23 @@ jobs:
const closeIssue = true; const closeIssue = true;
// Get all Labels of issue, and compared each label with the labelKeepIssue const variable // Get all Labels of issue, and compared each label with the labelKeepIssue const variable
const respondIssueLabels = await octokit.request("GET /repos/{owner}/{repo}/issues/{issue_number}/labels", { try {
owner: owner, const respondIssueLabels = await octokit.request("GET /repos/{owner}/{repo}/issues/{issue_number}/labels", {
repo: repo, owner: owner,
issue_number: issue.number repo: repo,
}); issue_number: issue.number
const labels = respondIssueLabels.data; });
const labels = respondIssueLabels.data;
for (let i = 0; i < labels.length; i++) { for (let i = 0; i < labels.length; i++) {
const label = labels[i] const label = labels[i]
if (label.name === labelKeepIssue) { if (label.name === labelKeepIssue) {
console.log(`Issue #${issue.number} will not be closed`); console.log(`Issue #${issue.number} will not be closed`);
closeIssue = false; closeIssue = false;
}
} }
} catch (error) {
console.error(`Error while Fetching Labels for Issue #${issue.number}, Error: ${error}`);
} }
if (!closeIssue) { if (!closeIssue) {