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 { GITHUB_API_URL, GITHUB_SERVER_URL } from "../github/api/config";
import type { GitHubContext } from "../github/context";
import { isEntityContext } from "../github/context";
import { Octokit } from "@octokit/rest";
type PrepareConfigParams = {
@@ -115,7 +116,7 @@ export async function prepareMcpConfig(
const hasActionsReadPermission =
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
const actuallyHasPermission = await checkActionsReadPermission(
process.env.ACTIONS_TOKEN || "",
@@ -141,8 +142,7 @@ export async function prepareMcpConfig(
GITHUB_TOKEN: process.env.ACTIONS_TOKEN,
REPO_OWNER: owner,
REPO_NAME: repo,
PR_NUMBER:
"entityNumber" in context
PR_NUMBER: isEntityContext(context)
? context.entityNumber?.toString() || ""
: "",
RUNNER_TEMP: process.env.RUNNER_TEMP || "/tmp",