summaryrefslogtreecommitdiff
path: root/source/features
diff options
context:
space:
mode:
Diffstat (limited to 'source/features')
-rw-r--r--source/features/default-branch-button.tsx3
-rw-r--r--source/features/list-prs-for-branch.tsx41
-rw-r--r--source/features/unreleased-commits.tsx21
3 files changed, 41 insertions, 24 deletions
diff --git a/source/features/default-branch-button.tsx b/source/features/default-branch-button.tsx
index eb9258df..866f80c8 100644
--- a/source/features/default-branch-button.tsx
+++ b/source/features/default-branch-button.tsx
@@ -10,6 +10,7 @@ import getDefaultBranch from '../github-helpers/get-default-branch.js';
import observe from '../helpers/selector-observer.js';
import {branchSelector} from '../github-helpers/selectors.js';
import isDefaultBranch from '../github-helpers/is-default-branch.js';
+import {isRepoCommitListRoot} from '../github-helpers/index.js';
async function add(branchSelector: HTMLElement): Promise<void> {
// Don't show the button if we’re already on the default branch
@@ -55,7 +56,7 @@ void features.add(import.meta.url, {
include: [
pageDetect.isRepoTree,
pageDetect.isSingleFile,
- pageDetect.isRepoCommitList,
+ isRepoCommitListRoot,
],
exclude: [
pageDetect.isRepoHome,
diff --git a/source/features/list-prs-for-branch.tsx b/source/features/list-prs-for-branch.tsx
index 93986967..ae61b6f4 100644
--- a/source/features/list-prs-for-branch.tsx
+++ b/source/features/list-prs-for-branch.tsx
@@ -1,12 +1,13 @@
import React from 'dom-chef';
-import * as pageDetect from 'github-url-detection';
import features from '../feature-manager.js';
import getCurrentGitRef from '../github-helpers/get-current-git-ref.js';
import isDefaultBranch from '../github-helpers/is-default-branch.js';
-import addAfterBranchSelector from '../helpers/add-after-branch-selector.js';
import {getPullRequestsAssociatedWithBranch, stateIcon} from './show-associated-branch-prs-on-fork.js';
-import {isPermalink} from '../github-helpers/index.js';
+import {addAfterBranchSelector, isPermalink, isRepoCommitListRoot} from '../github-helpers/index.js';
+import observe from '../helpers/selector-observer.js';
+import api from '../github-helpers/api.js';
+import {branchSelectorParent} from '../github-helpers/selectors.js';
// Taken from https://github.com/fregante/github-issue-link-status/blob/98792f2837352bacbf80664f3edbcec8e579ed17/source/github-issue-link-status.js#L10
const stateColorMap = {
@@ -16,11 +17,7 @@ const stateColorMap = {
DRAFT: '',
};
-async function init(): Promise<void | false> {
- if (await isPermalink() || await isDefaultBranch()) {
- return false;
- }
-
+async function add(branchSelectorParent: HTMLDetailsElement): Promise<void | false> {
const getPr = await getPullRequestsAssociatedWithBranch();
const currentBranch = getCurrentGitRef()!;
const prInfo = getPr[currentBranch];
@@ -29,7 +26,9 @@ async function init(): Promise<void | false> {
}
const StateIcon = stateIcon[prInfo.state];
- const link = (
+
+ addAfterBranchSelector(
+ branchSelectorParent,
<a
data-issue-and-pr-hovercards-enabled
href={prInfo.url}
@@ -39,16 +38,32 @@ async function init(): Promise<void | false> {
>
<StateIcon className={stateColorMap[prInfo.state]}/>
<span> #{prInfo.number}</span>
- </a>
+ </a>,
);
+}
- await addAfterBranchSelector(link);
+async function init(signal: AbortSignal): Promise<false | void> {
+ if (await isPermalink() || await isDefaultBranch()) {
+ return false;
+ }
+
+ await api.expectToken();
+
+ observe(branchSelectorParent, add, {signal});
}
void features.add(import.meta.url, {
include: [
- pageDetect.isRepoCommitList,
+ isRepoCommitListRoot,
],
- deduplicate: 'has-rgh-inner',
init,
});
+
+/*
+
+Test URLs
+
+https://github.com/refined-github/sandbox/commits/4679-1
+https://github.com/refined-github/sandbox/commits/branch/with/slashes
+
+*/
diff --git a/source/features/unreleased-commits.tsx b/source/features/unreleased-commits.tsx
index b19a0f76..ecab238f 100644
--- a/source/features/unreleased-commits.tsx
+++ b/source/features/unreleased-commits.tsx
@@ -6,10 +6,11 @@ import {TagIcon} from '@primer/octicons-react';
import features from '../feature-manager.js';
import observe from '../helpers/selector-observer.js';
import * as api from '../github-helpers/api.js';
-import {buildRepoURL, cacheByRepo, getLatestVersionTag} from '../github-helpers/index.js';
+import {addAfterBranchSelector, buildRepoURL, cacheByRepo, getLatestVersionTag} from '../github-helpers/index.js';
import isDefaultBranch from '../github-helpers/is-default-branch.js';
import getDefaultBranch from '../github-helpers/get-default-branch.js';
import pluralize from '../helpers/pluralize.js';
+import {branchSelectorParent} from '../github-helpers/selectors.js';
type RepoPublishState = {
latestTag: string | false;
@@ -87,11 +88,7 @@ export const getRepoPublishState = cache.function('tag-ahead-by', async (): Prom
cacheKey: cacheByRepo,
});
-async function add(branchSelector: HTMLElement): Promise<void> {
- if (!await isDefaultBranch()) {
- return;
- }
-
+async function add(branchSelectorParent: HTMLDetailsElement): Promise<void> {
const {latestTag, aheadBy} = await getRepoPublishState();
const isAhead = aheadBy > 0;
@@ -105,10 +102,10 @@ async function add(branchSelector: HTMLElement): Promise<void> {
: pluralize(aheadBy, '$$ unreleased commit');
const label = `There are ${commitCount} since ${latestTag}`;
- // TODO: use .position-relative:has(> #branch-select-menu)
- branchSelector.closest('.position-relative')!.after(
+ addAfterBranchSelector(
+ branchSelectorParent,
<a
- className="btn ml-2 px-2 tooltipped tooltipped-ne"
+ className="btn px-2 tooltipped tooltipped-ne"
href={buildRepoURL('compare', `${latestTag}...${await getDefaultBranch()}`)}
aria-label={label}
>
@@ -119,9 +116,13 @@ async function add(branchSelector: HTMLElement): Promise<void> {
}
async function init(signal: AbortSignal): Promise<false | void> {
+ if (!await isDefaultBranch()) {
+ return false;
+ }
+
await api.expectToken();
- observe('#branch-select-menu', add, {signal});
+ observe(branchSelectorParent, add, {signal});
}
void features.add(import.meta.url, {