Skip to content

Commit 97e2655

Browse files
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
1 parent 9e79bda commit 97e2655

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/github.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ export const reactionTypes: ReactionID[] = ['+1', '-1', 'laugh', 'hooray', 'conf
1515

1616
let owner: string;
1717
let repo: string;
18-
const branch = 'master';
18+
let branch = 'master';
1919

20-
export function setRepoContext(context: { owner: string; repo: string; }) {
20+
export function setRepoContext(context: { owner: string; repo: string; branch?: string; }) {
2121
owner = context.owner;
2222
repo = context.repo;
23+
if (context.branch) {
24+
branch = context.branch;
25+
}
2326
}
2427

2528
function githubRequest(relativeUrl: string, init?: RequestInit) {

src/page-attributes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function readPageAttributes() {
5151
description: params.description,
5252
label: params.label,
5353
theme: params.theme || 'github-light',
54-
session: params.session
54+
session: params.session,
55+
branch: params.branch || 'master'
5556
};
5657
}
5758

src/utterances.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async function renderComments(issue: Issue, timeline: TimelineComponent) {
138138

139139
export async function assertOrigin() {
140140
const { origins } = await getRepoConfig();
141-
const { origin, owner, repo } = page;
141+
const { origin, owner, repo, branch } = page;
142142
if (origins.indexOf(origin) !== -1) {
143143
return;
144144
}
@@ -147,7 +147,7 @@ export async function assertOrigin() {
147147
<div class="flash flash-error flash-not-installed">
148148
Error: <code>${origin}</code> is not permitted to post to <code>${owner}/${repo}</code>.
149149
Confirm this is the correct repo for this site's comments. If you own this repo,
150-
<a href="https://github.com/${owner}/${repo}/edit/master/utterances.json" target="_top">
150+
<a href="https://github.com/${owner}/${repo}/edit/${branch}/utterances.json" target="_top">
151151
<strong>update the utterances.json</strong>
152152
</a>
153153
to include <code>${origin}</code> in the list of origins.<br/><br/>

0 commit comments

Comments
 (0)