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:
Yuku Kotani
2025-07-21 16:10:35 +09:00
parent d46f8d940d
commit bf34e22e43
7 changed files with 21 additions and 10 deletions

View File

@@ -48,8 +48,7 @@ async function run() {
}
// Step 5: Check if actor is human
const allowedBots = process.env.ALLOWED_BOTS || "";
await checkHumanActor(octokit.rest, context, allowedBots);
await checkHumanActor(octokit.rest, context);
// Step 6: Create initial tracking comment
const commentData = await createInitialComment(octokit.rest, context);

View File

@@ -39,6 +39,7 @@ export type ParsedGitHubContext = {
useStickyComment: boolean;
additionalPermissions: Map<string, string>;
useCommitSigning: boolean;
allowedBots: string;
};
};
@@ -70,6 +71,7 @@ export function parseGitHubContext(): ParsedGitHubContext {
process.env.ADDITIONAL_PERMISSIONS ?? "",
),
useCommitSigning: process.env.USE_COMMIT_SIGNING === "true",
allowedBots: process.env.ALLOWED_BOTS ?? "",
},
};

View File

@@ -11,7 +11,6 @@ import type { ParsedGitHubContext } from "../context";
export async function checkHumanActor(
octokit: Octokit,
githubContext: ParsedGitHubContext,
allowedBots: string,
) {
// Fetch user information from GitHub API
const { data: userData } = await octokit.users.getByUsername({
@@ -24,6 +23,8 @@ export async function checkHumanActor(
// Check bot permissions if actor is not a User
if (actorType !== "User") {
const allowedBots = githubContext.inputs.allowedBots;
// Parse allowed bots list
const allowedBotsList = allowedBots
.split(",")

View File

@@ -24,7 +24,7 @@ describe("checkHumanActor", () => {
context.actor = "human-user";
await expect(
checkHumanActor(mockOctokit, context, ""),
checkHumanActor(mockOctokit, context),
).resolves.toBeUndefined();
});
@@ -32,8 +32,9 @@ describe("checkHumanActor", () => {
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
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.",
);
});
@@ -42,9 +43,10 @@ describe("checkHumanActor", () => {
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
context.actor = "test-bot";
context.inputs.allowedBots = "*";
await expect(
checkHumanActor(mockOctokit, context, "*"),
checkHumanActor(mockOctokit, context),
).resolves.toBeUndefined();
});
@@ -52,9 +54,10 @@ describe("checkHumanActor", () => {
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
context.actor = "dependabot";
context.inputs.allowedBots = "dependabot,renovate";
await expect(
checkHumanActor(mockOctokit, context, "dependabot,renovate"),
checkHumanActor(mockOctokit, context),
).resolves.toBeUndefined();
});
@@ -62,10 +65,9 @@ describe("checkHumanActor", () => {
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
context.actor = "other-bot";
context.inputs.allowedBots = "dependabot,renovate";
await expect(
checkHumanActor(mockOctokit, context, "dependabot,renovate"),
).rejects.toThrow(
await expect(checkHumanActor(mockOctokit, context)).rejects.toThrow(
"Workflow initiated by non-human actor: other-bot (type: Bot). Add bot to allowed_bots list or use '*' to allow all bots.",
);
});

View File

@@ -35,6 +35,7 @@ describe("prepareMcpConfig", () => {
useStickyComment: false,
additionalPermissions: new Map(),
useCommitSigning: false,
allowedBots: "",
},
};

View File

@@ -23,6 +23,7 @@ const defaultInputs = {
useStickyComment: false,
additionalPermissions: new Map<string, string>(),
useCommitSigning: false,
allowedBots: "",
};
const defaultRepository = {

View File

@@ -39,6 +39,7 @@ describe("checkContainsTrigger", () => {
useStickyComment: false,
additionalPermissions: new Map(),
useCommitSigning: false,
allowedBots: "",
},
});
expect(checkContainsTrigger(context)).toBe(true);
@@ -70,6 +71,7 @@ describe("checkContainsTrigger", () => {
useStickyComment: false,
additionalPermissions: new Map(),
useCommitSigning: false,
allowedBots: "",
},
});
expect(checkContainsTrigger(context)).toBe(false);
@@ -285,6 +287,7 @@ describe("checkContainsTrigger", () => {
useStickyComment: false,
additionalPermissions: new Map(),
useCommitSigning: false,
allowedBots: "",
},
});
expect(checkContainsTrigger(context)).toBe(true);
@@ -317,6 +320,7 @@ describe("checkContainsTrigger", () => {
useStickyComment: false,
additionalPermissions: new Map(),
useCommitSigning: false,
allowedBots: "",
},
});
expect(checkContainsTrigger(context)).toBe(true);
@@ -349,6 +353,7 @@ describe("checkContainsTrigger", () => {
useStickyComment: false,
additionalPermissions: new Map(),
useCommitSigning: false,
allowedBots: "",
},
});
expect(checkContainsTrigger(context)).toBe(false);