diff --git a/source/features/update-pr-from-base-branch.tsx b/source/features/update-pr-from-base-branch.tsx index 5c81434f993..4a7e8f5acf1 100644 --- a/source/features/update-pr-from-base-branch.tsx +++ b/source/features/update-pr-from-base-branch.tsx @@ -86,16 +86,13 @@ async function addButton(): Promise { } function init(): void | false { - const mergeButton = select('[data-details-container=".js-merge-pr"]'); - // Only if user can merge it - if (!mergeButton) { - return false; - } - + // Button exists when the current user can merge the PR. // Button is disabled when: // - There are conflicts (there's already a native "Resolve conflicts" button) // - Draft PR (show the button anyway) - if (mergeButton.disabled && !select.exists('[action$="ready_for_review"]')) { + const canMerge = select.exists('[data-details-container=".js-merge-pr"]:not(:disabled)'); + const isDraftPR = select.exists('[action$="ready_for_review"]'); + if (!canMerge && !isDraftPR) { return false; } diff --git a/source/features/user-profile-follower-badge.tsx b/source/features/user-profile-follower-badge.tsx index 51dc87f629c..cbb5af09cc3 100644 --- a/source/features/user-profile-follower-badge.tsx +++ b/source/features/user-profile-follower-badge.tsx @@ -6,12 +6,12 @@ import features from '../libs/features'; import {getUsername, getCleanPathname} from '../libs/utils'; async function init(): Promise { - const {status} = await api.v3( + const {httpStatus} = await api.v3( `users/${getCleanPathname()}/following/${getUsername()}`, {ignoreHTTPStatus: true} ); - if (status === 204) { + if (httpStatus === 204) { select('.vcard-names-container:not(.is-placeholder)')!.after(
Follows you
); diff --git a/source/libs/api.ts b/source/libs/api.ts index 4003d51b322..a582db295a7 100644 --- a/source/libs/api.ts +++ b/source/libs/api.ts @@ -32,15 +32,17 @@ type JsonError = { message: string; }; -interface APIResponse { +interface GraphQLResponse { message?: string; -} - -interface GraphQLResponse extends APIResponse { data?: JsonObject; errors?: JsonError[]; } +interface RestResponse extends AnyObject { + httpStatus: number; + ok: boolean; +} + export const escapeKey = (value: string): string => '_' + value.replace(/[ ./-]/g, '_'); export class RefinedGitHubAPIError extends Error { @@ -82,7 +84,7 @@ const v4defaults: GHGraphQLApiOptions = { export const v3 = mem(async ( query: string, options: GHRestApiOptions = v3defaults -): Promise => { +): Promise => { const {ignoreHTTPStatus, method, body, headers} = {...v3defaults, ...options}; const {personalToken} = await settings; @@ -103,7 +105,7 @@ export const v3 = mem(async ( if (response.ok || ignoreHTTPStatus) { return Object.assign(apiResponse, { - status: response.status, + httpStatus: response.status, ok: response.ok }); }