Skip to content

Commit fa6dd86

Browse files
authored
Remove @ts-nocheck from 15 .cjs files and fix type errors (#7909)
1 parent e063e0a commit fa6dd86

16 files changed

Lines changed: 98 additions & 61 deletions

actions/setup/js/add_copilot_reviewer.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
/**
@@ -52,7 +52,7 @@ Successfully added Copilot as a reviewer to PR #${prNumber}.
5252
)
5353
.write();
5454
} catch (error) {
55-
const errorMessage = error?.message ?? String(error);
55+
const errorMessage = error instanceof Error ? error.message : String(error);
5656
core.error(`Failed to add Copilot as reviewer: ${errorMessage}`);
5757
core.setFailed(`Failed to add Copilot as reviewer to PR #${prNumber}: ${errorMessage}`);
5858
}

actions/setup/js/add_reviewer.cjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
const { processSafeOutput, processItems } = require("./safe_output_processor.cjs");
@@ -50,8 +50,8 @@ async function main() {
5050
core.setFailed("Internal error: config, targetResult, or targetResult.number is undefined");
5151
return;
5252
}
53-
const { allowed: allowedReviewers, maxCount } = config;
54-
const prNumber = targetResult.number;
53+
const { allowed: allowedReviewers, maxCount = 1 } = config;
54+
const prNumber = /** @type {number} */ (targetResult.number);
5555

5656
const requestedReviewers = reviewerItem.reviewers || [];
5757
core.info(`Requested reviewers: ${JSON.stringify(requestedReviewers)}`);
@@ -103,7 +103,8 @@ No reviewers were added (no valid reviewers found in agent output).
103103
});
104104
core.info(`Successfully added copilot as reviewer to PR #${prNumber}`);
105105
} catch (copilotError) {
106-
core.warning(`Failed to add copilot as reviewer: ${copilotError?.message ?? String(copilotError)}`);
106+
const copilotErrorMsg = copilotError instanceof Error ? copilotError.message : String(copilotError);
107+
core.warning(`Failed to add copilot as reviewer: ${copilotErrorMsg}`);
107108
// Don't fail the whole step if copilot reviewer fails
108109
}
109110
}
@@ -123,7 +124,7 @@ ${reviewersListMarkdown}
123124
)
124125
.write();
125126
} catch (error) {
126-
const errorMessage = error?.message ?? String(error);
127+
const errorMessage = error instanceof Error ? error.message : String(error);
127128
core.error(`Failed to add reviewers: ${errorMessage}`);
128129
core.setFailed(`Failed to add reviewers: ${errorMessage}`);
129130
}

