Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/github/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export enum PullRequestMergeability {
Behind,
}

export interface PullRequestMergeabilityResult {
mergeability: PullRequestMergeability;
conflicts?: string[];
}

export enum MergeQueueState {
AwaitingChecks,
Locked,
Expand Down
3 changes: 2 additions & 1 deletion src/github/pullRequestModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
PullRequest,
PullRequestChecks,
PullRequestMergeability,
PullRequestMergeabilityResult,
PullRequestReviewRequirement,
ReadyForReview,
ReviewEventEnum,
Expand Down Expand Up @@ -2055,7 +2056,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
/**
* Get the current mergeability of the pull request.
*/
async getMergeability(): Promise<{ mergeability: PullRequestMergeability, conflicts?: string[] }> {
async getMergeability(): Promise<PullRequestMergeabilityResult> {
try {
Logger.debug(`Fetch pull request mergeability ${this.number} - enter`, PullRequestModel.ID);
const { query, remote, schema } = await this.githubRepository.ensure();
Expand Down
5 changes: 3 additions & 2 deletions webviews/common/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getMessageHandler, MessageHandler } from './message';
import { CloseResult, DescriptionResult, OpenCommitChangesArgs, OpenLocalFileArgs } from '../../common/views';
import { IComment } from '../../src/common/comment';
import { EventType, ReviewEvent, SessionLinkInfo, TimelineEvent } from '../../src/common/timelineEvent';
import { IProjectItem, MergeMethod, PullRequestCheckStatus, ReadyForReview } from '../../src/github/interface';
import { IProjectItem, MergeMethod, PullRequestCheckStatus, PullRequestMergeabilityResult, ReadyForReview } from '../../src/github/interface';
import { CancelCodingAgentReply, ChangeAssigneesReply, ChangeBaseReply, ConvertToDraftReply, DeleteReviewResult, FileUploadCompletedMessage, MergeArguments, MergeResult, ProjectItemsReply, PullRequest, ReadyForReviewReply, SubmitReviewArgs, SubmitReviewReply, UploadFilesReply } from '../../src/github/views';

/**
Expand Down Expand Up @@ -86,7 +86,8 @@ export class PRContext {
this.updatePR(this.pr);
};

public checkMergeability = () => this.postMessage({ command: 'pr.checkMergeability' });
public checkMergeability = (): Promise<PullRequestMergeabilityResult> =>
this.postMessage({ command: 'pr.checkMergeability' });

public changeEmail = async (current: string) => {
const newEmail = await this.postMessage({ command: 'pr.change-email', args: current });
Expand Down
2 changes: 1 addition & 1 deletion webviews/components/merge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export const MergeStatusAndActions = ({ pr, isSimple }: { pr: PullRequest; isSim
useEffect(() => {
const handle = setInterval(async () => {
if (mergeable === PullRequestMergeability.Unknown) {
const newMergeability = await checkMergeability();
const { mergeability: newMergeability } = await checkMergeability();
setMergeability(newMergeability);
}
}, 3000);
Expand Down
57 changes: 57 additions & 0 deletions webviews/editorWebview/test/merge.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { default as assert } from 'assert';
import * as React from 'react';
import { cleanup, render } from 'react-testing-library';
import { createSandbox, SinonFakeTimers, SinonSandbox } from 'sinon';

import { PullRequestBuilder } from './builder/pullRequest';
import { PullRequestMergeability } from '../../../src/github/interface';
import { PRContext, default as PullRequestContext } from '../../common/context';
import { MergeStatusAndActions } from '../../components/merge';

describe('Merge status and actions', function () {
let sinon: SinonSandbox;
let clock: SinonFakeTimers & { tickAsync(milliseconds: number): Promise<number> };

beforeEach(function () {
sinon = createSandbox();
clock = sinon.useFakeTimers() as SinonFakeTimers & { tickAsync(milliseconds: number): Promise<number> };
});

afterEach(function () {
cleanup();
sinon.restore();
});

it('updates an unknown mergeability state from the polling response', async function () {
const pr = new PullRequestBuilder()
.mergeable(PullRequestMergeability.Unknown)
.hasWritePermission(false)
.build();
const context = new PRContext(pr);
const checkMergeability = sinon.stub(context, 'checkMergeability').resolves({
mergeability: PullRequestMergeability.Mergeable,
});
Comment on lines +30 to +38

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial Copilot review specifically requested a component test for MergeStatusAndActions to match the existing webview tests.

All React component tests in this repository (app.test.tsx, overview.test.tsx, and reviewSummary.test.tsx) are in webviews/editorWebview/test/. src/test/ is configured only for extension-host tests under tsconfig.test.json without JSX support, so component tests cannot be placed there.

Setting up a dedicated test runner for webview component tests is broader infrastructure work that is outside the scope of this bug fix.


const view = render(
<PullRequestContext.Provider value={context}>
<MergeStatusAndActions pr={pr} isSimple={true} />
</PullRequestContext.Provider>,
);

assert(view.queryByText('Checking if this branch can be merged...'));

await clock.tickAsync(3000);

assert(view.queryByText('This branch has no conflicts with the base branch.'));
assert.strictEqual(checkMergeability.calledOnce, true);

await clock.tickAsync(3000);

assert.strictEqual(checkMergeability.calledOnce, true);
});
});