mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
Format code with prettier
This commit is contained in:
@@ -68,7 +68,7 @@ export async function prepareMcpConfig(
|
|||||||
const hasGitHubMcpTools = allowedToolsList.some((tool) =>
|
const hasGitHubMcpTools = allowedToolsList.some((tool) =>
|
||||||
tool.startsWith("mcp__github__"),
|
tool.startsWith("mcp__github__"),
|
||||||
);
|
);
|
||||||
|
|
||||||
const hasInlineCommentTools = allowedToolsList.some((tool) =>
|
const hasInlineCommentTools = allowedToolsList.some((tool) =>
|
||||||
tool.startsWith("mcp__github_inline_comment__"),
|
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
|
// 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 = {
|
baseMcpConfig.mcpServers.github_inline_comment = {
|
||||||
command: "bun",
|
command: "bun",
|
||||||
args: [
|
args: [
|
||||||
|
|||||||
@@ -46,11 +46,12 @@ export const agentMode: Mode = {
|
|||||||
await mkdir(`${process.env.RUNNER_TEMP}/claude-prompts`, {
|
await mkdir(`${process.env.RUNNER_TEMP}/claude-prompts`, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Write the prompt file - use the user's prompt directly
|
// 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}`;
|
`Repository: ${context.repository.owner}/${context.repository.repo}`;
|
||||||
|
|
||||||
await writeFile(
|
await writeFile(
|
||||||
`${process.env.RUNNER_TEMP}/claude-prompts/claude-prompt.txt`,
|
`${process.env.RUNNER_TEMP}/claude-prompts/claude-prompt.txt`,
|
||||||
promptContent,
|
promptContent,
|
||||||
@@ -59,12 +60,11 @@ export const agentMode: Mode = {
|
|||||||
// Parse allowed tools from user's claude_args
|
// Parse allowed tools from user's claude_args
|
||||||
const userClaudeArgs = process.env.CLAUDE_ARGS || "";
|
const userClaudeArgs = process.env.CLAUDE_ARGS || "";
|
||||||
const allowedTools = parseAllowedTools(userClaudeArgs);
|
const allowedTools = parseAllowedTools(userClaudeArgs);
|
||||||
|
|
||||||
// Detect current branch from GitHub environment
|
// Detect current branch from GitHub environment
|
||||||
const currentBranch = process.env.GITHUB_HEAD_REF ||
|
const currentBranch =
|
||||||
process.env.GITHUB_REF_NAME ||
|
process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || "main";
|
||||||
"main";
|
|
||||||
|
|
||||||
// Get MCP configuration with GitHub servers when requested
|
// Get MCP configuration with GitHub servers when requested
|
||||||
const additionalMcpConfig = process.env.MCP_CONFIG || "";
|
const additionalMcpConfig = process.env.MCP_CONFIG || "";
|
||||||
const mcpConfig = await prepareMcpConfig({
|
const mcpConfig = await prepareMcpConfig({
|
||||||
@@ -81,8 +81,9 @@ export const agentMode: Mode = {
|
|||||||
|
|
||||||
// Build final claude_args
|
// Build final claude_args
|
||||||
const escapedMcpConfig = mcpConfig.replace(/'/g, "'\\''");
|
const escapedMcpConfig = mcpConfig.replace(/'/g, "'\\''");
|
||||||
const claudeArgs = `--mcp-config '${escapedMcpConfig}' ${userClaudeArgs}`.trim();
|
const claudeArgs =
|
||||||
|
`--mcp-config '${escapedMcpConfig}' ${userClaudeArgs}`.trim();
|
||||||
|
|
||||||
core.setOutput("claude_args", claudeArgs);
|
core.setOutput("claude_args", claudeArgs);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -2,21 +2,21 @@ export function parseAllowedTools(claudeArgs: string): string[] {
|
|||||||
// Match --allowedTools followed by the value
|
// Match --allowedTools followed by the value
|
||||||
// Handle both quoted and unquoted values
|
// Handle both quoted and unquoted values
|
||||||
const patterns = [
|
const patterns = [
|
||||||
/--allowedTools\s+"([^"]+)"/, // Double quoted
|
/--allowedTools\s+"([^"]+)"/, // Double quoted
|
||||||
/--allowedTools\s+'([^']+)'/, // Single quoted
|
/--allowedTools\s+'([^']+)'/, // Single quoted
|
||||||
/--allowedTools\s+([^\s]+)/, // Unquoted
|
/--allowedTools\s+([^\s]+)/, // Unquoted
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const pattern of patterns) {
|
for (const pattern of patterns) {
|
||||||
const match = claudeArgs.match(pattern);
|
const match = claudeArgs.match(pattern);
|
||||||
if (match && match[1]) {
|
if (match && match[1]) {
|
||||||
// Don't return if the value starts with -- (another flag)
|
// Don't return if the value starts with -- (another flag)
|
||||||
if (match[1].startsWith('--')) {
|
if (match[1].startsWith("--")) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return match[1].split(',').map(t => t.trim());
|
return match[1].split(",").map((t) => t.trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ describe("parseAllowedTools", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("handles multiple flags with allowedTools in middle", () => {
|
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__*"]);
|
expect(parseAllowedTools(args)).toEqual(["mcp__github__*"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -60,10 +61,11 @@ describe("parseAllowedTools", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("handles tools with special characters", () => {
|
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([
|
expect(parseAllowedTools(args)).toEqual([
|
||||||
"mcp__github__create_issue",
|
"mcp__github__create_issue",
|
||||||
"mcp__github_comment__update",
|
"mcp__github_comment__update",
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user