actions/setup/js/assign_agent_helpers.cjs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
/**
@@ -59,7 +59,8 @@ async function getAvailableAgentLogins(owner, repo) {
5959
const available = actors.filter(actor => actor?.login && knownValues.includes(actor.login)).map(actor => actor.login);
6060
return available.sort();
6161
} catch (e) {
62-
core.debug(`Failed to list available agent logins: ${e?.message ?? String(e)}`);
62+
const errorMessage = e instanceof Error ? e.message : String(e);
63+
core.debug(`Failed to list available agent logins: ${errorMessage}`);
6364
return [];
6465
}
6566
}
@@ -117,7 +118,8 @@ async function findAgent(owner, repo, agentName) {
117118
}
118119
return null;
119120
} catch (error) {
120-
core.error(`Failed to find ${agentName} agent: ${error?.message ?? String(error)}`);
121+
const errorMessage = error instanceof Error ? error.message : String(error);
122+
core.error(`Failed to find ${agentName} agent: ${errorMessage}`);
121123
return null;
122124
}
123125
}
@@ -161,7 +163,8 @@ async function getIssueDetails(owner, repo, issueNumber) {
161163
currentAssignees,
162164
};
163165
} catch (error) {
164-
core.error(`Failed to get issue details: ${error?.message ?? String(error)}`);
166+
const errorMessage = error instanceof Error ? error.message : String(error);
167+
core.error(`Failed to get issue details: ${errorMessage}`);
165168
return null;
166169
}
167170
}
@@ -204,21 +207,22 @@ async function assignAgentToIssue(issueId, agentId, currentAssignees, agentName)
204207
core.error("Unexpected response from GitHub API");
205208
return false;
206209
} catch (error) {
207-
const errorMessage = error?.message ?? String(error);
210+
const errorMessage = error instanceof Error ? error.message : String(error);
208211

209212
// Debug: surface the raw GraphQL error structure for troubleshooting fine-grained permission issues
210213
try {
211214
core.debug(`Raw GraphQL error message: ${errorMessage}`);
212215
if (error && typeof error === "object") {
213216
// Common GraphQL error shapes: error.errors (array), error.data, error.response
217+
const err = /** @type {any} */ (error);
214218
const details = {
215-
...(error.errors && { errors: error.errors }),
216-
...(error.response && { response: error.response }),
217-
...(error.data && { data: error.data }),
219+
...(err.errors && { errors: err.errors }),
220+
...(err.response && { response: err.response }),
221+
...(err.data && { data: err.data }),
218222
};
219223
// If GitHub returns an array of errors with 'type'/'message'
220-
if (Array.isArray(error.errors)) {
221-
details.compactMessages = error.errors.map(e => e.message).filter(Boolean);
224+
if (Array.isArray(err.errors)) {
225+
details.compactMessages = err.errors.map(e => e.message).filter(Boolean);
222226
}
223227
const serialized = JSON.stringify(details, null, 2);
224228
if (serialized !== "{}") {
@@ -233,7 +237,8 @@ async function assignAgentToIssue(issueId, agentId, currentAssignees, agentName)
233237
}
234238
} catch (loggingErr) {
235239
// Never fail assignment because of debug logging
236-
core.debug(`Failed to serialize GraphQL error details: ${loggingErr?.message ?? String(loggingErr)}`);
240+
const loggingErrMsg = loggingErr instanceof Error ? loggingErr.message : String(loggingErr);
241+
core.debug(`Failed to serialize GraphQL error details: ${loggingErrMsg}`);
237242
}
238243

239244
// Check for permission-related errors
@@ -263,7 +268,8 @@ async function assignAgentToIssue(issueId, agentId, currentAssignees, agentName)
263268
}
264269
core.warning("Fallback mutation returned unexpected response; proceeding with permission guidance.");
265270
} catch (fallbackError) {
266-
core.error(`Fallback addAssigneesToAssignable failed: ${fallbackError?.message ?? String(fallbackError)}`);
271+
const fallbackErrMsg = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
272+
core.error(`Fallback addAssigneesToAssignable failed: ${fallbackErrMsg}`);
267273
}
268274
logPermissionError(agentName);
269275
} else {
@@ -392,7 +398,8 @@ async function assignAgentToIssueByName(owner, repo, issueNumber, agentName) {
392398
core.info(`Successfully assigned ${agentName} coding agent to issue #${issueNumber}`);
393399
return { success: true };
394400
} catch (error) {
395-
return { success: false, error: error?.message ?? String(error) };
401+
const errorMessage = error instanceof Error ? error.message : String(error);
402+
return { success: false, error: errorMessage };
396403
}
397404
}
398405

