From 3fa4ea21746fbdcc9fbf8ee54fb274285dbab0c6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 4 Sep 2025 10:36:22 -0700 Subject: [PATCH] refactor: replace magic number with GITHUB_ACTIONS_BOT_ID constant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- action.yml | 2 +- src/github/constants.ts | 14 ++++++++++++++ src/github/context.ts | 3 ++- src/github/operations/git-config.ts | 5 +++-- src/modes/agent/index.ts | 3 ++- test/install-mcp-server.test.ts | 3 ++- test/mockContext.ts | 3 ++- test/permissions.test.ts | 3 ++- 8 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/github/constants.ts diff --git a/action.yml b/action.yml index d9cdf7c..3f47a2f 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/src/github/constants.ts b/src/github/constants.ts new file mode 100644 index 0000000..f7bfbf4 --- /dev/null +++ b/src/github/constants.ts @@ -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]"; diff --git a/src/github/context.ts b/src/github/context.ts index 8a3a2ba..6332efb 100644 --- a/src/github/context.ts +++ b/src/github/context.ts @@ -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", }, diff --git a/src/github/operations/git-config.ts b/src/github/operations/git-config.ts index 0ff9500..5d759ab 100644 --- a/src/github/operations/git-config.ts +++ b/src/github/operations/git-config.ts @@ -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 diff --git a/src/modes/agent/index.ts b/src/modes/agent/index.ts index 51b2f21..38d1ba3 100644 --- a/src/modes/agent/index.ts +++ b/src/modes/agent/index.ts @@ -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({ diff --git a/test/install-mcp-server.test.ts b/test/install-mcp-server.test.ts index 601d817..bdeae97 100644 --- a/test/install-mcp-server.test.ts +++ b/test/install-mcp-server.test.ts @@ -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, }, diff --git a/test/mockContext.ts b/test/mockContext.ts index 3786813..effc23b 100644 --- a/test/mockContext.ts +++ b/test/mockContext.ts @@ -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, }; diff --git a/test/permissions.test.ts b/test/permissions.test.ts index 7d82e12..f4d2ea0 100644 --- a/test/permissions.test.ts +++ b/test/permissions.test.ts @@ -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, },