Skip to content

Commit

Permalink
Fix update-pr-from-base-branch feature (#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Nov 11, 2019
1 parent 3891c51 commit 45e4323
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
11 changes: 4 additions & 7 deletions source/features/update-pr-from-base-branch.tsx
Expand Up @@ -86,16 +86,13 @@ async function addButton(): Promise<void> {
}

function init(): void | false {
const mergeButton = select<HTMLButtonElement>('[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;
}

Expand Down
4 changes: 2 additions & 2 deletions source/features/user-profile-follower-badge.tsx
Expand Up @@ -6,12 +6,12 @@ import features from '../libs/features';
import {getUsername, getCleanPathname} from '../libs/utils';

async function init(): Promise<void> {
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(
<div className="rgh-follower-badge">Follows you</div>
);
Expand Down
14 changes: 8 additions & 6 deletions source/libs/api.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -82,7 +84,7 @@ const v4defaults: GHGraphQLApiOptions = {
export const v3 = mem(async (
query: string,
options: GHRestApiOptions = v3defaults
): Promise<AnyObject> => {
): Promise<RestResponse> => {
const {ignoreHTTPStatus, method, body, headers} = {...v3defaults, ...options};
const {personalToken} = await settings;

Expand All @@ -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
});
}
Expand Down

0 comments on commit 45e4323

Please sign in to comment.