mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
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:
@@ -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,8 +142,7 @@ 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",
|
||||||
|
|||||||
Reference in New Issue
Block a user