fix: fall back to repo default_branch instead of hardcoded "main" (#1143)

* fix: fall back to repo default_branch instead of hardcoded "main"

When no explicit base_branch input is provided, the action previously
fell back to a hardcoded "main", which fails on repositories whose
default branch is named differently (e.g. "master", "develop").

This reads repository.default_branch from the GitHub event payload
(populated once in parseGitHubContext) and uses it as the fallback in
all three callsites: agent/index.ts, run.ts, and update-comment-link.ts.
Explicit env/input precedence is preserved; "main" remains only as a
last-resort defensive fallback if the payload somehow lacks the field.

* test: drop unused BASE_BRANCH env handling from default_branch test

agent/index.ts no longer reads process.env.BASE_BRANCH directly (it now
goes through context.inputs.baseBranch which is set on the mock context),
so saving/clearing/restoring that env var in the regression test is dead
code.
This commit is contained in:
Ashwin Bhat
2026-04-01 14:48:46 -07:00
committed by GitHub
parent 408a40e7c2
commit c281e17d7f
6 changed files with 66 additions and 8 deletions
+3 -3
View File
@@ -229,8 +229,8 @@ async function run() {
// Restore them from the base branch before the CLI reads them.
//
// We read pull_request.base.ref from the payload directly because agent
// mode's branchInfo.baseBranch defaults to "main" rather than the PR's
// actual target (agent/index.ts). For issue_comment on a PR the payload
// mode's branchInfo.baseBranch defaults to the repo's default branch rather
// than the PR's actual target (agent/index.ts). For issue_comment on a PR the payload
// lacks base.ref, so we fall back to the mode-provided value — tag mode
// fetches it from GraphQL; agent mode on issue_comment is an edge case
// that at worst restores from the wrong trusted branch (still secure).
@@ -312,7 +312,7 @@ async function run() {
commentId,
githubToken,
claudeBranch,
baseBranch: baseBranch || "main",
baseBranch: baseBranch || context.repository.default_branch || "main",
triggerUsername: context.actor,
context,
octokit,