mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
refactor: replace magic number with GITHUB_ACTIONS_BOT_ID constant
- Create new constants file at src/github/constants.ts with GITHUB_ACTIONS_BOT_ID and GITHUB_ACTIONS_BOT_LOGIN - Replace all occurrences of magic number 41898282 with the constant - Update imports across source and test files to use the new constants - Add comment in action.yml referencing the constants file for the default bot_id value This improves code maintainability by centralizing the GitHub Actions bot ID definition. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -76,7 +76,7 @@ inputs:
|
||||
bot_id:
|
||||
description: "GitHub user ID to use for git operations when authenticated user cannot be fetched (defaults to github-actions[bot] ID)"
|
||||
required: false
|
||||
default: "41898282"
|
||||
default: "41898282" # github-actions[bot] ID - see src/github/constants.ts
|
||||
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."
|
||||
required: false
|
||||
|
||||
14
src/github/constants.ts
Normal file
14
src/github/constants.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* GitHub-related constants used throughout the application
|
||||
*/
|
||||
|
||||
/**
|
||||
* GitHub Actions bot user ID
|
||||
* This is the official ID for github-actions[bot] used in GitHub repositories
|
||||
*/
|
||||
export const GITHUB_ACTIONS_BOT_ID = 41898282;
|
||||
|
||||
/**
|
||||
* GitHub Actions bot username
|
||||
*/
|
||||
export const GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]";
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
PullRequestReviewCommentEvent,
|
||||
WorkflowRunEvent,
|
||||
} from "@octokit/webhooks-types";
|
||||
import { GITHUB_ACTIONS_BOT_ID } from "./constants";
|
||||
// Custom types for GitHub Actions events that aren't webhooks
|
||||
export type WorkflowDispatchEvent = {
|
||||
action?: never;
|
||||
@@ -123,7 +124,7 @@ export function parseGitHubContext(): GitHubContext {
|
||||
branchPrefix: process.env.BRANCH_PREFIX ?? "claude/",
|
||||
useStickyComment: process.env.USE_STICKY_COMMENT === "true",
|
||||
useCommitSigning: process.env.USE_COMMIT_SIGNING === "true",
|
||||
botId: process.env.BOT_ID ?? "41898282",
|
||||
botId: process.env.BOT_ID ?? String(GITHUB_ACTIONS_BOT_ID),
|
||||
allowedBots: process.env.ALLOWED_BOTS ?? "",
|
||||
trackProgress: process.env.TRACK_PROGRESS === "true",
|
||||
},
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import { $ } from "bun";
|
||||
import type { GitHubContext } from "../context";
|
||||
import { GITHUB_SERVER_URL } from "../api/config";
|
||||
import { GITHUB_ACTIONS_BOT_ID, GITHUB_ACTIONS_BOT_LOGIN } from "../constants";
|
||||
|
||||
type GitUser = {
|
||||
login: string;
|
||||
@@ -39,8 +40,8 @@ export async function configureGitAuth(
|
||||
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}"`;
|
||||
await $`git config user.name "${GITHUB_ACTIONS_BOT_LOGIN}"`;
|
||||
await $`git config user.email "${GITHUB_ACTIONS_BOT_ID}+${GITHUB_ACTIONS_BOT_LOGIN}@${noreplyDomain}"`;
|
||||
}
|
||||
|
||||
// Remove the authorization header that actions/checkout sets
|
||||
|
||||
@@ -7,6 +7,7 @@ import { parseAllowedTools } from "./parse-tools";
|
||||
import { configureGitAuth } from "../../github/operations/git-config";
|
||||
import type { GitHubContext } from "../../github/context";
|
||||
import { isEntityContext } from "../../github/context";
|
||||
import { GITHUB_ACTIONS_BOT_ID } from "../../github/constants";
|
||||
|
||||
/**
|
||||
* Extract GitHub context as environment variables for agent mode
|
||||
@@ -88,7 +89,7 @@ export const agentMode: Mode = {
|
||||
|
||||
// Check if bot_id is provided
|
||||
const botId = context.inputs.botId;
|
||||
if (botId && botId !== "41898282") {
|
||||
if (botId && botId !== String(GITHUB_ACTIONS_BOT_ID)) {
|
||||
// Use custom bot_id - try to fetch user info
|
||||
try {
|
||||
const { data: userData } = await octokit.rest.users.getByUsername({
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, test, expect, beforeEach, afterEach, spyOn } from "bun:test";
|
||||
import { prepareMcpConfig } from "../src/mcp/install-mcp-server";
|
||||
import * as core from "@actions/core";
|
||||
import type { ParsedGitHubContext } from "../src/github/context";
|
||||
import { GITHUB_ACTIONS_BOT_ID } from "../src/github/constants";
|
||||
|
||||
describe("prepareMcpConfig", () => {
|
||||
let consoleInfoSpy: any;
|
||||
@@ -31,7 +32,7 @@ describe("prepareMcpConfig", () => {
|
||||
branchPrefix: "",
|
||||
useStickyComment: false,
|
||||
useCommitSigning: false,
|
||||
botId: "41898282",
|
||||
botId: String(GITHUB_ACTIONS_BOT_ID),
|
||||
allowedBots: "",
|
||||
trackProgress: false,
|
||||
},
|
||||
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
PullRequestReviewEvent,
|
||||
PullRequestReviewCommentEvent,
|
||||
} from "@octokit/webhooks-types";
|
||||
import { GITHUB_ACTIONS_BOT_ID } from "../src/github/constants";
|
||||
|
||||
const defaultInputs = {
|
||||
prompt: "",
|
||||
@@ -18,7 +19,7 @@ const defaultInputs = {
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
useCommitSigning: false,
|
||||
botId: "41898282",
|
||||
botId: String(GITHUB_ACTIONS_BOT_ID),
|
||||
allowedBots: "",
|
||||
trackProgress: false,
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, test, spyOn, beforeEach, afterEach } from "bun:test";
|
||||
import * as core from "@actions/core";
|
||||
import { checkWritePermissions } from "../src/github/validation/permissions";
|
||||
import type { ParsedGitHubContext } from "../src/github/context";
|
||||
import { GITHUB_ACTIONS_BOT_ID } from "../src/github/constants";
|
||||
|
||||
describe("checkWritePermissions", () => {
|
||||
let coreInfoSpy: any;
|
||||
@@ -67,7 +68,7 @@ describe("checkWritePermissions", () => {
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
useCommitSigning: false,
|
||||
botId: "41898282",
|
||||
botId: String(GITHUB_ACTIONS_BOT_ID),
|
||||
allowedBots: "",
|
||||
trackProgress: false,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user