mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
feat: add bot_id input to handle GitHub App authentication errors
Adds a new optional bot_id input parameter that defaults to the github-actions[bot] ID (41898282). This resolves the "403 Resource not accessible by integration" error that occurs when using GitHub App installation tokens, which cannot access the /user endpoint. Changes: - Add bot_id input to action.yml with default value - Update context parsing to include bot_id from environment - Modify agent mode to use bot_id when available, avoiding API calls that fail with GitHub App tokens - Add clear error handling for GitHub App token limitations - Update documentation in usage.md and faq.md - Fix test mocks to include bot_id field This allows users to specify a custom bot user ID or use the default github-actions[bot] ID automatically, preventing 403 errors in automation workflows. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,7 @@ describe("prepareMcpConfig", () => {
|
||||
branchPrefix: "",
|
||||
useStickyComment: false,
|
||||
useCommitSigning: false,
|
||||
botId: "41898282",
|
||||
allowedBots: "",
|
||||
trackProgress: false,
|
||||
},
|
||||
|
||||
@@ -18,6 +18,7 @@ const defaultInputs = {
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
useCommitSigning: false,
|
||||
botId: "41898282",
|
||||
allowedBots: "",
|
||||
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 type { GitHubContext } from "../../src/github/context";
|
||||
import { createMockContext, createMockAutomationContext } from "../mockContext";
|
||||
import * as core from "@actions/core";
|
||||
import * as gitConfig from "../../src/github/operations/git-config";
|
||||
|
||||
describe("Agent Mode", () => {
|
||||
let mockContext: GitHubContext;
|
||||
let exportVariableSpy: any;
|
||||
let setOutputSpy: any;
|
||||
let configureGitAuthSpy: any;
|
||||
|
||||
beforeEach(() => {
|
||||
mockContext = createMockAutomationContext({
|
||||
@@ -17,13 +27,22 @@ describe("Agent Mode", () => {
|
||||
() => {},
|
||||
);
|
||||
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(() => {
|
||||
exportVariableSpy?.mockClear();
|
||||
setOutputSpy?.mockClear();
|
||||
configureGitAuthSpy?.mockClear();
|
||||
exportVariableSpy?.mockRestore();
|
||||
setOutputSpy?.mockRestore();
|
||||
configureGitAuthSpy?.mockRestore();
|
||||
});
|
||||
|
||||
test("agent mode has correct properties", () => {
|
||||
@@ -113,7 +132,22 @@ describe("Agent Mode", () => {
|
||||
// Set CLAUDE_ARGS environment variable
|
||||
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({
|
||||
context: contextWithCustomArgs,
|
||||
octokit: mockOctokit,
|
||||
@@ -152,7 +186,22 @@ describe("Agent Mode", () => {
|
||||
// In v1-dev, we only have the unified prompt field
|
||||
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({
|
||||
context: contextWithPrompts,
|
||||
octokit: mockOctokit,
|
||||
|
||||
@@ -67,6 +67,7 @@ describe("checkWritePermissions", () => {
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
useCommitSigning: false,
|
||||
botId: "41898282",
|
||||
allowedBots: "",
|
||||
trackProgress: false,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user