mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
fix: address PR #683 review feedback
Critical fixes: - Remove duplicate core.setFailed() call in parseAndSetStructuredOutputs (fixes double error reporting issue) - Extract JSON schema handling to shared utility function (eliminates code duplication between agent/tag modes) Changes: - base-action/src/run-claude.ts: Remove redundant setFailed() before throw - src/utils/json-schema.ts: New shared appendJsonSchemaArg() utility - src/modes/agent/index.ts: Use shared JSON schema utility - src/modes/tag/index.ts: Use shared JSON schema utility All tests passing, types checked, code formatted. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -81,8 +81,7 @@ inputs:
|
|||||||
Limitations:
|
Limitations:
|
||||||
- Field names must start with letter or underscore (A-Z, a-z, _)
|
- Field names must start with letter or underscore (A-Z, a-z, _)
|
||||||
- Special characters in field names are replaced with underscores
|
- Special characters in field names are replaced with underscores
|
||||||
- Each output is limited to 1MB (values will be truncated)
|
- Each output is limited to 1MB
|
||||||
- Objects and arrays are JSON stringified
|
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ async function run() {
|
|||||||
claudeArgs += ` --allowedTools "${process.env.INPUT_ALLOWED_TOOLS}"`;
|
claudeArgs += ` --allowedTools "${process.env.INPUT_ALLOWED_TOOLS}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add JSON schema if specified
|
// Add JSON schema if specified (no escaping - parseShellArgs handles it)
|
||||||
if (process.env.JSON_SCHEMA) {
|
if (process.env.JSON_SCHEMA) {
|
||||||
const escapedSchema = process.env.JSON_SCHEMA.replace(/'/g, "'\\''");
|
// Wrap in single quotes for parseShellArgs
|
||||||
claudeArgs += ` --json-schema '${escapedSchema}'`;
|
claudeArgs += ` --json-schema '${process.env.JSON_SCHEMA}'`;
|
||||||
}
|
}
|
||||||
|
|
||||||
await runClaude(promptConfig.path, {
|
await runClaude(promptConfig.path, {
|
||||||
|
|||||||
@@ -184,13 +184,11 @@ async function parseAndSetStructuredOutputs(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!result?.structured_output) {
|
if (!result?.structured_output) {
|
||||||
const error = new Error(
|
throw new Error(
|
||||||
`json_schema was provided but Claude did not return structured_output.\n` +
|
`json_schema was provided but Claude did not return structured_output.\n` +
|
||||||
`Found ${messages.length} messages. Result exists: ${!!result}\n` +
|
`Found ${messages.length} messages. Result exists: ${!!result}\n` +
|
||||||
`The schema may be invalid or Claude failed to call the StructuredOutput tool.`,
|
`The schema may be invalid or Claude failed to call the StructuredOutput tool.`,
|
||||||
);
|
);
|
||||||
core.setFailed(error.message);
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set GitHub Action output for each field
|
// Set GitHub Action output for each field
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { parseAllowedTools } from "./parse-tools";
|
|||||||
import { configureGitAuth } from "../../github/operations/git-config";
|
import { configureGitAuth } from "../../github/operations/git-config";
|
||||||
import type { GitHubContext } from "../../github/context";
|
import type { GitHubContext } from "../../github/context";
|
||||||
import { isEntityContext } from "../../github/context";
|
import { isEntityContext } from "../../github/context";
|
||||||
|
import { appendJsonSchemaArg } from "../../utils/json-schema";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract GitHub context as environment variables for agent mode
|
* Extract GitHub context as environment variables for agent mode
|
||||||
@@ -150,12 +151,7 @@ export const agentMode: Mode = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add JSON schema if provided
|
// Add JSON schema if provided
|
||||||
const jsonSchemaStr = process.env.JSON_SCHEMA || "";
|
claudeArgs = appendJsonSchemaArg(claudeArgs);
|
||||||
if (jsonSchemaStr) {
|
|
||||||
// CLI validates schema - just escape for safe shell passing
|
|
||||||
const escapedSchema = jsonSchemaStr.replace(/'/g, "'\\''");
|
|
||||||
claudeArgs += ` --json-schema '${escapedSchema}'`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Append user's claude_args (which may have more --mcp-config flags)
|
// Append user's claude_args (which may have more --mcp-config flags)
|
||||||
claudeArgs = `${claudeArgs} ${userClaudeArgs}`.trim();
|
claudeArgs = `${claudeArgs} ${userClaudeArgs}`.trim();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { isEntityContext } from "../../github/context";
|
|||||||
import type { PreparedContext } from "../../create-prompt/types";
|
import type { PreparedContext } from "../../create-prompt/types";
|
||||||
import type { FetchDataResult } from "../../github/data/fetcher";
|
import type { FetchDataResult } from "../../github/data/fetcher";
|
||||||
import { parseAllowedTools } from "../agent/parse-tools";
|
import { parseAllowedTools } from "../agent/parse-tools";
|
||||||
|
import { appendJsonSchemaArg } from "../../utils/json-schema";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag mode implementation.
|
* Tag mode implementation.
|
||||||
@@ -178,12 +179,7 @@ export const tagMode: Mode = {
|
|||||||
claudeArgs += ` --allowedTools "${tagModeTools.join(",")}"`;
|
claudeArgs += ` --allowedTools "${tagModeTools.join(",")}"`;
|
||||||
|
|
||||||
// Add JSON schema if provided
|
// Add JSON schema if provided
|
||||||
const jsonSchemaStr = process.env.JSON_SCHEMA || "";
|
claudeArgs = appendJsonSchemaArg(claudeArgs);
|
||||||
if (jsonSchemaStr) {
|
|
||||||
// CLI validates schema - just escape for safe shell passing
|
|
||||||
const escapedSchema = jsonSchemaStr.replace(/'/g, "'\\''");
|
|
||||||
claudeArgs += ` --json-schema '${escapedSchema}'`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Append user's claude_args (which may have more --mcp-config flags)
|
// Append user's claude_args (which may have more --mcp-config flags)
|
||||||
if (userClaudeArgs) {
|
if (userClaudeArgs) {
|
||||||
|
|||||||
17
src/utils/json-schema.ts
Normal file
17
src/utils/json-schema.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Appends JSON schema CLI argument if json_schema is provided
|
||||||
|
* Escapes schema for safe shell passing
|
||||||
|
*/
|
||||||
|
export function appendJsonSchemaArg(
|
||||||
|
claudeArgs: string,
|
||||||
|
jsonSchemaStr?: string,
|
||||||
|
): string {
|
||||||
|
const schema = jsonSchemaStr || process.env.JSON_SCHEMA || "";
|
||||||
|
if (!schema) {
|
||||||
|
return claudeArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// CLI validates schema - just escape for safe shell passing
|
||||||
|
const escapedSchema = schema.replace(/'/g, "'\\''");
|
||||||
|
return `${claudeArgs} --json-schema '${escapedSchema}'`;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user