diff options
Diffstat (limited to 'source/features')
22 files changed, 40 insertions, 49 deletions
diff --git a/source/features/clean-conversation-filters.tsx b/source/features/clean-conversation-filters.tsx index 9134390a..b7e4e0d7 100644 --- a/source/features/clean-conversation-filters.tsx +++ b/source/features/clean-conversation-filters.tsx @@ -5,11 +5,11 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; import * as api from '../github-helpers/api'; -import {getRepo, getRepoGQL} from '../github-helpers'; +import {getRepo} from '../github-helpers'; const hasAnyProjects = cache.function(async (): Promise<boolean> => { const {repository, organization} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { projects { totalCount } } organization(login: "${getRepo()!.owner}") { diff --git a/source/features/clone-branch.tsx b/source/features/clone-branch.tsx index 8e15d99d..2373ff86 100644 --- a/source/features/clone-branch.tsx +++ b/source/features/clone-branch.tsx @@ -10,11 +10,10 @@ import * as textFieldEdit from 'text-field-edit'; import features from '.'; import * as api from '../github-helpers/api'; import LoadingIcon from '../github-helpers/icon-loading'; -import {getRepoGQL} from '../github-helpers'; const getBranchBaseSha = async (branchName: string): Promise<string> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { ref(qualifiedName: "${branchName}") { target { oid diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index 9a8727aa..3b16758f 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -8,11 +8,11 @@ import features from '.'; import * as api from '../github-helpers/api'; import GitHubURL from '../github-helpers/github-url'; import {appendBefore} from '../helpers/dom-utils'; -import {buildRepoURL, isPermalink, getRepoGQL} from '../github-helpers'; +import {buildRepoURL, isPermalink} from '../github-helpers'; async function updateURLtoDatedSha(url: GitHubURL, date: string): Promise<void> { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { ref(qualifiedName: "${url.branch}") { target { ... on Commit { diff --git a/source/features/deep-reblame.tsx b/source/features/deep-reblame.tsx index 637ab008..08f96012 100644 --- a/source/features/deep-reblame.tsx +++ b/source/features/deep-reblame.tsx @@ -10,12 +10,11 @@ import features from '.'; import * as api from '../github-helpers/api'; import GitHubURL from '../github-helpers/github-url'; import LoadingIcon from '../github-helpers/icon-loading'; -import {getRepoGQL} from '../github-helpers'; import looseParseInt from '../helpers/loose-parse-int'; const getPullRequestBlameCommit = mem(async (commit: string, prNumber: number, currentFilename: string): Promise<string> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { file: object(expression: "${commit}:${currentFilename}") { id } @@ -64,7 +63,7 @@ async function redirectToBlameCommit(event: delegate.Event<MouseEvent, HTMLAncho blameElement.blur(); // Hide tooltip after click, it’s shown on :focus const blameHunk = blameElement.closest('.blame-hunk')!; - const prNumber = looseParseInt(select('.issue-link', blameHunk)!.textContent!); + const prNumber = looseParseInt(select('.issue-link', blameHunk)!); const prCommit = select<HTMLAnchorElement>('a.message', blameHunk)!.pathname.split('/').pop()!; const blameUrl = new GitHubURL(location.href); diff --git a/source/features/expand-all-hidden-comments.tsx b/source/features/expand-all-hidden-comments.tsx index d15c440b..9d379711 100644 --- a/source/features/expand-all-hidden-comments.tsx +++ b/source/features/expand-all-hidden-comments.tsx @@ -17,7 +17,7 @@ function handleAltClick(event: delegate.Event<MouseEvent, HTMLButtonElement>): v const form = event.delegateTarget.form!; const hiddenItemsCount = Math.min( 200, // https://github.com/sindresorhus/refined-github/issues/2931 - looseParseInt(form.textContent!) + looseParseInt(form) ); const url = new URL(form.action); diff --git a/source/features/highlight-non-default-base-branch.tsx b/source/features/highlight-non-default-base-branch.tsx index fb4dee82..40626e99 100644 --- a/source/features/highlight-non-default-base-branch.tsx +++ b/source/features/highlight-non-default-base-branch.tsx @@ -5,8 +5,8 @@ import PullRequestIcon from 'octicon/git-pull-request.svg'; import features from '.'; import * as api from '../github-helpers/api'; +import {buildRepoURL} from '../github-helpers'; import getDefaultBranch from '../github-helpers/get-default-branch'; -import {getRepoGQL, buildRepoURL} from '../github-helpers'; interface BranchInfo { baseRef: string; @@ -15,7 +15,7 @@ interface BranchInfo { function buildQuery(issueIds: string[]): string { return ` - repository(${getRepoGQL()}) { + repository() { ${issueIds.map(id => ` ${id}: pullRequest(number: ${id.replace(/\D/g, '')}) { baseRef {id} diff --git a/source/features/latest-tag-button.tsx b/source/features/latest-tag-button.tsx index a48937d4..3ddc6e8f 100644 --- a/source/features/latest-tag-button.tsx +++ b/source/features/latest-tag-button.tsx @@ -12,7 +12,7 @@ import pluralize from '../helpers/pluralize'; import GitHubURL from '../github-helpers/github-url'; import {groupButtons} from '../github-helpers/group-buttons'; import getDefaultBranch from '../github-helpers/get-default-branch'; -import {buildRepoURL, getCurrentBranch, getRepoGQL, getLatestVersionTag, getRepo} from '../github-helpers'; +import {buildRepoURL, getCurrentBranch, getLatestVersionTag, getRepo} from '../github-helpers'; interface RepoPublishState { latestTag: string | false; @@ -21,7 +21,7 @@ interface RepoPublishState { const getRepoPublishState = cache.function(async (): Promise<RepoPublishState> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { refs(first: 20, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: DESC diff --git a/source/features/list-prs-for-file.tsx b/source/features/list-prs-for-file.tsx index cc459cc1..24bcd8e7 100644 --- a/source/features/list-prs-for-file.tsx +++ b/source/features/list-prs-for-file.tsx @@ -7,7 +7,7 @@ import PullRequestIcon from 'octicon/git-pull-request.svg'; import features from '.'; import * as api from '../github-helpers/api'; import getDefaultBranch from '../github-helpers/get-default-branch'; -import {buildRepoURL, getRepoGQL, getRepo} from '../github-helpers'; +import {buildRepoURL, getRepo} from '../github-helpers'; function getPRUrl(prNumber: number): string { return buildRepoURL('pull', prNumber, 'files'); @@ -53,7 +53,7 @@ function getSingleButton(prNumber: number, _?: number, prs?: number[]): HTMLElem */ const getPrsByFile = cache.function(async (): Promise<Record<string, number[]>> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { pullRequests( first: 25, states: OPEN, diff --git a/source/features/mark-merge-commits-in-list.tsx b/source/features/mark-merge-commits-in-list.tsx index d0d9ec8a..e6cbea71 100644 --- a/source/features/mark-merge-commits-in-list.tsx +++ b/source/features/mark-merge-commits-in-list.tsx @@ -6,11 +6,10 @@ import PullRequestIcon from 'octicon/git-pull-request.svg'; import features from '.'; import * as api from '../github-helpers/api'; -import {getRepoGQL} from '../github-helpers'; const filterMergeCommits = async (commits: string[]): Promise<string[]> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { ${commits.map((commit: string) => ` ${api.escapeKey(commit)}: object(expression: "${commit}") { ... on Commit { diff --git a/source/features/next-scheduled-github-action.tsx b/source/features/next-scheduled-github-action.tsx index 30dbbb20..c7f50bce 100644 --- a/source/features/next-scheduled-github-action.tsx +++ b/source/features/next-scheduled-github-action.tsx @@ -7,11 +7,11 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; import * as api from '../github-helpers/api'; -import {getRepoGQL, getRepo} from '../github-helpers'; +import {getRepo} from '../github-helpers'; const getScheduledWorkflows = cache.function(async (): Promise<Record<string, string> | false> => { const {repository: {object: {entries: workflows}}} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { object(expression: "HEAD:.github/workflows") { ... on Tree { entries { diff --git a/source/features/pinned-issues-update-time.tsx b/source/features/pinned-issues-update-time.tsx index 0cc428e9..5bcd6844 100644 --- a/source/features/pinned-issues-update-time.tsx +++ b/source/features/pinned-issues-update-time.tsx @@ -5,8 +5,8 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; import * as api from '../github-helpers/api'; +import {getRepo} from '../github-helpers'; import looseParseInt from '../helpers/loose-parse-int'; -import {getRepoGQL, getRepo} from '../github-helpers'; interface IssueInfo { updatedAt: string; @@ -14,7 +14,7 @@ interface IssueInfo { const getLastUpdated = cache.function(async (issueNumbers: number[]): Promise<Record<string, IssueInfo>> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { ${issueNumbers.map(number => ` ${api.escapeKey(number)}: issue(number: ${number}) { updatedAt @@ -30,7 +30,7 @@ const getLastUpdated = cache.function(async (issueNumbers: number[]): Promise<Re }); function getPinnedIssueNumber(pinnedIssue: HTMLElement): number { - return looseParseInt(select('.opened-by', pinnedIssue)!.firstChild!.textContent!); + return looseParseInt(select('.opened-by', pinnedIssue)!.firstChild!); } async function init(): Promise<void | false> { diff --git a/source/features/pr-commit-lines-changed.tsx b/source/features/pr-commit-lines-changed.tsx index 9bd9379a..c5d7ac10 100644 --- a/source/features/pr-commit-lines-changed.tsx +++ b/source/features/pr-commit-lines-changed.tsx @@ -6,11 +6,10 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; 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<[additions: number, deletions: number]> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { object(expression: "${commit}") { ... on Commit { additions diff --git a/source/features/pr-filters.tsx b/source/features/pr-filters.tsx index 9c88f9a2..9fbfd10a 100644 --- a/source/features/pr-filters.tsx +++ b/source/features/pr-filters.tsx @@ -8,7 +8,7 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; import * as api from '../github-helpers/api'; -import {getRepoGQL, getRepo} from '../github-helpers'; +import {getRepo} from '../github-helpers'; const reviewsFilterSelector = '#reviews-select-menu'; @@ -64,7 +64,7 @@ function addDraftFilter({delegateTarget: reviewsFilter}: delegate.Event): void { const hasChecks = cache.function(async (): Promise<boolean> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { head: object(expression: "HEAD") { ... on Commit { history(first: 10) { diff --git a/source/features/quick-review-buttons.tsx b/source/features/quick-review-buttons.tsx index 08fd85ad..4bfee13e 100644 --- a/source/features/quick-review-buttons.tsx +++ b/source/features/quick-review-buttons.tsx @@ -74,7 +74,7 @@ function init(): false | void { // This will prevent submission when clicking "Comment" and "Request changes" without entering a comment and no other review comments are pending delegate<HTMLButtonElement>(form, 'button', 'click', ({delegateTarget: {value}}) => { - const pendingComments = looseParseInt(select('.js-reviews-toggle .js-pending-review-comment-count')!.textContent!); + const pendingComments = looseParseInt(select('.js-reviews-toggle .js-pending-review-comment-count')!); const submissionRequiresComment = pendingComments === 0 && (value === 'reject' || value === 'comment'); select('#pull_request_review_body', form)!.toggleAttribute('required', submissionRequiresComment); }); diff --git a/source/features/recently-pushed-branches-enhancements.tsx b/source/features/recently-pushed-branches-enhancements.tsx index 3c97d856..9ee72de9 100644 --- a/source/features/recently-pushed-branches-enhancements.tsx +++ b/source/features/recently-pushed-branches-enhancements.tsx @@ -7,7 +7,7 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; import {getRepo} from '../github-helpers'; -const fragmentURL = `/${getRepo()!.nameWithOwner}/show_partial?partial=tree%2Frecently_touched_branches_list`; +const fragmentURL = `/${getRepo()?.nameWithOwner!}/show_partial?partial=tree%2Frecently_touched_branches_list`; const selector = `[data-url='${fragmentURL}' i], [src='${fragmentURL}' i]`; // Ajaxed pages will load a new fragment on every ajaxed load, but we only really need the one generated on the first load diff --git a/source/features/release-download-count.tsx b/source/features/release-download-count.tsx index d65479bf..7108069c 100644 --- a/source/features/release-download-count.tsx +++ b/source/features/release-download-count.tsx @@ -6,7 +6,6 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; import * as api from '../github-helpers/api'; -import {getRepoGQL} from '../github-helpers'; interface Asset { name: string; @@ -15,7 +14,7 @@ interface Asset { type Tag = Record<string, Asset[]>; async function getAssetsForTag(tags: string[]): Promise<Tag> { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { ${tags.map(tag => ` ${api.escapeKey(tag)}: release(tagName:"${tag}") { releaseAssets(first: 100) { diff --git a/source/features/releases-tab.tsx b/source/features/releases-tab.tsx index 855fbda6..b1e7812b 100644 --- a/source/features/releases-tab.tsx +++ b/source/features/releases-tab.tsx @@ -10,7 +10,7 @@ import * as api from '../github-helpers/api'; import looseParseInt from '../helpers/loose-parse-int'; import {appendBefore} from '../helpers/dom-utils'; import {createDropdownItem} from './more-dropdown'; -import {buildRepoURL, getRepoGQL, getRepo} from '../github-helpers'; +import {buildRepoURL, getRepo} from '../github-helpers'; const getCacheKey = (): string => `releases-count:${getRepo()!.nameWithOwner}`; @@ -31,7 +31,7 @@ function parseCountFromDom(): number { async function fetchFromApi(): Promise<number> { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { refs(refPrefix: "refs/tags/") { totalCount } @@ -136,11 +136,7 @@ async function init(): Promise<false | void> { // Update "selected" tab mark if (pageDetect.isReleasesOrTags()) { - const selected = select('.reponav-item.selected'); - if (selected) { - selected.classList.remove('js-selected-navigation-item', 'selected'); - } - + select('.reponav-item.selected')?.classList.remove('js-selected-navigation-item', 'selected'); releasesTab.classList.add('js-selected-navigation-item', 'selected'); releasesTab.dataset.selectedLinks = 'repo_releases'; // Required for ajaxLoad } diff --git a/source/features/repo-age.tsx b/source/features/repo-age.tsx index aafe6712..c02f08cc 100644 --- a/source/features/repo-age.tsx +++ b/source/features/repo-age.tsx @@ -8,7 +8,7 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; import * as api from '../github-helpers/api'; -import {getRepoGQL, getRepo} from '../github-helpers'; +import {getRepo} from '../github-helpers'; const dateFormatter = new Intl.DateTimeFormat('en-US', { year: 'numeric', @@ -18,7 +18,7 @@ const dateFormatter = new Intl.DateTimeFormat('en-US', { const getRepoAge = async (commitSha: string, commitsCount: number): Promise<[committedDate: string, resourcePath: string]> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { defaultBranchRef { target { ... on Commit { @@ -44,7 +44,7 @@ const getRepoAge = async (commitSha: string, commitsCount: number): Promise<[com const getFirstCommit = cache.function(async (): Promise<[committedDate: string, resourcePath: string]> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { defaultBranchRef { target { ... on Commit { diff --git a/source/features/restore-file.tsx b/source/features/restore-file.tsx index 44b881f1..67170630 100644 --- a/source/features/restore-file.tsx +++ b/source/features/restore-file.tsx @@ -8,7 +8,7 @@ import features from '.'; import * as api from '../github-helpers/api'; import fetchDom from '../helpers/fetch-dom'; import postForm from '../helpers/post-form'; -import {getConversationNumber, getRepoGQL, getCurrentBranch, getPRHeadRepo} from '../github-helpers'; +import {getConversationNumber, getCurrentBranch, getPRHeadRepo} from '../github-helpers'; function showError(menuItem: HTMLButtonElement, error: string): void { menuItem.disabled = true; @@ -22,7 +22,7 @@ This value is not consistently available on the page (appears in `/files` but no */ const getBaseReference = onetime(async (): Promise<string> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { pullRequest(number: ${getConversationNumber()!}) { baseRefOid } @@ -33,7 +33,7 @@ const getBaseReference = onetime(async (): Promise<string> => { async function getFile(filePath: string): Promise<{isTruncated: boolean; text: string} | null> { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { file: object(expression: "${await getBaseReference()}:${filePath}") { ... on Blob { isTruncated diff --git a/source/features/show-associated-branch-prs-on-fork.tsx b/source/features/show-associated-branch-prs-on-fork.tsx index 062cc3ba..049a0fa5 100644 --- a/source/features/show-associated-branch-prs-on-fork.tsx +++ b/source/features/show-associated-branch-prs-on-fork.tsx @@ -8,7 +8,7 @@ import PullRequestIcon from 'octicon/git-pull-request.svg'; import features from '.'; import * as api from '../github-helpers/api'; -import {getRepoGQL, getRepo, upperCaseFirst} from '../github-helpers'; +import {getRepo, upperCaseFirst} from '../github-helpers'; interface PullRequest { number: number; @@ -19,7 +19,7 @@ interface PullRequest { const getPullRequestsAssociatedWithBranch = cache.function(async (): Promise<Record<string, PullRequest>> => { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { refs(refPrefix: "refs/heads/", last: 100) { nodes { name diff --git a/source/features/tags-on-commits-list.tsx b/source/features/tags-on-commits-list.tsx index 2f4ebde2..31d4cc81 100644 --- a/source/features/tags-on-commits-list.tsx +++ b/source/features/tags-on-commits-list.tsx @@ -7,7 +7,7 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; import * as api from '../github-helpers/api'; import {getCommitHash} from './mark-merge-commits-in-list'; -import {buildRepoURL, getRepoGQL, getRepo} from '../github-helpers'; +import {buildRepoURL, getRepo} from '../github-helpers'; type CommitTags = Record<string, string[]>; @@ -50,7 +50,7 @@ function isTagTarget(target: CommonTarget): target is TagTarget { async function getTags(lastCommit: string, after?: string): Promise<CommitTags> { const {repository} = await api.v4(` - repository(${getRepoGQL()}) { + repository() { refs( first: 100, refPrefix: "refs/tags/", diff --git a/source/features/user-profile-follower-badge.tsx b/source/features/user-profile-follower-badge.tsx index 0c5e3d29..2c5f5966 100644 --- a/source/features/user-profile-follower-badge.tsx +++ b/source/features/user-profile-follower-badge.tsx @@ -9,7 +9,7 @@ import * as api from '../github-helpers/api'; import {getUsername, getCleanPathname} from '../github-helpers'; const doesUserFollow = cache.function(async (userA: string, userB: string): Promise<boolean> => { - const {httpStatus} = await api.v3(`users/${userA}/following/${userB}`, { + const {httpStatus} = await api.v3(`/users/${userA}/following/${userB}`, { json: false, ignoreHTTPStatus: true }); |