mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
refactor: move allowedBots parameter to context object
Move allowedBots from function parameter to context.inputs to maintain consistency with other input handling throughout the codebase. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -48,8 +48,7 @@ async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step 5: Check if actor is human
|
// Step 5: Check if actor is human
|
||||||
const allowedBots = process.env.ALLOWED_BOTS || "";
|
await checkHumanActor(octokit.rest, context);
|
||||||
await checkHumanActor(octokit.rest, context, allowedBots);
|
|
||||||
|
|
||||||
// Step 6: Create initial tracking comment
|
// Step 6: Create initial tracking comment
|
||||||
const commentData = await createInitialComment(octokit.rest, context);
|
const commentData = await createInitialComment(octokit.rest, context);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export type ParsedGitHubContext = {
|
|||||||
useStickyComment: boolean;
|
useStickyComment: boolean;
|
||||||
additionalPermissions: Map<string, string>;
|
additionalPermissions: Map<string, string>;
|
||||||
useCommitSigning: boolean;
|
useCommitSigning: boolean;
|
||||||
|
allowedBots: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,6 +71,7 @@ export function parseGitHubContext(): ParsedGitHubContext {
|
|||||||
process.env.ADDITIONAL_PERMISSIONS ?? "",
|
process.env.ADDITIONAL_PERMISSIONS ?? "",
|
||||||
),
|
),
|
||||||
useCommitSigning: process.env.USE_COMMIT_SIGNING === "true",
|
useCommitSigning: process.env.USE_COMMIT_SIGNING === "true",
|
||||||
|
allowedBots: process.env.ALLOWED_BOTS ?? "",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import type { ParsedGitHubContext } from "../context";
|
|||||||
export async function checkHumanActor(
|
export async function checkHumanActor(
|
||||||
octokit: Octokit,
|
octokit: Octokit,
|
||||||
githubContext: ParsedGitHubContext,
|
githubContext: ParsedGitHubContext,
|
||||||
allowedBots: string,
|
|
||||||
) {
|
) {
|
||||||
// Fetch user information from GitHub API
|
// Fetch user information from GitHub API
|
||||||
const { data: userData } = await octokit.users.getByUsername({
|
const { data: userData } = await octokit.users.getByUsername({
|
||||||
@@ -24,6 +23,8 @@ export async function checkHumanActor(
|
|||||||
|
|
||||||
// Check bot permissions if actor is not a User
|
// Check bot permissions if actor is not a User
|
||||||
if (actorType !== "User") {
|
if (actorType !== "User") {
|
||||||
|
const allowedBots = githubContext.inputs.allowedBots;
|
||||||
|
|
||||||
// Parse allowed bots list
|
// Parse allowed bots list
|
||||||
const allowedBotsList = allowedBots
|
const allowedBotsList = allowedBots
|
||||||
.split(",")
|
.split(",")
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ describe("checkHumanActor", () => {
|
|||||||
context.actor = "human-user";
|
context.actor = "human-user";
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
checkHumanActor(mockOctokit, context, ""),
|
checkHumanActor(mockOctokit, context),
|
||||||
).resolves.toBeUndefined();
|
).resolves.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,8 +32,9 @@ describe("checkHumanActor", () => {
|
|||||||
const mockOctokit = createMockOctokit("Bot");
|
const mockOctokit = createMockOctokit("Bot");
|
||||||
const context = createMockContext();
|
const context = createMockContext();
|
||||||
context.actor = "test-bot";
|
context.actor = "test-bot";
|
||||||
|
context.inputs.allowedBots = "";
|
||||||
|
|
||||||
await expect(checkHumanActor(mockOctokit, context, "")).rejects.toThrow(
|
await expect(checkHumanActor(mockOctokit, context)).rejects.toThrow(
|
||||||
"Workflow initiated by non-human actor: test-bot (type: Bot). Add bot to allowed_bots list or use '*' to allow all bots.",
|
"Workflow initiated by non-human actor: test-bot (type: Bot). Add bot to allowed_bots list or use '*' to allow all bots.",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -42,9 +43,10 @@ describe("checkHumanActor", () => {
|
|||||||
const mockOctokit = createMockOctokit("Bot");
|
const mockOctokit = createMockOctokit("Bot");
|
||||||
const context = createMockContext();
|
const context = createMockContext();
|
||||||
context.actor = "test-bot";
|
context.actor = "test-bot";
|
||||||
|
context.inputs.allowedBots = "*";
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
checkHumanActor(mockOctokit, context, "*"),
|
checkHumanActor(mockOctokit, context),
|
||||||
).resolves.toBeUndefined();
|
).resolves.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -52,9 +54,10 @@ describe("checkHumanActor", () => {
|
|||||||
const mockOctokit = createMockOctokit("Bot");
|
const mockOctokit = createMockOctokit("Bot");
|
||||||
const context = createMockContext();
|
const context = createMockContext();
|
||||||
context.actor = "dependabot";
|
context.actor = "dependabot";
|
||||||
|
context.inputs.allowedBots = "dependabot,renovate";
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
checkHumanActor(mockOctokit, context, "dependabot,renovate"),
|
checkHumanActor(mockOctokit, context),
|
||||||
).resolves.toBeUndefined();
|
).resolves.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -62,10 +65,9 @@ describe("checkHumanActor", () => {
|
|||||||
const mockOctokit = createMockOctokit("Bot");
|
const mockOctokit = createMockOctokit("Bot");
|
||||||
const context = createMockContext();
|
const context = createMockContext();
|
||||||
context.actor = "other-bot";
|
context.actor = "other-bot";
|
||||||
|
context.inputs.allowedBots = "dependabot,renovate";
|
||||||
|
|
||||||
await expect(
|
await expect(checkHumanActor(mockOctokit, context)).rejects.toThrow(
|
||||||
checkHumanActor(mockOctokit, context, "dependabot,renovate"),
|
|
||||||
).rejects.toThrow(
|
|
||||||
"Workflow initiated by non-human actor: other-bot (type: Bot). Add bot to allowed_bots list or use '*' to allow all bots.",
|
"Workflow initiated by non-human actor: other-bot (type: Bot). Add bot to allowed_bots list or use '*' to allow all bots.",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ describe("prepareMcpConfig", () => {
|
|||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
additionalPermissions: new Map(),
|
additionalPermissions: new Map(),
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
allowedBots: "",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const defaultInputs = {
|
|||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
additionalPermissions: new Map<string, string>(),
|
additionalPermissions: new Map<string, string>(),
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
allowedBots: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultRepository = {
|
const defaultRepository = {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ describe("checkContainsTrigger", () => {
|
|||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
additionalPermissions: new Map(),
|
additionalPermissions: new Map(),
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
allowedBots: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(checkContainsTrigger(context)).toBe(true);
|
expect(checkContainsTrigger(context)).toBe(true);
|
||||||
@@ -70,6 +71,7 @@ describe("checkContainsTrigger", () => {
|
|||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
additionalPermissions: new Map(),
|
additionalPermissions: new Map(),
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
allowedBots: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(checkContainsTrigger(context)).toBe(false);
|
expect(checkContainsTrigger(context)).toBe(false);
|
||||||
@@ -285,6 +287,7 @@ describe("checkContainsTrigger", () => {
|
|||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
additionalPermissions: new Map(),
|
additionalPermissions: new Map(),
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
allowedBots: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(checkContainsTrigger(context)).toBe(true);
|
expect(checkContainsTrigger(context)).toBe(true);
|
||||||
@@ -317,6 +320,7 @@ describe("checkContainsTrigger", () => {
|
|||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
additionalPermissions: new Map(),
|
additionalPermissions: new Map(),
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
allowedBots: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(checkContainsTrigger(context)).toBe(true);
|
expect(checkContainsTrigger(context)).toBe(true);
|
||||||
@@ -349,6 +353,7 @@ describe("checkContainsTrigger", () => {
|
|||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
additionalPermissions: new Map(),
|
additionalPermissions: new Map(),
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
allowedBots: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(checkContainsTrigger(context)).toBe(false);
|
expect(checkContainsTrigger(context)).toBe(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user