Skip to content

Commit b991927

Browse files
committed
refactor: improve code organization and documentation
- Replace single HTTP_NOT_FOUND constant with HttpStatusCode enum - Add comprehensive JSDoc documentation for RcaFormResponse interface - Move SheetsV4 type alias to top of file with other type definitions - Better code organization with all types grouped at the top
1 parent 195420a commit b991927

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { context, getOctokit } from '@actions/github';
66
// @ts-ignore - googleapis types may not be available locally
77
import { google } from 'googleapis';
88

9-
// HTTP status codes
10-
const HTTP_NOT_FOUND = 404;
9+
// HTTP status codes enum for better maintainability
10+
enum HttpStatusCode {
11+
NotFound = 404,
12+
}
1113

1214
interface Label {
1315
name: string;
@@ -21,12 +23,23 @@ const RCA_NEEDED_LABEL: Label = {
2123
description: 'Issue requires Root Cause Analysis',
2224
};
2325

26+
// Type alias for Google Sheets v4 API
27+
// @ts-ignore - googleapis types may not be available locally
28+
type SheetsV4 = ReturnType<typeof google.sheets>;
29+
2430
// Google Sheets configuration from environment variables
2531
// @ts-ignore - process is available at runtime in GitHub Actions
2632
const SPREADSHEET_ID = process.env.SPREADSHEET_ID;
2733
// @ts-ignore - process is available at runtime in GitHub Actions
2834
const SHEET_NAME = process.env.SHEET_NAME;
2935

36+
/**
37+
* Represents a single response row from the RCA (Root Cause Analysis) Google Form.
38+
* @property issueNumber - The GitHub issue number associated with this RCA response (as a string)
39+
* @property timestamp - The timestamp when the form was submitted
40+
* @property [key: string] - Any additional form fields captured from the Google Form.
41+
* The keys correspond to column headers in the Google Sheet, and the values are the user responses.
42+
*/
3043
interface RcaFormResponse {
3144
issueNumber: string;
3245
timestamp: string;
@@ -209,10 +222,6 @@ async function main(): Promise<void> {
209222
}
210223
}
211224

212-
// Type alias for Google Sheets v4 API
213-
// @ts-ignore - googleapis types may not be available locally
214-
type SheetsV4 = ReturnType<typeof google.sheets>;
215-
216225
async function initializeGoogleSheets(credentials: string): Promise<SheetsV4> {
217226
// Decode base64 credentials
218227
const credentialsJson = JSON.parse(
@@ -373,7 +382,7 @@ async function removeLabelFromIssue(
373382
} catch (error: any) {
374383
// If label doesn't exist on issue, the API will throw 404
375384
// This is not an error for our use case, so we can safely ignore it
376-
if (error?.status !== HTTP_NOT_FOUND) {
385+
if (error?.status !== HttpStatusCode.NotFound) {
377386
throw error;
378387
}
379388
}

0 commit comments

Comments
 (0)