Skip to content

Commit 0ccbd2a

Browse files
committed
refactor: address additional Copilot review feedback
- Replace process.exit() with early returns after core.setFailed() - Add @ts-ignore comments for process.env and Buffer usage - Improve error handling consistency throughout the script - core.setFailed() already handles exit codes properly
1 parent eee20bc commit 0ccbd2a

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

.github/scripts/remove-rca-needed-label-sheets.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const RCA_NEEDED_LABEL: Label = {
2121
};
2222

2323
// Google Sheets configuration from environment variables
24+
// @ts-ignore - process is available at runtime in GitHub Actions
2425
const SPREADSHEET_ID = process.env.SPREADSHEET_ID;
26+
// @ts-ignore - process is available at runtime in GitHub Actions
2527
const SHEET_NAME = process.env.SHEET_NAME;
2628

2729
interface RcaFormResponse {
@@ -32,29 +34,32 @@ interface RcaFormResponse {
3234

3335
async function main(): Promise<void> {
3436
try {
37+
// @ts-ignore - process is available at runtime in GitHub Actions
3538
const githubToken = process.env.GITHUB_TOKEN;
3639
if (!githubToken) {
3740
core.setFailed('GITHUB_TOKEN not found');
38-
process.exit(1);
41+
return; // Exit early instead of process.exit()
3942
}
4043

4144
// Google Sheets API credentials (base64 encoded service account JSON)
45+
// @ts-ignore - process is available at runtime in GitHub Actions
4246
const googleCredentials = process.env.GOOGLE_SHEETS_CREDENTIALS;
4347
if (!googleCredentials) {
4448
core.setFailed('GOOGLE_SHEETS_CREDENTIALS not found');
45-
process.exit(1);
49+
return; // Exit early instead of process.exit()
4650
}
4751

4852
// Validate sheet configuration
4953
if (!SPREADSHEET_ID) {
5054
core.setFailed('SPREADSHEET_ID not configured');
51-
process.exit(1);
55+
return; // Exit early instead of process.exit()
5256
}
5357
if (!SHEET_NAME) {
5458
core.setFailed('SHEET_NAME not configured');
55-
process.exit(1);
59+
return; // Exit early instead of process.exit()
5660
}
5761

62+
// @ts-ignore - process is available at runtime in GitHub Actions
5863
const isDryRun = process.env.DRY_RUN === 'true';
5964

6065
const octokit: InstanceType<typeof GitHub> = getOctokit(githubToken);
@@ -159,7 +164,7 @@ async function main(): Promise<void> {
159164
// Set appropriate exit status
160165
if (failedCount > 0 && removedCount === 0) {
161166
core.setFailed('All label removal attempts failed');
162-
process.exit(1);
167+
return; // Exit early instead of process.exit()
163168
} else if (failedCount > 0) {
164169
console.log(
165170
`\n⚠️ Completed with ${failedCount} failures. Check logs for details.`,
@@ -171,13 +176,14 @@ async function main(): Promise<void> {
171176
core.setFailed(
172177
`Error in Google Sheets RCA label removal: ${error?.message || error}`,
173178
);
174-
process.exit(1);
179+
// No need for process.exit() - core.setFailed() handles the exit code
175180
}
176181
}
177182

178183
async function initializeGoogleSheets(credentials: string): Promise<any> {
179184
// Decode base64 credentials
180185
const credentialsJson = JSON.parse(
186+
// @ts-ignore - Buffer is available at runtime in GitHub Actions
181187
Buffer.from(credentials, 'base64').toString('utf-8'),
182188
);
183189

@@ -358,6 +364,7 @@ async function removeLabelFromIssue(
358364

359365
// Run the main function
360366
main().catch((error: Error): void => {
361-
console.error(error);
362-
process.exit(1);
367+
console.error('Unhandled error:', error);
368+
core.setFailed(`Unhandled error: ${error.message}`);
369+
// No need for process.exit() - core.setFailed() handles the exit code
363370
});

0 commit comments

Comments
 (0)