mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 15:04:13 +08:00
Compare commits
3 Commits
claude/sla
...
ashwin/deb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5940655715 | ||
|
|
0c4374199a | ||
|
|
c67fb66a79 |
4
.github/workflows/sync-base-action.yml
vendored
4
.github/workflows/sync-base-action.yml
vendored
@@ -94,5 +94,5 @@ jobs:
|
||||
echo "✅ Successfully synced \`base-action\` directory to [anthropics/claude-code-base-action](https://github.com/anthropics/claude-code-base-action)" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Source commit**: [\`${GITHUB_SHA:0:7}\`](https://github.com/anthropics/claude-code-action/commit/${GITHUB_SHA})" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Triggered by**: $GITHUB_EVENT_NAME" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Actor**: @$GITHUB_ACTOR" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Triggered by**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Actor**: @${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
16
action.yml
16
action.yml
@@ -140,12 +140,10 @@ runs:
|
||||
- name: Setup Custom Bun Path
|
||||
if: inputs.path_to_bun_executable != ''
|
||||
shell: bash
|
||||
env:
|
||||
PATH_TO_BUN_EXECUTABLE: ${{ inputs.path_to_bun_executable }}
|
||||
run: |
|
||||
echo "Using custom Bun executable: $PATH_TO_BUN_EXECUTABLE"
|
||||
echo "Using custom Bun executable: ${{ inputs.path_to_bun_executable }}"
|
||||
# Add the directory containing the custom executable to PATH
|
||||
BUN_DIR=$(dirname "$PATH_TO_BUN_EXECUTABLE")
|
||||
BUN_DIR=$(dirname "${{ inputs.path_to_bun_executable }}")
|
||||
echo "$BUN_DIR" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Install Dependencies
|
||||
@@ -184,8 +182,6 @@ runs:
|
||||
- name: Install Base Action Dependencies
|
||||
if: steps.prepare.outputs.contains_trigger == 'true'
|
||||
shell: bash
|
||||
env:
|
||||
PATH_TO_CLAUDE_CODE_EXECUTABLE: ${{ inputs.path_to_claude_code_executable }}
|
||||
run: |
|
||||
echo "Installing base-action dependencies..."
|
||||
cd ${GITHUB_ACTION_PATH}/base-action
|
||||
@@ -194,8 +190,8 @@ runs:
|
||||
cd -
|
||||
|
||||
# Install Claude Code if no custom executable is provided
|
||||
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
||||
CLAUDE_CODE_VERSION="2.0.62"
|
||||
if [ -z "${{ inputs.path_to_claude_code_executable }}" ]; then
|
||||
CLAUDE_CODE_VERSION="2.0.60"
|
||||
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
||||
for attempt in 1 2 3; do
|
||||
echo "Installation attempt $attempt..."
|
||||
@@ -214,9 +210,9 @@ runs:
|
||||
echo "Claude Code installed successfully"
|
||||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||
else
|
||||
echo "Using custom Claude Code executable: $PATH_TO_CLAUDE_CODE_EXECUTABLE"
|
||||
echo "Using custom Claude Code executable: ${{ inputs.path_to_claude_code_executable }}"
|
||||
# Add the directory containing the custom executable to PATH
|
||||
CLAUDE_DIR=$(dirname "$PATH_TO_CLAUDE_CODE_EXECUTABLE")
|
||||
CLAUDE_DIR=$(dirname "${{ inputs.path_to_claude_code_executable }}")
|
||||
echo "$CLAUDE_DIR" >> "$GITHUB_PATH"
|
||||
fi
|
||||
|
||||
|
||||
@@ -101,12 +101,10 @@ runs:
|
||||
- name: Setup Custom Bun Path
|
||||
if: inputs.path_to_bun_executable != ''
|
||||
shell: bash
|
||||
env:
|
||||
PATH_TO_BUN_EXECUTABLE: ${{ inputs.path_to_bun_executable }}
|
||||
run: |
|
||||
echo "Using custom Bun executable: $PATH_TO_BUN_EXECUTABLE"
|
||||
echo "Using custom Bun executable: ${{ inputs.path_to_bun_executable }}"
|
||||
# Add the directory containing the custom executable to PATH
|
||||
BUN_DIR=$(dirname "$PATH_TO_BUN_EXECUTABLE")
|
||||
BUN_DIR=$(dirname "${{ inputs.path_to_bun_executable }}")
|
||||
echo "$BUN_DIR" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Install Dependencies
|
||||
@@ -117,11 +115,9 @@ runs:
|
||||
|
||||
- name: Install Claude Code
|
||||
shell: bash
|
||||
env:
|
||||
PATH_TO_CLAUDE_CODE_EXECUTABLE: ${{ inputs.path_to_claude_code_executable }}
|
||||
run: |
|
||||
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
||||
CLAUDE_CODE_VERSION="2.0.62"
|
||||
if [ -z "${{ inputs.path_to_claude_code_executable }}" ]; then
|
||||
CLAUDE_CODE_VERSION="2.0.60"
|
||||
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
||||
for attempt in 1 2 3; do
|
||||
echo "Installation attempt $attempt..."
|
||||
@@ -139,9 +135,9 @@ runs:
|
||||
done
|
||||
echo "Claude Code installed successfully"
|
||||
else
|
||||
echo "Using custom Claude Code executable: $PATH_TO_CLAUDE_CODE_EXECUTABLE"
|
||||
echo "Using custom Claude Code executable: ${{ inputs.path_to_claude_code_executable }}"
|
||||
# Add the directory containing the custom executable to PATH
|
||||
CLAUDE_DIR=$(dirname "$PATH_TO_CLAUDE_CODE_EXECUTABLE")
|
||||
CLAUDE_DIR=$(dirname "${{ inputs.path_to_claude_code_executable }}")
|
||||
echo "$CLAUDE_DIR" >> "$GITHUB_PATH"
|
||||
fi
|
||||
|
||||
|
||||
@@ -75,15 +75,28 @@ export async function runClaudeWithSdk(
|
||||
}
|
||||
|
||||
console.log(`Running Claude with prompt from file: ${promptPath}`);
|
||||
// Log SDK options without env (which could contain sensitive data)
|
||||
const { env, ...optionsToLog } = sdkOptions;
|
||||
console.log("SDK options:", JSON.stringify(optionsToLog, null, 2));
|
||||
console.log(
|
||||
"[DEBUG] Prompt content (first 2000 chars):",
|
||||
prompt.substring(0, 2000),
|
||||
);
|
||||
console.log("[DEBUG] Prompt length:", prompt.length);
|
||||
console.log(
|
||||
"[DEBUG] sdkOptions passed to query():",
|
||||
JSON.stringify(sdkOptions, null, 2),
|
||||
);
|
||||
|
||||
const messages: SDKMessage[] = [];
|
||||
let resultMessage: SDKResultMessage | undefined;
|
||||
|
||||
try {
|
||||
console.log("[DEBUG] About to call query()...");
|
||||
for await (const message of query({ prompt, options: sdkOptions })) {
|
||||
console.log(
|
||||
"[DEBUG] Received message type:",
|
||||
message.type,
|
||||
"subtype:",
|
||||
(message as any).subtype,
|
||||
);
|
||||
messages.push(message);
|
||||
|
||||
const sanitized = sanitizeSdkOutput(message, showFullOutput);
|
||||
@@ -93,8 +106,16 @@ export async function runClaudeWithSdk(
|
||||
|
||||
if (message.type === "result") {
|
||||
resultMessage = message as SDKResultMessage;
|
||||
console.log(
|
||||
"[DEBUG] Got result message:",
|
||||
JSON.stringify(resultMessage, null, 2),
|
||||
);
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
"[DEBUG] Finished iterating query(), total messages:",
|
||||
messages.length,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("SDK execution error:", error);
|
||||
core.setOutput("conclusion", "failure");
|
||||
|
||||
@@ -174,7 +174,15 @@ export async function runClaude(promptPath: string, options: ClaudeOptions) {
|
||||
);
|
||||
|
||||
if (useAgentSdk) {
|
||||
console.log(
|
||||
"[DEBUG] Raw options passed to SDK path:",
|
||||
JSON.stringify(options, null, 2),
|
||||
);
|
||||
const parsedOptions = parseSdkOptions(options);
|
||||
console.log(
|
||||
"[DEBUG] Parsed SDK options:",
|
||||
JSON.stringify(parsedOptions, null, 2),
|
||||
);
|
||||
return runClaudeWithSdk(promptPath, parsedOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,20 +15,6 @@ import { GITHUB_SERVER_URL } from "../github/api/config";
|
||||
import { checkAndCommitOrDeleteBranch } from "../github/operations/branch-cleanup";
|
||||
import { updateClaudeComment } from "../github/operations/comments/update-claude-comment";
|
||||
|
||||
/**
|
||||
* Encodes a branch name for use in a URL, preserving forward slashes.
|
||||
* GitHub expects literal slashes in branch names (e.g., /tree/feature/branch)
|
||||
* but other special characters like parentheses need to be encoded.
|
||||
* Note: encodeURIComponent doesn't encode ( ) ! ' * ~ per RFC 3986,
|
||||
* but parentheses break markdown links so we encode them manually.
|
||||
*/
|
||||
function encodeBranchName(branchName: string): string {
|
||||
return encodeURIComponent(branchName)
|
||||
.replace(/%2F/gi, "/")
|
||||
.replace(/\(/g, "%28")
|
||||
.replace(/\)/g, "%29");
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const commentId = parseInt(process.env.CLAUDE_COMMENT_ID!);
|
||||
@@ -154,7 +140,7 @@ async function run() {
|
||||
const prBody = encodeURIComponent(
|
||||
`This PR addresses ${entityType.toLowerCase()} #${context.entityNumber}\n\nGenerated with [Claude Code](https://claude.ai/code)`,
|
||||
);
|
||||
const prUrl = `${serverUrl}/${owner}/${repo}/compare/${encodeBranchName(baseBranch)}...${encodeBranchName(claudeBranch)}?quick_pull=1&title=${prTitle}&body=${prBody}`;
|
||||
const prUrl = `${serverUrl}/${owner}/${repo}/compare/${baseBranch}...${claudeBranch}?quick_pull=1&title=${prTitle}&body=${prBody}`;
|
||||
prLink = `\n[Create a PR](${prUrl})`;
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -2,20 +2,6 @@ import type { Octokits } from "../api/client";
|
||||
import { GITHUB_SERVER_URL } from "../api/config";
|
||||
import { $ } from "bun";
|
||||
|
||||
/**
|
||||
* Encodes a branch name for use in a URL, preserving forward slashes.
|
||||
* GitHub expects literal slashes in branch names (e.g., /tree/feature/branch)
|
||||
* but other special characters like parentheses need to be encoded.
|
||||
* Note: encodeURIComponent doesn't encode ( ) ! ' * ~ per RFC 3986,
|
||||
* but parentheses break markdown links so we encode them manually.
|
||||
*/
|
||||
function encodeBranchName(branchName: string): string {
|
||||
return encodeURIComponent(branchName)
|
||||
.replace(/%2F/gi, "/")
|
||||
.replace(/\(/g, "%28")
|
||||
.replace(/\)/g, "%29");
|
||||
}
|
||||
|
||||
export async function checkAndCommitOrDeleteBranch(
|
||||
octokit: Octokits,
|
||||
owner: string,
|
||||
@@ -94,7 +80,7 @@ export async function checkAndCommitOrDeleteBranch(
|
||||
);
|
||||
|
||||
// Set branch link since we now have commits
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${encodeBranchName(claudeBranch)}`;
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`;
|
||||
branchLink = `\n[View branch](${branchUrl})`;
|
||||
} else {
|
||||
console.log(
|
||||
@@ -105,7 +91,7 @@ export async function checkAndCommitOrDeleteBranch(
|
||||
} catch (gitError) {
|
||||
console.error("Error checking/committing changes:", gitError);
|
||||
// If we can't check git status, assume the branch might have changes
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${encodeBranchName(claudeBranch)}`;
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`;
|
||||
branchLink = `\n[View branch](${branchUrl})`;
|
||||
}
|
||||
} else {
|
||||
@@ -116,13 +102,13 @@ export async function checkAndCommitOrDeleteBranch(
|
||||
}
|
||||
} else {
|
||||
// Only add branch link if there are commits
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${encodeBranchName(claudeBranch)}`;
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`;
|
||||
branchLink = `\n[View branch](${branchUrl})`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error comparing commits on Claude branch:", error);
|
||||
// If we can't compare but the branch exists remotely, include the branch link
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${encodeBranchName(claudeBranch)}`;
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`;
|
||||
branchLink = `\n[View branch](${branchUrl})`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
import { GITHUB_SERVER_URL } from "../api/config";
|
||||
|
||||
/**
|
||||
* Encodes a branch name for use in a URL, preserving forward slashes.
|
||||
* GitHub expects literal slashes in branch names (e.g., /tree/feature/branch)
|
||||
* but other special characters like parentheses need to be encoded.
|
||||
* Note: encodeURIComponent doesn't encode ( ) ! ' * ~ per RFC 3986,
|
||||
* but parentheses break markdown links so we encode them manually.
|
||||
*/
|
||||
function encodeBranchName(branchName: string): string {
|
||||
return encodeURIComponent(branchName)
|
||||
.replace(/%2F/gi, "/")
|
||||
.replace(/\(/g, "%28")
|
||||
.replace(/\)/g, "%29");
|
||||
}
|
||||
|
||||
export type ExecutionDetails = {
|
||||
total_cost_usd?: number;
|
||||
duration_ms?: number;
|
||||
@@ -174,7 +160,7 @@ export function updateCommentBody(input: CommentUpdateInput): string {
|
||||
// Extract owner/repo from jobUrl
|
||||
const repoMatch = jobUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\//);
|
||||
if (repoMatch) {
|
||||
branchUrl = `${GITHUB_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/tree/${encodeBranchName(finalBranchName)}`;
|
||||
branchUrl = `${GITHUB_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/tree/${finalBranchName}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,9 +172,8 @@ export function updateCommentBody(input: CommentUpdateInput): string {
|
||||
}
|
||||
|
||||
// Add PR link (either from content or provided)
|
||||
// Use greedy match with end anchor to capture full URL even if it contains parentheses
|
||||
const prUrl =
|
||||
prLinkFromContent || (prLink ? prLink.match(/\((.+)\)$/)?.[1] : "");
|
||||
prLinkFromContent || (prLink ? prLink.match(/\(([^)]+)\)/)?.[1] : "");
|
||||
if (prUrl) {
|
||||
links += ` • [Create PR ➔](${prUrl})`;
|
||||
}
|
||||
|
||||
@@ -12,26 +12,12 @@ export function createJobRunLink(
|
||||
return `[View job run](${jobRunUrl})`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a branch name for use in a URL, preserving forward slashes.
|
||||
* GitHub expects literal slashes in branch names (e.g., /tree/feature/branch)
|
||||
* but other special characters like parentheses need to be encoded.
|
||||
* Note: encodeURIComponent doesn't encode ( ) ! ' * ~ per RFC 3986,
|
||||
* but parentheses break markdown links so we encode them manually.
|
||||
*/
|
||||
function encodeBranchName(branchName: string): string {
|
||||
return encodeURIComponent(branchName)
|
||||
.replace(/%2F/gi, "/")
|
||||
.replace(/\(/g, "%28")
|
||||
.replace(/\)/g, "%29");
|
||||
}
|
||||
|
||||
export function createBranchLink(
|
||||
owner: string,
|
||||
repo: string,
|
||||
branchName: string,
|
||||
): string {
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${encodeBranchName(branchName)}`;
|
||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${branchName}`;
|
||||
return `\n[View branch](${branchUrl})`;
|
||||
}
|
||||
|
||||
|
||||
@@ -139,21 +139,6 @@ describe("updateCommentBody", () => {
|
||||
);
|
||||
expect(result).not.toContain("View branch");
|
||||
});
|
||||
|
||||
it("encodes special characters in branch names while preserving slashes", () => {
|
||||
const input = {
|
||||
...baseInput,
|
||||
branchName: "feature/fix(issue)-test",
|
||||
};
|
||||
|
||||
const result = updateCommentBody(input);
|
||||
// Branch name display should show the original name
|
||||
expect(result).toContain("`feature/fix(issue)-test`");
|
||||
// URL should have encoded parentheses but preserved slashes
|
||||
expect(result).toContain(
|
||||
"https://github.com/owner/repo/tree/feature/fix%28issue%29-test",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("PR link", () => {
|
||||
|
||||
Reference in New Issue
Block a user