summaryrefslogtreecommitdiff
path: root/source/github-helpers/is-default-branch.ts
diff options
context:
space:
mode:
authorGravatar Federico Brigante <me@fregante.com> 2023-05-10 04:32:07 +0800
committerGravatar GitHub <noreply@github.com> 2023-05-10 04:32:07 +0800
commit747b87a6358c729e54148021d44c94e828603e01 (patch)
treedbe2d54ce393ce66bc9ada86655647ed2a586e00 /source/github-helpers/is-default-branch.ts
parent12532fc4c149f5922fffba89ee2624bf3982e975 (diff)
downloadrefined-github-747b87a6358c729e54148021d44c94e828603e01.tar.gz
refined-github-747b87a6358c729e54148021d44c94e828603e01.tar.zst
refined-github-747b87a6358c729e54148021d44c94e828603e01.zip
Reliability fixes for `default-branch-button` (#6629)
Diffstat (limited to 'source/github-helpers/is-default-branch.ts')
-rw-r--r--source/github-helpers/is-default-branch.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/source/github-helpers/is-default-branch.ts b/source/github-helpers/is-default-branch.ts
new file mode 100644
index 00000000..82ef0be1
--- /dev/null
+++ b/source/github-helpers/is-default-branch.ts
@@ -0,0 +1,13 @@
+import getDefaultBranch from './get-default-branch.js';
+import getCurrentGitRef from './get-current-git-ref.js';
+
+/** Detects if the current view is on the default branch. To be used on file/folder/commit lists */
+export default async function isDefaultBranch(): Promise<boolean> {
+ const currentBranch = getCurrentGitRef();
+ if (!currentBranch) {
+ // This happens on the repo root OR on views that are not branch-specific (like isIssue)
+ return true;
+ }
+
+ return currentBranch === await getDefaultBranch();
+}