From a674be1d74fad387d00582b1c1b3f1f64793aa99 Mon Sep 17 00:00:00 2001 From: SL Date: Thu, 4 Jun 2026 11:50:23 +0800 Subject: [PATCH] feat: support configurable branch name for 'main' and other defaults The branch name was hardcoded as 'master', causing the whitelist feature to fail when repositories use 'main' or other default branch names. Changes: - Add 'branch' parameter to page-attributes (defaults to 'master') - Make branch variable in github.ts configurable via setRepoContext() - Update error message link to use the configured branch Fixes #523 --- src/github.ts | 7 +++++-- src/page-attributes.ts | 3 ++- src/utterances.ts | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/github.ts b/src/github.ts index fad8b6f4..335a9fd3 100644 --- a/src/github.ts +++ b/src/github.ts @@ -15,11 +15,14 @@ export const reactionTypes: ReactionID[] = ['+1', '-1', 'laugh', 'hooray', 'conf let owner: string; let repo: string; -const branch = 'master'; +let branch = 'master'; -export function setRepoContext(context: { owner: string; repo: string; }) { +export function setRepoContext(context: { owner: string; repo: string; branch?: string; }) { owner = context.owner; repo = context.repo; + if (context.branch) { + branch = context.branch; + } } function githubRequest(relativeUrl: string, init?: RequestInit) { diff --git a/src/page-attributes.ts b/src/page-attributes.ts index 64783325..c88da6a4 100644 --- a/src/page-attributes.ts +++ b/src/page-attributes.ts @@ -51,7 +51,8 @@ function readPageAttributes() { description: params.description, label: params.label, theme: params.theme || 'github-light', - session: params.session + session: params.session, + branch: params.branch || 'master' }; } diff --git a/src/utterances.ts b/src/utterances.ts index 588bf08b..9a3b78a7 100644 --- a/src/utterances.ts +++ b/src/utterances.ts @@ -138,7 +138,7 @@ async function renderComments(issue: Issue, timeline: TimelineComponent) { export async function assertOrigin() { const { origins } = await getRepoConfig(); - const { origin, owner, repo } = page; + const { origin, owner, repo, branch } = page; if (origins.indexOf(origin) !== -1) { return; } @@ -147,7 +147,7 @@ export async function assertOrigin() {
Error: ${origin} is not permitted to post to ${owner}/${repo}. Confirm this is the correct repo for this site's comments. If you own this repo, - + update the utterances.json to include ${origin} in the list of origins.