fix: use proper type guards instead of manual property checks

Address review feedback by using isEntityContext() type guard instead of
checking 'isPR' in context manually. This provides better type safety
and uses the existing type guard infrastructure.
This commit is contained in:
km-anthropic
2025-08-01 15:43:07 -07:00
parent 9abdfa8a3a
commit 340104d9cf

View File

@@ -1,6 +1,7 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import { GITHUB_API_URL, GITHUB_SERVER_URL } from "../github/api/config"; import { GITHUB_API_URL, GITHUB_SERVER_URL } from "../github/api/config";
import type { GitHubContext } from "../github/context"; import type { GitHubContext } from "../github/context";
import { isEntityContext } from "../github/context";
import { Octokit } from "@octokit/rest"; import { Octokit } from "@octokit/rest";
type PrepareConfigParams = { type PrepareConfigParams = {
@@ -115,7 +116,7 @@ export async function prepareMcpConfig(
const hasActionsReadPermission = const hasActionsReadPermission =
context.inputs.additionalPermissions.get("actions") === "read"; context.inputs.additionalPermissions.get("actions") === "read";
if ("isPR" in context && context.isPR && hasActionsReadPermission) { if (isEntityContext(context) && context.isPR && hasActionsReadPermission) {
// Verify the token actually has actions:read permission // Verify the token actually has actions:read permission
const actuallyHasPermission = await checkActionsReadPermission( const actuallyHasPermission = await checkActionsReadPermission(
process.env.ACTIONS_TOKEN || "", process.env.ACTIONS_TOKEN || "",
@@ -141,10 +142,9 @@ export async function prepareMcpConfig(
GITHUB_TOKEN: process.env.ACTIONS_TOKEN, GITHUB_TOKEN: process.env.ACTIONS_TOKEN,
REPO_OWNER: owner, REPO_OWNER: owner,
REPO_NAME: repo, REPO_NAME: repo,
PR_NUMBER: PR_NUMBER: isEntityContext(context)
"entityNumber" in context ? context.entityNumber?.toString() || ""
? context.entityNumber?.toString() || "" : "",
: "",
RUNNER_TEMP: process.env.RUNNER_TEMP || "/tmp", RUNNER_TEMP: process.env.RUNNER_TEMP || "/tmp",
}, },
}; };