mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 23:14:13 +08:00
Compare commits
4 Commits
ashwin/tes
...
demo/subtl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66ff608953 | ||
|
|
1a6e0b6355 | ||
|
|
7dff9f06f7 | ||
|
|
f6b1490a80 |
10
action.yml
10
action.yml
@@ -73,14 +73,6 @@ 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
|
||||||
@@ -152,8 +144,6 @@ 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,33 +28,6 @@ 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?
|
||||||
|
|||||||
@@ -47,30 +47,28 @@ 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 | - |
|
||||||
| `track_progress` | Force tag mode with tracking comments. Only works with specific PR/issue events. Preserves GitHub context | No | `false` |
|
| `track_progress` | Force tag mode with tracking comments. Only works with specific PR/issue events. Preserves GitHub context | No | `false` |
|
||||||
| `claude_args` | Additional arguments to pass directly to Claude CLI (e.g., `--max-turns 10 --model claude-4-0-sonnet-20250805`) | No | "" |
|
| `claude_args` | Additional arguments to pass directly to Claude CLI (e.g., `--max-turns 10 --model claude-4-0-sonnet-20250805`) | No | "" |
|
||||||
| `base_branch` | The base branch to use for creating new branches (e.g., 'main', 'develop') | No | - |
|
| `base_branch` | The base branch to use for creating new branches (e.g., 'main', 'develop') | No | - |
|
||||||
| `use_sticky_comment` | Use just one comment to deliver PR comments (only applies for pull_request event workflows) | No | `false` |
|
| `use_sticky_comment` | Use just one comment to deliver PR comments (only applies for pull_request event workflows) | No | `false` |
|
||||||
| `github_token` | GitHub token for Claude to operate with. **Only include this if you're connecting a custom GitHub app of your own!** | No | - |
|
| `github_token` | GitHub token for Claude to operate with. **Only include this if you're connecting a custom GitHub app of your own!** | No | - |
|
||||||
| `use_bedrock` | Use Amazon Bedrock with OIDC authentication instead of direct Anthropic API | No | `false` |
|
| `use_bedrock` | Use Amazon Bedrock with OIDC authentication instead of direct Anthropic API | No | `false` |
|
||||||
| `use_vertex` | Use Google Vertex AI with OIDC authentication instead of direct Anthropic API | No | `false` |
|
| `use_vertex` | Use Google Vertex AI with OIDC authentication instead of direct Anthropic API | No | `false` |
|
||||||
| `mcp_config` | Additional MCP configuration (JSON string) that merges with the built-in GitHub MCP servers | No | "" |
|
| `mcp_config` | Additional MCP configuration (JSON string) that merges with the built-in GitHub MCP servers | No | "" |
|
||||||
| `assignee_trigger` | The assignee username that triggers the action (e.g. @claude). Only used for issue assignment | No | - |
|
| `assignee_trigger` | The assignee username that triggers the action (e.g. @claude). Only used for issue assignment | No | - |
|
||||||
| `label_trigger` | The label name that triggers the action when applied to an issue (e.g. "claude") | No | - |
|
| `label_trigger` | The label name that triggers the action when applied to an issue (e.g. "claude") | No | - |
|
||||||
| `trigger_phrase` | The trigger phrase to look for in comments, issue/PR bodies, and issue titles | No | `@claude` |
|
| `trigger_phrase` | The trigger phrase to look for in comments, issue/PR bodies, and issue titles | No | `@claude` |
|
||||||
| `branch_prefix` | The prefix to use for Claude branches (defaults to 'claude/', use 'claude-' for dash format) | No | `claude/` |
|
| `branch_prefix` | The prefix to use for Claude branches (defaults to 'claude/', use 'claude-' for dash format) | No | `claude/` |
|
||||||
| `settings` | Claude Code settings as JSON string or path to settings JSON file | No | "" |
|
| `settings` | Claude Code settings as JSON string or path to settings JSON file | No | "" |
|
||||||
| `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` |
|
| `allowed_bots` | Comma-separated list of allowed bot usernames, or '\*' to allow all bots. Empty string (default) allows no bots | No | "" |
|
||||||
| `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 | "" |
|
|
||||||
|
|
||||||
### Deprecated Inputs
|
### Deprecated Inputs
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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,7 +8,6 @@ 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;
|
||||||
@@ -75,8 +74,6 @@ 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;
|
||||||
};
|
};
|
||||||
@@ -125,8 +122,6 @@ 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",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type GitUser = {
|
|||||||
export async function configureGitAuth(
|
export async function configureGitAuth(
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
context: GitHubContext,
|
context: GitHubContext,
|
||||||
user: GitUser,
|
user: GitUser | null,
|
||||||
) {
|
) {
|
||||||
console.log("Configuring git authentication for non-signing mode");
|
console.log("Configuring git authentication for non-signing mode");
|
||||||
|
|
||||||
@@ -28,14 +28,20 @@ export async function configureGitAuth(
|
|||||||
? "users.noreply.github.com"
|
? "users.noreply.github.com"
|
||||||
: `users.noreply.${serverUrl.hostname}`;
|
: `users.noreply.${serverUrl.hostname}`;
|
||||||
|
|
||||||
// Configure git user
|
// Configure git user based on the comment creator
|
||||||
console.log("Configuring git user...");
|
console.log("Configuring git user...");
|
||||||
const botName = user.login;
|
if (user) {
|
||||||
const botId = user.id;
|
const botName = user.login;
|
||||||
console.log(`Setting git user as ${botName}...`);
|
const botId = user.id;
|
||||||
await $`git config user.name "${botName}"`;
|
console.log(`Setting git user as ${botName}...`);
|
||||||
await $`git config user.email "${botId}+${botName}@${noreplyDomain}"`;
|
await $`git config user.name "${botName}"`;
|
||||||
console.log(`✓ Set git user as ${botName}`);
|
await $`git config user.email "${botId}+${botName}@${noreplyDomain}"`;
|
||||||
|
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...");
|
||||||
|
|||||||
259
src/github/validation/__tests__/trigger.test.ts
Normal file
259
src/github/validation/__tests__/trigger.test.ts
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
import { describe, test, expect } from "bun:test";
|
||||||
|
import { checkContainsTrigger } from "../trigger";
|
||||||
|
import type { ParsedGitHubContext } from "../../context";
|
||||||
|
|
||||||
|
describe("Trigger Validation", () => {
|
||||||
|
const createMockContext = (overrides = {}): ParsedGitHubContext => ({
|
||||||
|
eventName: "issue_comment",
|
||||||
|
eventAction: "created",
|
||||||
|
repository: {
|
||||||
|
owner: "test-owner",
|
||||||
|
repo: "test-repo",
|
||||||
|
full_name: "test-owner/test-repo",
|
||||||
|
},
|
||||||
|
actor: "testuser",
|
||||||
|
entityNumber: 42,
|
||||||
|
isPR: false,
|
||||||
|
runId: "test-run-id",
|
||||||
|
inputs: {
|
||||||
|
triggerPhrase: "@claude",
|
||||||
|
assigneeTrigger: "",
|
||||||
|
labelTrigger: "",
|
||||||
|
prompt: "",
|
||||||
|
trackProgress: false,
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
comment: {
|
||||||
|
body: "Test comment",
|
||||||
|
id: 12345,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...overrides,
|
||||||
|
} as ParsedGitHubContext);
|
||||||
|
|
||||||
|
describe("checkContainsTrigger", () => {
|
||||||
|
test("should detect @claude mentions", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
payload: {
|
||||||
|
comment: { body: "Hey @claude can you fix this?", id: 12345 },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should detect Claude mentions case-insensitively", () => {
|
||||||
|
// Testing multiple case variations
|
||||||
|
const contexts = [
|
||||||
|
createMockContext({
|
||||||
|
payload: { comment: { body: "Hey @Claude please help", id: 12345 } },
|
||||||
|
}),
|
||||||
|
createMockContext({
|
||||||
|
payload: { comment: { body: "Hey @CLAUDE please help", id: 12345 } },
|
||||||
|
}),
|
||||||
|
createMockContext({
|
||||||
|
payload: { comment: { body: "Hey @ClAuDe please help", id: 12345 } },
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Note: The actual function is case-sensitive, it looks for exact match
|
||||||
|
contexts.forEach(context => {
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(false); // @claude is case-sensitive
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should not trigger on partial matches", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
payload: {
|
||||||
|
comment: { body: "Emailed @claudette about this", id: 12345 },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle claude mentions in code blocks", () => {
|
||||||
|
// Testing mentions inside code blocks - they SHOULD trigger
|
||||||
|
// The regex checks for word boundaries, not markdown context
|
||||||
|
const context = createMockContext({
|
||||||
|
payload: {
|
||||||
|
comment: {
|
||||||
|
body: "Here's an example:\n```\n@claude fix this\n```",
|
||||||
|
id: 12345
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(true); // Mentions in code blocks do trigger
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should detect trigger in issue body for opened events", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
eventName: "issues",
|
||||||
|
eventAction: "opened",
|
||||||
|
payload: {
|
||||||
|
action: "opened",
|
||||||
|
issue: {
|
||||||
|
body: "@claude implement this feature",
|
||||||
|
title: "New feature",
|
||||||
|
number: 42
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle multiple mentions", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
payload: {
|
||||||
|
comment: { body: "@claude and @claude should both work", id: 12345 },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Multiple mentions in same comment should trigger (only needs one match)
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle null/undefined comment body", () => {
|
||||||
|
const contextNull = createMockContext({
|
||||||
|
payload: { comment: { body: null } },
|
||||||
|
});
|
||||||
|
const contextUndefined = createMockContext({
|
||||||
|
payload: { comment: { body: undefined } },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(checkContainsTrigger(contextNull)).toBe(false);
|
||||||
|
expect(checkContainsTrigger(contextUndefined)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle empty comment body", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
payload: { comment: { body: "" } },
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should detect trigger in pull request body", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
eventName: "pull_request",
|
||||||
|
eventAction: "opened",
|
||||||
|
isPR: true,
|
||||||
|
payload: {
|
||||||
|
action: "opened",
|
||||||
|
pull_request: {
|
||||||
|
body: "@claude please review this PR",
|
||||||
|
title: "Feature update",
|
||||||
|
number: 42
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should detect trigger in pull request review", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
eventName: "pull_request_review",
|
||||||
|
eventAction: "submitted",
|
||||||
|
isPR: true,
|
||||||
|
payload: {
|
||||||
|
action: "submitted",
|
||||||
|
review: {
|
||||||
|
body: "@claude can you fix this issue?",
|
||||||
|
id: 999
|
||||||
|
},
|
||||||
|
pull_request: {
|
||||||
|
number: 42
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should detect trigger when assigned to specified user", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
eventName: "issues",
|
||||||
|
eventAction: "assigned",
|
||||||
|
inputs: {
|
||||||
|
triggerPhrase: "@claude",
|
||||||
|
assigneeTrigger: "claude-bot",
|
||||||
|
labelTrigger: "",
|
||||||
|
prompt: "",
|
||||||
|
trackProgress: false,
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
action: "assigned",
|
||||||
|
issue: {
|
||||||
|
number: 42,
|
||||||
|
body: "Some issue",
|
||||||
|
title: "Title"
|
||||||
|
},
|
||||||
|
assignee: {
|
||||||
|
login: "claude-bot"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should detect trigger when labeled with specified label", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
eventName: "issues",
|
||||||
|
eventAction: "labeled",
|
||||||
|
inputs: {
|
||||||
|
triggerPhrase: "@claude",
|
||||||
|
assigneeTrigger: "",
|
||||||
|
labelTrigger: "needs-claude",
|
||||||
|
prompt: "",
|
||||||
|
trackProgress: false,
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
action: "labeled",
|
||||||
|
issue: {
|
||||||
|
number: 42,
|
||||||
|
body: "Some issue",
|
||||||
|
title: "Title"
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
name: "needs-claude"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should always trigger when prompt is provided", () => {
|
||||||
|
const context = createMockContext({
|
||||||
|
inputs: {
|
||||||
|
triggerPhrase: "@claude",
|
||||||
|
assigneeTrigger: "",
|
||||||
|
labelTrigger: "",
|
||||||
|
prompt: "Fix all the bugs",
|
||||||
|
trackProgress: false,
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
comment: { body: "No trigger phrase here", id: 12345 },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = checkContainsTrigger(context);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -77,16 +77,22 @@ export const agentMode: Mode = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
async prepare({ context, githubToken }: ModeOptions): Promise<ModeResult> {
|
async prepare({
|
||||||
|
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) {
|
||||||
// Use bot_id and bot_name from inputs directly
|
|
||||||
const user = {
|
|
||||||
login: context.inputs.botName,
|
|
||||||
id: parseInt(context.inputs.botId),
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Get the authenticated user (will be claude[bot] when using Claude App token)
|
||||||
|
const { data: authenticatedUser } =
|
||||||
|
await octokit.rest.users.getAuthenticated();
|
||||||
|
const user = {
|
||||||
|
login: authenticatedUser.login,
|
||||||
|
id: authenticatedUser.id,
|
||||||
|
};
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|||||||
@@ -89,14 +89,8 @@ 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, user);
|
await configureGitAuth(githubToken, context, commentData.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,7 +2,6 @@ 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;
|
||||||
@@ -32,8 +31,6 @@ 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,7 +9,6 @@ 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: "",
|
||||||
@@ -19,8 +18,6 @@ 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,23 +1,13 @@
|
|||||||
import {
|
import { describe, test, expect, beforeEach, afterEach, spyOn } from "bun:test";
|
||||||
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({
|
||||||
@@ -27,22 +17,13 @@ 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", () => {
|
||||||
@@ -132,22 +113,7 @@ 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 = {
|
const mockOctokit = {} as any;
|
||||||
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,
|
||||||
@@ -186,22 +152,7 @@ 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 = {
|
const mockOctokit = {} as any;
|
||||||
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,7 +2,6 @@ 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;
|
||||||
@@ -68,8 +67,6 @@ 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,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user