diff options
-rw-r--r-- | source/features/ci-link.tsx | 25 | ||||
-rw-r--r-- | source/features/pr-filters.tsx | 3 | ||||
-rw-r--r-- | source/libs/utils.ts | 5 |
3 files changed, 13 insertions, 20 deletions
diff --git a/source/features/ci-link.tsx b/source/features/ci-link.tsx index 1a3cd34b..b44ce59e 100644 --- a/source/features/ci-link.tsx +++ b/source/features/ci-link.tsx @@ -1,26 +1,23 @@ import './ci-link.css'; -import onetime from 'onetime'; import features from '../libs/features'; -import {appendBefore} from '../libs/dom-utils'; -import {getRepoURL, getRepoBranch} from '../libs/utils'; import fetchDom from '../libs/fetch-dom'; +import {getRepoURL} from '../libs/utils'; +import {appendBefore} from '../libs/dom-utils'; -export const fetchCIStatus = onetime(async (): Promise<HTMLElement | void> => { - const url = `/${getRepoURL()}/commits/${getRepoBranch() ?? ''}`; - const icon = await fetchDom<HTMLElement>(url, '.commit-build-statuses'); - if (icon) { - icon.classList.add('rgh-ci-link'); - return icon; - } -}); +let callCount = 0; +export function getIcon(): Promise<HTMLElement | undefined> { + callCount += 1; + return fetchDom(`/${getRepoURL()}/commits`, '.commit-build-statuses'); +} async function init(): Promise<false | void> { - const icon = await fetchCIStatus(); + const icon = await getIcon(); if (!icon) { return false; } - if (onetime.callCount(fetchCIStatus) > 1) { + icon.classList.add('rgh-ci-link'); + if (callCount > 1) { icon.style.animation = 'none'; } @@ -35,6 +32,6 @@ features.add({ include: [ features.isRepo ], - load: features.onAjaxedPages, + load: features.nowAndOnAjaxedPages, init }); diff --git a/source/features/pr-filters.tsx b/source/features/pr-filters.tsx index 6a5df5e6..490fae35 100644 --- a/source/features/pr-filters.tsx +++ b/source/features/pr-filters.tsx @@ -2,7 +2,7 @@ import React from 'dom-chef'; import select from 'select-dom'; import checkIcon from 'octicon/check.svg'; import features from '../libs/features'; -import {fetchCIStatus} from './ci-link'; +import {getIcon as fetchCIStatus} from './ci-link'; let currentQuerySegments: string[]; @@ -48,6 +48,7 @@ function addDraftFilter(reviewsFilter: HTMLElement): void { } async function addStatusFilter(reviewsFilter: HTMLElement): Promise<void> { + // TODO: replace this with an API call const hasCI = await fetchCIStatus(); if (!hasCI) { return; diff --git a/source/libs/utils.ts b/source/libs/utils.ts index 5eedbda0..85886c97 100644 --- a/source/libs/utils.ts +++ b/source/libs/utils.ts @@ -27,11 +27,6 @@ export const getRepoPath = (): string | undefined => { return undefined; }; -export const getRepoBranch = (): string | undefined => { - const [type, branch] = location.pathname.split('/').slice(3); - return isRepo() && type === 'tree' ? branch : undefined; -}; - export const replaceBranch = (currentBranch: string, newBranch: string): string => { // `pageType` will be either `blob' or 'tree' const [pageType, ...branchAndPathParts] = getRepoPath()!.split('/'); |