summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/features/bugs-tab.tsx2
-rw-r--r--source/features/clean-conversation-headers.tsx3
-rw-r--r--source/features/clone-branch.tsx3
-rw-r--r--source/features/highlight-deleted-and-added-files-in-diffs.tsx19
-rw-r--r--source/features/pr-commit-lines-changed.tsx2
-rw-r--r--source/features/remove-label-faster.tsx9
-rw-r--r--source/features/repo-age.tsx7
-rw-r--r--source/features/restore-file.tsx2
-rw-r--r--source/features/show-open-prs-of-forks.tsx4
9 files changed, 27 insertions, 24 deletions
diff --git a/source/features/bugs-tab.tsx b/source/features/bugs-tab.tsx
index f97db003..c0d3c364 100644
--- a/source/features/bugs-tab.tsx
+++ b/source/features/bugs-tab.tsx
@@ -95,7 +95,7 @@ async function init(): Promise<void | false> {
bugsCounter.textContent = numberFormatter.format(await countPromise);
} catch (error) {
bugsCounter.remove();
- throw error;
+ features.error(__filebasename, error);
}
}
diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx
index 2c89ea5b..08189264 100644
--- a/source/features/clean-conversation-headers.tsx
+++ b/source/features/clean-conversation-headers.tsx
@@ -20,8 +20,9 @@ function initIssue(): void {
}
function initPR(): void {
- observe('.gh-header-meta .flex-auto', {
+ observe('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)', {
add(byline) {
+ byline.classList.add('rgh-clean-conversation-header');
const isMerged = select.exists('#partial-discussion-header [title="Status: Merged"]');
const isSameAuthor = select('.js-discussion > .TimelineItem:first-child .author')?.textContent === select('.author', byline)!.textContent;
const baseBranch = select('.commit-ref:not(.head-ref)', byline)!;
diff --git a/source/features/clone-branch.tsx b/source/features/clone-branch.tsx
index b913f2fa..a3933287 100644
--- a/source/features/clone-branch.tsx
+++ b/source/features/clone-branch.tsx
@@ -69,7 +69,8 @@ async function cloneBranch({delegateTarget: cloneButton}: delegate.Event<MouseEv
);
}
-function init(): void | false {
+async function init(): Promise<void | false> {
+ await api.expectToken();
const deleteIcons = select.all([
'branch-filter-item-controller .octicon-trashcan', // Pre "Repository refresh" layout
'branch-filter-item .octicon-trashcan'
diff --git a/source/features/highlight-deleted-and-added-files-in-diffs.tsx b/source/features/highlight-deleted-and-added-files-in-diffs.tsx
index dc3e5cac..36d8078a 100644
--- a/source/features/highlight-deleted-and-added-files-in-diffs.tsx
+++ b/source/features/highlight-deleted-and-added-files-in-diffs.tsx
@@ -1,19 +1,21 @@
import React from 'dom-chef';
import select from 'select-dom';
-import oneTime from 'onetime';
-import {observe} from 'selector-observer';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';
+import {observe, Observer} from 'selector-observer';
import features from '.';
import {observeOneMutation} from '../helpers/simplified-element-observer';
+let observer: Observer;
+
async function loadDeferred(jumpList: Element): Promise<void> {
- const loadJumpList = (jumpList: Element) => jumpList.parentElement!.dispatchEvent(new MouseEvent('mouseover'));
- loadJumpList(jumpList);
- // The event listener might not have been attached yet, so we can try twice
- setTimeout(loadJumpList, 1000, jumpList);
+ // This event will trigger the loading, but if run too early, GitHub might not have attached the listener yet, so we try multiple times.
+ const retrier = setInterval(() => {
+ jumpList.parentElement!.dispatchEvent(new MouseEvent('mouseover'));
+ }, 100);
await observeOneMutation(jumpList);
+ clearInterval(retrier);
}
async function init(): Promise<void> {
@@ -25,7 +27,7 @@ async function init(): Promise<void> {
await loadDeferred(fileList!);
}
- observe('.file-info [href]:not(.rgh-pr-file-state)', {
+ observer = observe('.file-info [href]:not(.rgh-pr-file-state)', {
constructor: HTMLAnchorElement,
add(filename) {
filename.classList.add('rgh-pr-file-state');
@@ -65,6 +67,7 @@ void features.add({
pageDetect.isPRFile404,
pageDetect.isPRCommit404
],
- init: oneTime(init),
+ init,
+ deinit: () => observer.abort(),
waitForDomReady: false
});
diff --git a/source/features/pr-commit-lines-changed.tsx b/source/features/pr-commit-lines-changed.tsx
index f7e85cda..cf4b8661 100644
--- a/source/features/pr-commit-lines-changed.tsx
+++ b/source/features/pr-commit-lines-changed.tsx
@@ -8,7 +8,7 @@ import * as api from '../github-helpers/api';
import pluralize from '../helpers/pluralize';
import {getRepoGQL} from '../github-helpers';
-const getCommitChanges = cache.function(async (commit: string): Promise<[number, number]> => {
+const getCommitChanges = cache.function(async (commit: string): Promise<[additions: number, deletions: number]> => {
const {repository} = await api.v4(`
repository(${getRepoGQL()}) {
object(expression: "${commit}") {
diff --git a/source/features/remove-label-faster.tsx b/source/features/remove-label-faster.tsx
index d993ecfb..0a547838 100644
--- a/source/features/remove-label-faster.tsx
+++ b/source/features/remove-label-faster.tsx
@@ -4,12 +4,11 @@ import XIcon from 'octicon/x.svg';
import select from 'select-dom';
import oneTime from 'onetime';
import delegate from 'delegate-it';
-import {observe, Observer} from 'selector-observer';
import * as pageDetect from 'github-url-detection';
+import {observe, Observer} from 'selector-observer';
import features from '.';
import * as api from '../github-helpers/api';
-
import {getRepoURL, getConversationNumber} from '../github-helpers';
let observer: Observer;
@@ -68,10 +67,6 @@ async function init(): Promise<void> {
delegate(document, '.rgh-remove-label-faster:not([disabled])', 'click', removeLabelButtonClickHandler);
}
-function deinit() {
- observer.abort();
-}
-
void features.add({
id: __filebasename,
description: 'Adds one-click buttons to remove labels in conversations.',
@@ -85,5 +80,5 @@ void features.add({
canNotEditLabels
],
init,
- deinit
+ deinit: () => observer.abort()
});
diff --git a/source/features/repo-age.tsx b/source/features/repo-age.tsx
index d01b9355..f453aeea 100644
--- a/source/features/repo-age.tsx
+++ b/source/features/repo-age.tsx
@@ -16,7 +16,7 @@ const dateFormatter = new Intl.DateTimeFormat('en-US', {
day: 'numeric'
});
-const getRepoAge = async (commitSha: string, commitsCount: number): Promise<[string, string]> => {
+const getRepoAge = async (commitSha: string, commitsCount: number): Promise<[committedDate: string, resourcePath: string]> => {
const {repository} = await api.v4(`
repository(${getRepoGQL()}) {
defaultBranchRef {
@@ -42,7 +42,7 @@ const getRepoAge = async (commitSha: string, commitsCount: number): Promise<[str
return [committedDate, resourcePath];
};
-const getFirstCommit = cache.function(async (): Promise<[string, string]> => {
+const getFirstCommit = cache.function(async (): Promise<[committedDate: string, resourcePath: string]> => {
const {repository} = await api.v4(`
repository(${getRepoGQL()}) {
defaultBranchRef {
@@ -122,6 +122,9 @@ void features.add({
include: [
pageDetect.isRepoRoot
],
+ exclude: [
+ pageDetect.isEmptyRepoRoot
+ ],
waitForDomReady: false,
init
});
diff --git a/source/features/restore-file.tsx b/source/features/restore-file.tsx
index df00e659..e144fdd0 100644
--- a/source/features/restore-file.tsx
+++ b/source/features/restore-file.tsx
@@ -109,7 +109,7 @@ async function handleRestoreFileClick(event: delegate.Event<MouseEvent, HTMLButt
menuItem.closest('.file')!.remove();
} catch (error) {
showError(menuItem, 'Restore failed. See console for details');
- throw error;
+ features.error(__filebasename, error);
}
}
diff --git a/source/features/show-open-prs-of-forks.tsx b/source/features/show-open-prs-of-forks.tsx
index 0d74259d..bb646394 100644
--- a/source/features/show-open-prs-of-forks.tsx
+++ b/source/features/show-open-prs-of-forks.tsx
@@ -13,7 +13,7 @@ function getLinkCopy(count: number): string {
return pluralize(count, 'one open pull request', '$$ open pull requests');
}
-const countPRs = cache.function(async (forkedRepo: string): Promise<[number, number?]> => {
+const countPRs = cache.function(async (forkedRepo: string): Promise<[prCount: number, singlePrNumber?: number]> => {
const {search} = await api.v4(`
search(
first: 100,
@@ -46,7 +46,7 @@ const countPRs = cache.function(async (forkedRepo: string): Promise<[number, num
cacheKey: ([forkedRepo]): string => 'prs-on-forked-repo:' + forkedRepo + ':' + getRepoURL()
});
-async function getPRs(): Promise<[number, string] | []> {
+async function getPRs(): Promise<[prCount: number, url: string] | []> {
// Wait for the tab bar to be loaded
await elementReady([
'.pagehead + *', // Pre "Repository refresh" layout