MCPcopy Index your code
hub / github.com/refined-github/refined-github / isDefaultBranch

Function isDefaultBranch

source/github-helpers/is-default-branch.ts:5–28  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4/** Detects if the current view is on the default branch. To be used on file/folder/commit lists */
5export default async function isDefaultBranch(): Promise<boolean> {
6 const repo = getRepo();
7 if (!repo) {
8 // Like /settings/repositories
9 return false;
10 }
11
12 const [type, ...parts] = repo.path.split('/');
13 if (parts.length === 0) {
14 // Exactly /user/repo, which is on the default branch
15 return true;
16 }
17
18 if (!['tree', 'blob', 'commits'].includes(type)) {
19 // Like /user/repo/pulls
20 return false;
21 }
22
23 // Don't use `getCurrentGitRef` because it requires too much DOM. This is good enough, it only fails when:
24 // defaultBranch === 'a/b' && currentBranch === 'a'
25 const path = parts.join('/');
26 const defaultBranch = await getDefaultBranch();
27 return path === defaultBranch || path.startsWith(`${defaultBranch}/`);
28}

Callers 1

addFunction · 0.85

Calls 2

getDefaultBranchFunction · 0.85
includesMethod · 0.80

Tested by

no test coverage detected