mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 23:14:13 +08:00
Compare commits
7 Commits
demo/flawe
...
ashwin/tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b1f984703 | ||
|
|
59a49d170c | ||
|
|
cc47c8baef | ||
|
|
222c780563 | ||
|
|
574f279fb0 | ||
|
|
3fa4ea2174 | ||
|
|
532c5e257d |
10
action.yml
10
action.yml
@@ -73,6 +73,14 @@ inputs:
|
|||||||
description: "Enable commit signing using GitHub's commit signature verification. When false, Claude uses standard git commands"
|
description: "Enable commit signing using GitHub's commit signature verification. When false, Claude uses standard git commands"
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
|
bot_id:
|
||||||
|
description: "GitHub user ID to use for git operations (defaults to Claude's bot ID)"
|
||||||
|
required: false
|
||||||
|
default: "41898282" # Claude's bot ID - see src/github/constants.ts
|
||||||
|
bot_name:
|
||||||
|
description: "GitHub username to use for git operations (defaults to Claude's bot name)"
|
||||||
|
required: false
|
||||||
|
default: "claude[bot]"
|
||||||
track_progress:
|
track_progress:
|
||||||
description: "Force tag mode with tracking comments for pull_request and issue events. Only applicable to pull_request (opened, synchronize, ready_for_review, reopened) and issue (opened, edited, labeled, assigned) events."
|
description: "Force tag mode with tracking comments for pull_request and issue events. Only applicable to pull_request (opened, synchronize, ready_for_review, reopened) and issue (opened, edited, labeled, assigned) events."
|
||||||
required: false
|
required: false
|
||||||
@@ -144,6 +152,8 @@ runs:
|
|||||||
USE_STICKY_COMMENT: ${{ inputs.use_sticky_comment }}
|
USE_STICKY_COMMENT: ${{ inputs.use_sticky_comment }}
|
||||||
DEFAULT_WORKFLOW_TOKEN: ${{ github.token }}
|
DEFAULT_WORKFLOW_TOKEN: ${{ github.token }}
|
||||||
USE_COMMIT_SIGNING: ${{ inputs.use_commit_signing }}
|
USE_COMMIT_SIGNING: ${{ inputs.use_commit_signing }}
|
||||||
|
BOT_ID: ${{ inputs.bot_id }}
|
||||||
|
BOT_NAME: ${{ inputs.bot_name }}
|
||||||
TRACK_PROGRESS: ${{ inputs.track_progress }}
|
TRACK_PROGRESS: ${{ inputs.track_progress }}
|
||||||
ADDITIONAL_PERMISSIONS: ${{ inputs.additional_permissions }}
|
ADDITIONAL_PERMISSIONS: ${{ inputs.additional_permissions }}
|
||||||
CLAUDE_ARGS: ${{ inputs.claude_args }}
|
CLAUDE_ARGS: ${{ inputs.claude_args }}
|
||||||
|
|||||||
27
docs/faq.md
27
docs/faq.md
@@ -28,6 +28,33 @@ permissions:
|
|||||||
|
|
||||||
The OIDC token is required in order for the Claude GitHub app to function. If you wish to not use the GitHub app, you can instead provide a `github_token` input to the action for Claude to operate with. See the [Claude Code permissions documentation][perms] for more.
|
The OIDC token is required in order for the Claude GitHub app to function. If you wish to not use the GitHub app, you can instead provide a `github_token` input to the action for Claude to operate with. See the [Claude Code permissions documentation][perms] for more.
|
||||||
|
|
||||||
|
### Why am I getting '403 Resource not accessible by integration' errors?
|
||||||
|
|
||||||
|
This error occurs when the action tries to fetch the authenticated user information using a GitHub App installation token. GitHub App tokens have limited access and cannot access the `/user` endpoint, which causes this 403 error.
|
||||||
|
|
||||||
|
**Solution**: The action now includes `bot_id` and `bot_name` inputs that default to Claude's bot credentials. This avoids the need to fetch user information from the API.
|
||||||
|
|
||||||
|
For the default claude[bot]:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: anthropics/claude-code-action@v1
|
||||||
|
with:
|
||||||
|
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||||
|
# bot_id and bot_name have sensible defaults, no need to specify
|
||||||
|
```
|
||||||
|
|
||||||
|
For custom bots, specify both:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: anthropics/claude-code-action@v1
|
||||||
|
with:
|
||||||
|
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||||
|
bot_id: "12345678" # Your bot's GitHub user ID
|
||||||
|
bot_name: "my-bot" # Your bot's username
|
||||||
|
```
|
||||||
|
|
||||||
|
This issue typically only affects agent/automation mode workflows. Interactive workflows (with @claude mentions) don't encounter this issue as they use the comment author's information.
|
||||||
|
|
||||||
## Claude's Capabilities and Limitations
|
## Claude's Capabilities and Limitations
|
||||||
|
|
||||||
### Why won't Claude update workflow files when I ask it to?
|
### Why won't Claude update workflow files when I ask it to?
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ jobs:
|
|||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
| Input | Description | Required | Default |
|
| Input | Description | Required | Default |
|
||||||
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------- | -------- | --------- |
|
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------- | -------- | ------------- |
|
||||||
| `anthropic_api_key` | Anthropic API key (required for direct API, not needed for Bedrock/Vertex) | No\* | - |
|
| `anthropic_api_key` | Anthropic API key (required for direct API, not needed for Bedrock/Vertex) | No\* | - |
|
||||||
| `claude_code_oauth_token` | Claude Code OAuth token (alternative to anthropic_api_key) | No\* | - |
|
| `claude_code_oauth_token` | Claude Code OAuth token (alternative to anthropic_api_key) | No\* | - |
|
||||||
| `prompt` | Instructions for Claude. Can be a direct prompt or custom template for automation workflows | No | - |
|
| `prompt` | Instructions for Claude. Can be a direct prompt or custom template for automation workflows | No | - |
|
||||||
@@ -68,6 +68,8 @@ jobs:
|
|||||||
| `additional_permissions` | Additional permissions to enable. Currently supports 'actions: read' for viewing workflow results | No | "" |
|
| `additional_permissions` | Additional permissions to enable. Currently supports 'actions: read' for viewing workflow results | No | "" |
|
||||||
| `experimental_allowed_domains` | Restrict network access to these domains only (newline-separated). | No | "" |
|
| `experimental_allowed_domains` | Restrict network access to these domains only (newline-separated). | No | "" |
|
||||||
| `use_commit_signing` | Enable commit signing using GitHub's commit signature verification. When false, Claude uses standard git commands | No | `false` |
|
| `use_commit_signing` | Enable commit signing using GitHub's commit signature verification. When false, Claude uses standard git commands | No | `false` |
|
||||||
|
| `bot_id` | GitHub user ID to use for git operations (defaults to Claude's bot ID) | No | `41898282` |
|
||||||
|
| `bot_name` | GitHub username to use for git operations (defaults to Claude's bot name) | No | `claude[bot]` |
|
||||||
| `allowed_bots` | Comma-separated list of allowed bot usernames, or '\*' to allow all bots. Empty string (default) allows no bots | No | "" |
|
| `allowed_bots` | Comma-separated list of allowed bot usernames, or '\*' to allow all bots. Empty string (default) allows no bots | No | "" |
|
||||||
|
|
||||||
### Deprecated Inputs
|
### Deprecated Inputs
|
||||||
|
|||||||
13
src/github/constants.ts
Normal file
13
src/github/constants.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* GitHub-related constants used throughout the application
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Claude App bot user ID
|
||||||
|
*/
|
||||||
|
export const CLAUDE_APP_BOT_ID = 41898282;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Claude bot username
|
||||||
|
*/
|
||||||
|
export const CLAUDE_BOT_LOGIN = "claude[bot]";
|
||||||
@@ -8,6 +8,7 @@ import type {
|
|||||||
PullRequestReviewCommentEvent,
|
PullRequestReviewCommentEvent,
|
||||||
WorkflowRunEvent,
|
WorkflowRunEvent,
|
||||||
} from "@octokit/webhooks-types";
|
} from "@octokit/webhooks-types";
|
||||||
|
import { CLAUDE_APP_BOT_ID, CLAUDE_BOT_LOGIN } from "./constants";
|
||||||
// Custom types for GitHub Actions events that aren't webhooks
|
// Custom types for GitHub Actions events that aren't webhooks
|
||||||
export type WorkflowDispatchEvent = {
|
export type WorkflowDispatchEvent = {
|
||||||
action?: never;
|
action?: never;
|
||||||
@@ -74,6 +75,8 @@ type BaseContext = {
|
|||||||
branchPrefix: string;
|
branchPrefix: string;
|
||||||
useStickyComment: boolean;
|
useStickyComment: boolean;
|
||||||
useCommitSigning: boolean;
|
useCommitSigning: boolean;
|
||||||
|
botId: string;
|
||||||
|
botName: string;
|
||||||
allowedBots: string;
|
allowedBots: string;
|
||||||
trackProgress: boolean;
|
trackProgress: boolean;
|
||||||
};
|
};
|
||||||
@@ -122,6 +125,8 @@ export function parseGitHubContext(): GitHubContext {
|
|||||||
branchPrefix: process.env.BRANCH_PREFIX ?? "claude/",
|
branchPrefix: process.env.BRANCH_PREFIX ?? "claude/",
|
||||||
useStickyComment: process.env.USE_STICKY_COMMENT === "true",
|
useStickyComment: process.env.USE_STICKY_COMMENT === "true",
|
||||||
useCommitSigning: process.env.USE_COMMIT_SIGNING === "true",
|
useCommitSigning: process.env.USE_COMMIT_SIGNING === "true",
|
||||||
|
botId: process.env.BOT_ID ?? String(CLAUDE_APP_BOT_ID),
|
||||||
|
botName: process.env.BOT_NAME ?? CLAUDE_BOT_LOGIN,
|
||||||
allowedBots: process.env.ALLOWED_BOTS ?? "",
|
allowedBots: process.env.ALLOWED_BOTS ?? "",
|
||||||
trackProgress: process.env.TRACK_PROGRESS === "true",
|
trackProgress: process.env.TRACK_PROGRESS === "true",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,234 +0,0 @@
|
|||||||
import {
|
|
||||||
describe,
|
|
||||||
test,
|
|
||||||
expect,
|
|
||||||
beforeEach,
|
|
||||||
spyOn,
|
|
||||||
afterEach,
|
|
||||||
mock,
|
|
||||||
} from "bun:test";
|
|
||||||
import type { Octokits } from "../../api/client";
|
|
||||||
import type { FetchDataResult } from "../../data/fetcher";
|
|
||||||
import type { ParsedGitHubContext } from "../../context";
|
|
||||||
import type { GitHubPullRequest, GitHubIssue } from "../../types";
|
|
||||||
|
|
||||||
// Mock the entire branch module to avoid executing shell commands
|
|
||||||
const mockSetupBranch = mock();
|
|
||||||
|
|
||||||
// Mock bun shell to prevent actual git commands
|
|
||||||
mock.module("bun", () => ({
|
|
||||||
$: new Proxy(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
get: () => async () => ({ text: async () => "" }),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Mock @actions/core
|
|
||||||
mock.module("@actions/core", () => ({
|
|
||||||
setOutput: mock(),
|
|
||||||
info: mock(),
|
|
||||||
warning: mock(),
|
|
||||||
error: mock(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("setupBranch", () => {
|
|
||||||
let mockOctokits: Octokits;
|
|
||||||
let mockContext: ParsedGitHubContext;
|
|
||||||
let mockGithubData: FetchDataResult;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
mock.restore();
|
|
||||||
|
|
||||||
// Mock the Octokits object with both rest and graphql
|
|
||||||
mockOctokits = {
|
|
||||||
rest: {
|
|
||||||
repos: {
|
|
||||||
get: mock(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
data: { default_branch: "main" },
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
git: {
|
|
||||||
getRef: mock(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
data: {
|
|
||||||
object: { sha: "abc123def456" },
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
graphql: mock(),
|
|
||||||
} as any;
|
|
||||||
|
|
||||||
// Create a base context
|
|
||||||
mockContext = {
|
|
||||||
runId: "12345",
|
|
||||||
eventName: "pull_request",
|
|
||||||
repository: {
|
|
||||||
owner: "test-owner",
|
|
||||||
repo: "test-repo",
|
|
||||||
full_name: "test-owner/test-repo",
|
|
||||||
},
|
|
||||||
actor: "test-user",
|
|
||||||
entityNumber: 42,
|
|
||||||
isPR: true,
|
|
||||||
inputs: {
|
|
||||||
prompt: "",
|
|
||||||
triggerPhrase: "@claude",
|
|
||||||
assigneeTrigger: "",
|
|
||||||
labelTrigger: "",
|
|
||||||
baseBranch: "",
|
|
||||||
branchPrefix: "claude/",
|
|
||||||
useStickyComment: false,
|
|
||||||
useCommitSigning: false,
|
|
||||||
allowedBots: "",
|
|
||||||
trackProgress: true,
|
|
||||||
},
|
|
||||||
payload: {} as any,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create mock GitHub data for a PR
|
|
||||||
mockGithubData = {
|
|
||||||
contextData: {
|
|
||||||
headRefName: "feature/test-branch",
|
|
||||||
baseRefName: "main",
|
|
||||||
state: "OPEN",
|
|
||||||
commits: {
|
|
||||||
totalCount: 5,
|
|
||||||
},
|
|
||||||
} as GitHubPullRequest,
|
|
||||||
comments: [],
|
|
||||||
changedFiles: [],
|
|
||||||
changedFilesWithSHA: [],
|
|
||||||
reviewData: null,
|
|
||||||
imageUrlMap: new Map(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Branch operation test structure", () => {
|
|
||||||
test("should handle PR context correctly", () => {
|
|
||||||
// Verify PR context structure
|
|
||||||
expect(mockContext.isPR).toBe(true);
|
|
||||||
expect(mockContext.entityNumber).toBe(42);
|
|
||||||
expect(mockGithubData.contextData).toHaveProperty("headRefName");
|
|
||||||
expect(mockGithubData.contextData).toHaveProperty("baseRefName");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should handle issue context correctly", () => {
|
|
||||||
// Convert to issue context
|
|
||||||
mockContext.isPR = false;
|
|
||||||
mockContext.eventName = "issues";
|
|
||||||
mockGithubData.contextData = {
|
|
||||||
title: "Test Issue",
|
|
||||||
body: "Issue description",
|
|
||||||
} as GitHubIssue;
|
|
||||||
|
|
||||||
// Verify issue context structure
|
|
||||||
expect(mockContext.isPR).toBe(false);
|
|
||||||
expect(mockContext.eventName).toBe("issues");
|
|
||||||
expect(mockGithubData.contextData).toHaveProperty("title");
|
|
||||||
expect(mockGithubData.contextData).toHaveProperty("body");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should verify branch naming conventions", () => {
|
|
||||||
const timestamp = new Date();
|
|
||||||
const formattedTimestamp = `${timestamp.getFullYear()}${String(timestamp.getMonth() + 1).padStart(2, "0")}${String(timestamp.getDate()).padStart(2, "0")}-${String(timestamp.getHours()).padStart(2, "0")}${String(timestamp.getMinutes()).padStart(2, "0")}`;
|
|
||||||
|
|
||||||
// Test PR branch name
|
|
||||||
const prBranchName = `${mockContext.inputs.branchPrefix}pr-${mockContext.entityNumber}-${formattedTimestamp}`;
|
|
||||||
expect(prBranchName).toMatch(/^claude\/pr-42-\d{8}-\d{4}$/);
|
|
||||||
|
|
||||||
// Test issue branch name
|
|
||||||
const issueBranchName = `${mockContext.inputs.branchPrefix}issue-${mockContext.entityNumber}-${formattedTimestamp}`;
|
|
||||||
expect(issueBranchName).toMatch(/^claude\/issue-42-\d{8}-\d{4}$/);
|
|
||||||
|
|
||||||
// Verify Kubernetes compatibility (lowercase, max 50 chars)
|
|
||||||
const kubeName = prBranchName.toLowerCase().substring(0, 50);
|
|
||||||
expect(kubeName).toMatch(/^[a-z0-9\/-]+$/);
|
|
||||||
expect(kubeName.length).toBeLessThanOrEqual(50);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should handle different PR states", () => {
|
|
||||||
const prData = mockGithubData.contextData as GitHubPullRequest;
|
|
||||||
|
|
||||||
// Test open PR
|
|
||||||
prData.state = "OPEN";
|
|
||||||
expect(prData.state).toBe("OPEN");
|
|
||||||
|
|
||||||
// Test closed PR
|
|
||||||
prData.state = "CLOSED";
|
|
||||||
expect(prData.state).toBe("CLOSED");
|
|
||||||
|
|
||||||
// Test merged PR
|
|
||||||
prData.state = "MERGED";
|
|
||||||
expect(prData.state).toBe("MERGED");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should handle commit signing configuration", () => {
|
|
||||||
// Without commit signing
|
|
||||||
expect(mockContext.inputs.useCommitSigning).toBe(false);
|
|
||||||
|
|
||||||
// With commit signing
|
|
||||||
mockContext.inputs.useCommitSigning = true;
|
|
||||||
expect(mockContext.inputs.useCommitSigning).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should handle custom base branch", () => {
|
|
||||||
// Default (no base branch)
|
|
||||||
expect(mockContext.inputs.baseBranch).toBe("");
|
|
||||||
|
|
||||||
// Custom base branch
|
|
||||||
mockContext.inputs.baseBranch = "develop";
|
|
||||||
expect(mockContext.inputs.baseBranch).toBe("develop");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should verify Octokits structure", () => {
|
|
||||||
expect(mockOctokits).toHaveProperty("rest");
|
|
||||||
expect(mockOctokits).toHaveProperty("graphql");
|
|
||||||
expect(mockOctokits.rest).toHaveProperty("repos");
|
|
||||||
expect(mockOctokits.rest).toHaveProperty("git");
|
|
||||||
expect(mockOctokits.rest.repos).toHaveProperty("get");
|
|
||||||
expect(mockOctokits.rest.git).toHaveProperty("getRef");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should verify FetchDataResult structure", () => {
|
|
||||||
expect(mockGithubData).toHaveProperty("contextData");
|
|
||||||
expect(mockGithubData).toHaveProperty("comments");
|
|
||||||
expect(mockGithubData).toHaveProperty("changedFiles");
|
|
||||||
expect(mockGithubData).toHaveProperty("changedFilesWithSHA");
|
|
||||||
expect(mockGithubData).toHaveProperty("reviewData");
|
|
||||||
expect(mockGithubData).toHaveProperty("imageUrlMap");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should handle PR with varying commit counts", () => {
|
|
||||||
const prData = mockGithubData.contextData as GitHubPullRequest;
|
|
||||||
|
|
||||||
// Few commits
|
|
||||||
prData.commits.totalCount = 5;
|
|
||||||
const fetchDepthSmall = Math.max(prData.commits.totalCount, 20);
|
|
||||||
expect(fetchDepthSmall).toBe(20);
|
|
||||||
|
|
||||||
// Many commits
|
|
||||||
prData.commits.totalCount = 150;
|
|
||||||
const fetchDepthLarge = Math.max(prData.commits.totalCount, 20);
|
|
||||||
expect(fetchDepthLarge).toBe(150);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should verify branch prefix customization", () => {
|
|
||||||
// Default prefix
|
|
||||||
expect(mockContext.inputs.branchPrefix).toBe("claude/");
|
|
||||||
|
|
||||||
// Custom prefix
|
|
||||||
mockContext.inputs.branchPrefix = "bot/";
|
|
||||||
expect(mockContext.inputs.branchPrefix).toBe("bot/");
|
|
||||||
|
|
||||||
// Another custom prefix
|
|
||||||
mockContext.inputs.branchPrefix = "ai-assistant/";
|
|
||||||
expect(mockContext.inputs.branchPrefix).toBe("ai-assistant/");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -17,7 +17,7 @@ type GitUser = {
|
|||||||
export async function configureGitAuth(
|
export async function configureGitAuth(
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
context: GitHubContext,
|
context: GitHubContext,
|
||||||
user: GitUser | null,
|
user: GitUser,
|
||||||
) {
|
) {
|
||||||
console.log("Configuring git authentication for non-signing mode");
|
console.log("Configuring git authentication for non-signing mode");
|
||||||
|
|
||||||
@@ -28,20 +28,14 @@ export async function configureGitAuth(
|
|||||||
? "users.noreply.github.com"
|
? "users.noreply.github.com"
|
||||||
: `users.noreply.${serverUrl.hostname}`;
|
: `users.noreply.${serverUrl.hostname}`;
|
||||||
|
|
||||||
// Configure git user based on the comment creator
|
// Configure git user
|
||||||
console.log("Configuring git user...");
|
console.log("Configuring git user...");
|
||||||
if (user) {
|
|
||||||
const botName = user.login;
|
const botName = user.login;
|
||||||
const botId = user.id;
|
const botId = user.id;
|
||||||
console.log(`Setting git user as ${botName}...`);
|
console.log(`Setting git user as ${botName}...`);
|
||||||
await $`git config user.name "${botName}"`;
|
await $`git config user.name "${botName}"`;
|
||||||
await $`git config user.email "${botId}+${botName}@${noreplyDomain}"`;
|
await $`git config user.email "${botId}+${botName}@${noreplyDomain}"`;
|
||||||
console.log(`✓ Set git user as ${botName}`);
|
console.log(`✓ Set git user as ${botName}`);
|
||||||
} else {
|
|
||||||
console.log("No user data in comment, using default bot user");
|
|
||||||
await $`git config user.name "github-actions[bot]"`;
|
|
||||||
await $`git config user.email "41898282+github-actions[bot]@${noreplyDomain}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the authorization header that actions/checkout sets
|
// Remove the authorization header that actions/checkout sets
|
||||||
console.log("Removing existing git authentication headers...");
|
console.log("Removing existing git authentication headers...");
|
||||||
|
|||||||
@@ -77,22 +77,16 @@ export const agentMode: Mode = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
async prepare({
|
async prepare({ context, githubToken }: ModeOptions): Promise<ModeResult> {
|
||||||
context,
|
|
||||||
githubToken,
|
|
||||||
octokit,
|
|
||||||
}: ModeOptions): Promise<ModeResult> {
|
|
||||||
// Configure git authentication for agent mode (same as tag mode)
|
// Configure git authentication for agent mode (same as tag mode)
|
||||||
if (!context.inputs.useCommitSigning) {
|
if (!context.inputs.useCommitSigning) {
|
||||||
try {
|
// Use bot_id and bot_name from inputs directly
|
||||||
// Get the authenticated user (will be claude[bot] when using Claude App token)
|
|
||||||
const { data: authenticatedUser } =
|
|
||||||
await octokit.rest.users.getAuthenticated();
|
|
||||||
const user = {
|
const user = {
|
||||||
login: authenticatedUser.login,
|
login: context.inputs.botName,
|
||||||
id: authenticatedUser.id,
|
id: parseInt(context.inputs.botId),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
// Use the shared git configuration function
|
// Use the shared git configuration function
|
||||||
await configureGitAuth(githubToken, context, user);
|
await configureGitAuth(githubToken, context, user);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -44,10 +44,6 @@ export function detectMode(context: GitHubContext): AutoDetectedMode {
|
|||||||
|
|
||||||
// Issue events
|
// Issue events
|
||||||
if (isEntityContext(context) && isIssuesEvent(context)) {
|
if (isEntityContext(context) && isIssuesEvent(context)) {
|
||||||
// If prompt is provided, use agent mode (same as PR events)
|
|
||||||
if (context.inputs.prompt) {
|
|
||||||
return "agent";
|
|
||||||
}
|
|
||||||
// Check for @claude mentions or labels/assignees
|
// Check for @claude mentions or labels/assignees
|
||||||
if (checkContainsTrigger(context)) {
|
if (checkContainsTrigger(context)) {
|
||||||
return "tag";
|
return "tag";
|
||||||
|
|||||||
@@ -89,8 +89,14 @@ export const tagMode: Mode = {
|
|||||||
|
|
||||||
// Configure git authentication if not using commit signing
|
// Configure git authentication if not using commit signing
|
||||||
if (!context.inputs.useCommitSigning) {
|
if (!context.inputs.useCommitSigning) {
|
||||||
|
// Use bot_id and bot_name from inputs directly
|
||||||
|
const user = {
|
||||||
|
login: context.inputs.botName,
|
||||||
|
id: parseInt(context.inputs.botId),
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await configureGitAuth(githubToken, context, commentData.user);
|
await configureGitAuth(githubToken, context, user);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to configure git authentication:", error);
|
console.error("Failed to configure git authentication:", error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { describe, test, expect, beforeEach, afterEach, spyOn } from "bun:test";
|
|||||||
import { prepareMcpConfig } from "../src/mcp/install-mcp-server";
|
import { prepareMcpConfig } from "../src/mcp/install-mcp-server";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import type { ParsedGitHubContext } from "../src/github/context";
|
import type { ParsedGitHubContext } from "../src/github/context";
|
||||||
|
import { CLAUDE_APP_BOT_ID, CLAUDE_BOT_LOGIN } from "../src/github/constants";
|
||||||
|
|
||||||
describe("prepareMcpConfig", () => {
|
describe("prepareMcpConfig", () => {
|
||||||
let consoleInfoSpy: any;
|
let consoleInfoSpy: any;
|
||||||
@@ -31,6 +32,8 @@ describe("prepareMcpConfig", () => {
|
|||||||
branchPrefix: "",
|
branchPrefix: "",
|
||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
botId: String(CLAUDE_APP_BOT_ID),
|
||||||
|
botName: CLAUDE_BOT_LOGIN,
|
||||||
allowedBots: "",
|
allowedBots: "",
|
||||||
trackProgress: false,
|
trackProgress: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import type {
|
|||||||
PullRequestReviewEvent,
|
PullRequestReviewEvent,
|
||||||
PullRequestReviewCommentEvent,
|
PullRequestReviewCommentEvent,
|
||||||
} from "@octokit/webhooks-types";
|
} from "@octokit/webhooks-types";
|
||||||
|
import { CLAUDE_APP_BOT_ID, CLAUDE_BOT_LOGIN } from "../src/github/constants";
|
||||||
|
|
||||||
const defaultInputs = {
|
const defaultInputs = {
|
||||||
prompt: "",
|
prompt: "",
|
||||||
@@ -18,6 +19,8 @@ const defaultInputs = {
|
|||||||
branchPrefix: "claude/",
|
branchPrefix: "claude/",
|
||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
botId: String(CLAUDE_APP_BOT_ID),
|
||||||
|
botName: CLAUDE_BOT_LOGIN,
|
||||||
allowedBots: "",
|
allowedBots: "",
|
||||||
trackProgress: false,
|
trackProgress: false,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,23 @@
|
|||||||
import { describe, test, expect, beforeEach, afterEach, spyOn } from "bun:test";
|
import {
|
||||||
|
describe,
|
||||||
|
test,
|
||||||
|
expect,
|
||||||
|
beforeEach,
|
||||||
|
afterEach,
|
||||||
|
spyOn,
|
||||||
|
mock,
|
||||||
|
} from "bun:test";
|
||||||
import { agentMode } from "../../src/modes/agent";
|
import { agentMode } from "../../src/modes/agent";
|
||||||
import type { GitHubContext } from "../../src/github/context";
|
import type { GitHubContext } from "../../src/github/context";
|
||||||
import { createMockContext, createMockAutomationContext } from "../mockContext";
|
import { createMockContext, createMockAutomationContext } from "../mockContext";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
import * as gitConfig from "../../src/github/operations/git-config";
|
||||||
|
|
||||||
describe("Agent Mode", () => {
|
describe("Agent Mode", () => {
|
||||||
let mockContext: GitHubContext;
|
let mockContext: GitHubContext;
|
||||||
let exportVariableSpy: any;
|
let exportVariableSpy: any;
|
||||||
let setOutputSpy: any;
|
let setOutputSpy: any;
|
||||||
|
let configureGitAuthSpy: any;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockContext = createMockAutomationContext({
|
mockContext = createMockAutomationContext({
|
||||||
@@ -17,13 +27,22 @@ describe("Agent Mode", () => {
|
|||||||
() => {},
|
() => {},
|
||||||
);
|
);
|
||||||
setOutputSpy = spyOn(core, "setOutput").mockImplementation(() => {});
|
setOutputSpy = spyOn(core, "setOutput").mockImplementation(() => {});
|
||||||
|
// Mock configureGitAuth to prevent actual git commands from running
|
||||||
|
configureGitAuthSpy = spyOn(
|
||||||
|
gitConfig,
|
||||||
|
"configureGitAuth",
|
||||||
|
).mockImplementation(async () => {
|
||||||
|
// Do nothing - prevent actual git config modifications
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
exportVariableSpy?.mockClear();
|
exportVariableSpy?.mockClear();
|
||||||
setOutputSpy?.mockClear();
|
setOutputSpy?.mockClear();
|
||||||
|
configureGitAuthSpy?.mockClear();
|
||||||
exportVariableSpy?.mockRestore();
|
exportVariableSpy?.mockRestore();
|
||||||
setOutputSpy?.mockRestore();
|
setOutputSpy?.mockRestore();
|
||||||
|
configureGitAuthSpy?.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("agent mode has correct properties", () => {
|
test("agent mode has correct properties", () => {
|
||||||
@@ -113,7 +132,22 @@ describe("Agent Mode", () => {
|
|||||||
// Set CLAUDE_ARGS environment variable
|
// Set CLAUDE_ARGS environment variable
|
||||||
process.env.CLAUDE_ARGS = "--model claude-sonnet-4 --max-turns 10";
|
process.env.CLAUDE_ARGS = "--model claude-sonnet-4 --max-turns 10";
|
||||||
|
|
||||||
const mockOctokit = {} as any;
|
const mockOctokit = {
|
||||||
|
rest: {
|
||||||
|
users: {
|
||||||
|
getAuthenticated: mock(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
data: { login: "test-user", id: 12345 },
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
getByUsername: mock(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
data: { login: "test-user", id: 12345 },
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as any;
|
||||||
const result = await agentMode.prepare({
|
const result = await agentMode.prepare({
|
||||||
context: contextWithCustomArgs,
|
context: contextWithCustomArgs,
|
||||||
octokit: mockOctokit,
|
octokit: mockOctokit,
|
||||||
@@ -152,7 +186,22 @@ describe("Agent Mode", () => {
|
|||||||
// In v1-dev, we only have the unified prompt field
|
// In v1-dev, we only have the unified prompt field
|
||||||
contextWithPrompts.inputs.prompt = "Custom prompt content";
|
contextWithPrompts.inputs.prompt = "Custom prompt content";
|
||||||
|
|
||||||
const mockOctokit = {} as any;
|
const mockOctokit = {
|
||||||
|
rest: {
|
||||||
|
users: {
|
||||||
|
getAuthenticated: mock(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
data: { login: "test-user", id: 12345 },
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
getByUsername: mock(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
data: { login: "test-user", id: 12345 },
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as any;
|
||||||
await agentMode.prepare({
|
await agentMode.prepare({
|
||||||
context: contextWithPrompts,
|
context: contextWithPrompts,
|
||||||
octokit: mockOctokit,
|
octokit: mockOctokit,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { describe, expect, test, spyOn, beforeEach, afterEach } from "bun:test";
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { checkWritePermissions } from "../src/github/validation/permissions";
|
import { checkWritePermissions } from "../src/github/validation/permissions";
|
||||||
import type { ParsedGitHubContext } from "../src/github/context";
|
import type { ParsedGitHubContext } from "../src/github/context";
|
||||||
|
import { CLAUDE_APP_BOT_ID, CLAUDE_BOT_LOGIN } from "../src/github/constants";
|
||||||
|
|
||||||
describe("checkWritePermissions", () => {
|
describe("checkWritePermissions", () => {
|
||||||
let coreInfoSpy: any;
|
let coreInfoSpy: any;
|
||||||
@@ -67,6 +68,8 @@ describe("checkWritePermissions", () => {
|
|||||||
branchPrefix: "claude/",
|
branchPrefix: "claude/",
|
||||||
useStickyComment: false,
|
useStickyComment: false,
|
||||||
useCommitSigning: false,
|
useCommitSigning: false,
|
||||||
|
botId: String(CLAUDE_APP_BOT_ID),
|
||||||
|
botName: CLAUDE_BOT_LOGIN,
|
||||||
allowedBots: "",
|
allowedBots: "",
|
||||||
trackProgress: false,
|
trackProgress: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -113,33 +113,6 @@ describe("detectMode with enhanced routing", () => {
|
|||||||
|
|
||||||
expect(detectMode(context)).toBe("agent");
|
expect(detectMode(context)).toBe("agent");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use agent mode for issues with explicit prompt", () => {
|
|
||||||
const context: GitHubContext = {
|
|
||||||
...baseContext,
|
|
||||||
eventName: "issues",
|
|
||||||
eventAction: "opened",
|
|
||||||
payload: { issue: { number: 1, body: "Test issue" } } as any,
|
|
||||||
entityNumber: 1,
|
|
||||||
isPR: false,
|
|
||||||
inputs: { ...baseContext.inputs, prompt: "Analyze this issue" },
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(detectMode(context)).toBe("agent");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should use tag mode for issues with @claude mention and no prompt", () => {
|
|
||||||
const context: GitHubContext = {
|
|
||||||
...baseContext,
|
|
||||||
eventName: "issues",
|
|
||||||
eventAction: "opened",
|
|
||||||
payload: { issue: { number: 1, body: "@claude help" } } as any,
|
|
||||||
entityNumber: 1,
|
|
||||||
isPR: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(detectMode(context)).toBe("tag");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Comment Events (unchanged behavior)", () => {
|
describe("Comment Events (unchanged behavior)", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user