actions/setup/js/assign_copilot_to_created_issues.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
const { AGENT_LOGIN_NAMES, findAgent, getIssueDetails, assignAgentToIssue, generatePermissionErrorSummary } = require("./assign_agent_helpers.cjs");
@@ -109,7 +109,7 @@ async function main() {
109109
success: true,
110110
});
111111
} catch (error) {
112-
const errorMessage = error?.message ?? String(error);
112+
const errorMessage = error instanceof Error ? error.message : String(error);
113113
core.error(`Failed to assign ${agentName} to issue #${issueNumber} in ${repoSlug}: ${errorMessage}`);
114114
results.push({
115115
repo: repoSlug,

actions/setup/js/assign_issue.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
const { getAgentName, getIssueDetails, findAgent, assignAgentToIssue } = require("./assign_agent_helpers.cjs");
@@ -95,7 +95,7 @@ Successfully assigned issue #${trimmedIssueNumber} to \`${trimmedAssignee}\`.
9595
)
9696
.write();
9797
} catch (error) {
98-
const errorMessage = error?.message ?? String(error);
98+
const errorMessage = error instanceof Error ? error.message : String(error);
9999
core.error(`Failed to assign issue: ${errorMessage}`);
100100
core.setFailed(`Failed to assign issue #${trimmedIssueNumber} to ${trimmedAssignee}: ${errorMessage}`);
101101
}

actions/setup/js/assign_milestone.cjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
const { processSafeOutput } = require("./safe_output_processor.cjs");
@@ -41,7 +41,7 @@ async function main() {
4141
core.setFailed("Internal error: config or milestoneItems is undefined");
4242
return;
4343
}
44-
const { allowed: allowedMilestones, maxCount } = config;
44+
const { allowed: allowedMilestones, maxCount = 1 } = config;
4545

4646
// Limit items to max count
4747
const itemsToProcess = milestoneItems.slice(0, maxCount);
@@ -62,7 +62,7 @@ async function main() {
6262
allMilestones = milestonesResponse.data;
6363
core.info(`Fetched ${allMilestones.length} milestones from repository`);
6464
} catch (error) {
65-
const errorMessage = error?.message ?? String(error);
65+
const errorMessage = error instanceof Error ? error.message : String(error);
6666
core.error(`Failed to fetch milestones: ${errorMessage}`);
6767
core.setFailed(`Failed to fetch milestones for validation: ${errorMessage}`);
6868
return;
@@ -86,7 +86,7 @@ async function main() {
8686
}
8787

8888
// Validate against allowed list if configured
89-
if (allowedMilestones?.length > 0) {
89+
if (allowedMilestones && allowedMilestones.length > 0) {
9090
const milestone = allMilestones.find(m => m.number === milestoneNumber);
9191

9292
if (!milestone) {
@@ -119,7 +119,7 @@ async function main() {
119119
success: true,
120120
});
121121
} catch (error) {
122-
const errorMessage = error?.message ?? String(error);
122+
const errorMessage = error instanceof Error ? error.message : String(error);
123123
core.error(`Failed to assign milestone #${milestoneNumber} to issue #${issueNumber}: ${errorMessage}`);
124124
results.push({
125125
issue_number: issueNumber,

actions/setup/js/assign_to_agent.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
const { loadAgentOutput } = require("./load_agent_output.cjs");
@@ -148,7 +148,7 @@ async function main() {
148148
success: true,
149149
});
150150
} catch (error) {
151-
let errorMessage = error?.message ?? String(error);
151+
let errorMessage = error instanceof Error ? error.message : String(error);
152152
if (errorMessage.includes("coding agent is not available for this repository")) {
153153
// Enrich with available agent logins to aid troubleshooting - uses built-in github object
154154
try {

actions/setup/js/assign_to_user.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
const { processSafeOutput, processItems } = require("./safe_output_processor.cjs");
@@ -49,7 +49,7 @@ async function main() {
4949
core.setFailed("Internal error: config, targetResult, or targetResult.number is undefined");
5050
return;
5151
}
52-
const { allowed: allowedAssignees, maxCount } = config;
52+
const { allowed: allowedAssignees, maxCount = 1 } = config;
5353
const issueNumber = targetResult.number;
5454

5555
// Support both singular "assignee" and plural "assignees" for flexibility

actions/setup/js/check_workflow_timestamp_api.cjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
/**
@@ -40,15 +40,20 @@ async function main() {
4040

4141
if (response.data && response.data.length > 0) {
4242
const commit = response.data[0];
43+
const committerDate = commit.commit.committer?.date;
44+
if (!committerDate) {
45+
return null;
46+
}
4347
return {
4448
sha: commit.sha,
45-
date: commit.commit.committer.date,
49+
date: committerDate,
4650
message: commit.commit.message,
4751
};
4852
}
4953
return null;
5054
} catch (error) {
51-
core.info(`Could not fetch commit for ${path}: ${error.message}`);
55+
const errorMessage = error instanceof Error ? error.message : String(error);
56+
core.info(`Could not fetch commit for ${path}: ${errorMessage}`);
5257
return null;
5358
}
5459
}

actions/setup/js/interpolate_prompt.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
1+
// @ts-check
22
/// <reference types="@actions/github-script" />
33

44
// interpolate_prompt.cjs
@@ -89,6 +89,7 @@ async function main() {
8989
}
9090

9191
// Step 2: Interpolate variables
92+
/** @type {Record<string, string>} */
9293
const variables = {};
9394
for (const [key, value] of Object.entries(process.env)) {
9495
if (key.startsWith("GH_AW_EXPR_")) {

0 commit comments

Comments
 (0)