Format code with prettier

This commit is contained in:
km-anthropic
2025-08-13 09:54:57 -07:00
parent e3b5697276
commit d24561da51
4 changed files with 31 additions and 24 deletions

View File

@@ -68,7 +68,7 @@ export async function prepareMcpConfig(
const hasGitHubMcpTools = allowedToolsList.some((tool) =>
tool.startsWith("mcp__github__"),
);
const hasInlineCommentTools = allowedToolsList.some((tool) =>
tool.startsWith("mcp__github_inline_comment__"),
);
@@ -115,9 +115,13 @@ export async function prepareMcpConfig(
},
};
}
// Include inline comment server for PRs when requested via allowed tools
if (isEntityContext(context) && context.isPR && (hasGitHubMcpTools || hasInlineCommentTools)) {
if (
isEntityContext(context) &&
context.isPR &&
(hasGitHubMcpTools || hasInlineCommentTools)
) {
baseMcpConfig.mcpServers.github_inline_comment = {
command: "bun",
args: [

View File

@@ -46,11 +46,12 @@ export const agentMode: Mode = {
await mkdir(`${process.env.RUNNER_TEMP}/claude-prompts`, {
recursive: true,
});
// Write the prompt file - use the user's prompt directly
const promptContent = context.inputs.prompt ||
const promptContent =
context.inputs.prompt ||
`Repository: ${context.repository.owner}/${context.repository.repo}`;
await writeFile(
`${process.env.RUNNER_TEMP}/claude-prompts/claude-prompt.txt`,
promptContent,
@@ -59,12 +60,11 @@ export const agentMode: Mode = {
// Parse allowed tools from user's claude_args
const userClaudeArgs = process.env.CLAUDE_ARGS || "";
const allowedTools = parseAllowedTools(userClaudeArgs);
// Detect current branch from GitHub environment
const currentBranch = process.env.GITHUB_HEAD_REF ||
process.env.GITHUB_REF_NAME ||
"main";
const currentBranch =
process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || "main";
// Get MCP configuration with GitHub servers when requested
const additionalMcpConfig = process.env.MCP_CONFIG || "";
const mcpConfig = await prepareMcpConfig({
@@ -81,8 +81,9 @@ export const agentMode: Mode = {
// Build final claude_args
const escapedMcpConfig = mcpConfig.replace(/'/g, "'\\''");
const claudeArgs = `--mcp-config '${escapedMcpConfig}' ${userClaudeArgs}`.trim();
const claudeArgs =
`--mcp-config '${escapedMcpConfig}' ${userClaudeArgs}`.trim();
core.setOutput("claude_args", claudeArgs);
return {

View File

@@ -2,21 +2,21 @@ export function parseAllowedTools(claudeArgs: string): string[] {
// Match --allowedTools followed by the value
// Handle both quoted and unquoted values
const patterns = [
/--allowedTools\s+"([^"]+)"/, // Double quoted
/--allowedTools\s+'([^']+)'/, // Single quoted
/--allowedTools\s+([^\s]+)/, // Unquoted
/--allowedTools\s+"([^"]+)"/, // Double quoted
/--allowedTools\s+'([^']+)'/, // Single quoted
/--allowedTools\s+([^\s]+)/, // Unquoted
];
for (const pattern of patterns) {
const match = claudeArgs.match(pattern);
if (match && match[1]) {
// Don't return if the value starts with -- (another flag)
if (match[1].startsWith('--')) {
if (match[1].startsWith("--")) {
return [];
}
return match[1].split(',').map(t => t.trim());
return match[1].split(",").map((t) => t.trim());
}
}
return [];
}
}

View File

@@ -47,7 +47,8 @@ describe("parseAllowedTools", () => {
});
test("handles multiple flags with allowedTools in middle", () => {
const args = '--flag1 value1 --allowedTools "mcp__github__*" --flag2 value2';
const args =
'--flag1 value1 --allowedTools "mcp__github__*" --flag2 value2';
expect(parseAllowedTools(args)).toEqual(["mcp__github__*"]);
});
@@ -60,10 +61,11 @@ describe("parseAllowedTools", () => {
});
test("handles tools with special characters", () => {
const args = '--allowedTools "mcp__github__create_issue,mcp__github_comment__update"';
const args =
'--allowedTools "mcp__github__create_issue,mcp__github_comment__update"';
expect(parseAllowedTools(args)).toEqual([
"mcp__github__create_issue",
"mcp__github_comment__update",
]);
});
});
});