Skip to content

Commit 51d89d8

Browse files
committed
Resole merge base when we fullfill missing information for a pull request.
1 parent 10a7a45 commit 51d89d8

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

src/github/interface.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export interface IPullRequestModel {
110110
isMerged: boolean;
111111
head?: GitHubRef;
112112
base?: GitHubRef;
113+
mergeBase?: string;
113114
localBranchName?: string;
114115
userAvatar: string;
115116
userAvatarUri: vscode.Uri;
@@ -131,7 +132,6 @@ export interface IPullRequestManager {
131132
mayHaveMorePages(): boolean;
132133
getPullRequestComments(pullRequest: IPullRequestModel): Promise<Comment[]>;
133134
getPullRequestCommits(pullRequest: IPullRequestModel): Promise<Commit[]>;
134-
getPullRequestMergeBase(pullRequest: IPullRequestModel): Promise<string>;
135135
getCommitChangedFiles(pullRequest: IPullRequestModel, commit: Commit): Promise<FileChange[]>;
136136
getReviewComments(pullRequest: IPullRequestModel, reviewId: string): Promise<Comment[]>;
137137
getTimelineEvents(pullRequest: IPullRequestModel): Promise<TimelineEvent[]>;
@@ -143,7 +143,14 @@ export interface IPullRequestManager {
143143
getPullRequestChangedFiles(pullRequest: IPullRequestModel): Promise<FileChange[]>;
144144
getPullRequestRepositoryDefaultBranch(pullRequest: IPullRequestModel): Promise<string>;
145145

146-
fullfillPullRequestCommitInfo(pullRequest: IPullRequestModel): Promise<void>;
146+
/**
147+
* Fullfill information for a pull request which we can't fetch with one single api call.
148+
* 1. base. This property might not exist in search results
149+
* 2. head. This property might not exist in search results
150+
* 3. merge base. This is necessary as base might not be the commit that files in Pull Request are being compared to.
151+
* @param pullRequest
152+
*/
153+
fullfillPullRequestMissingInfo(pullRequest: IPullRequestModel): Promise<void>;
147154
updateRepositories(): Promise<void>;
148155

149156
/**

src/github/pullRequestManager.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,6 @@ export class PullRequestManager implements IPullRequestManager {
236236
}
237237
}
238238

239-
async getPullRequestMergeBase(pullRequest: IPullRequestModel): Promise<string> {
240-
try {
241-
const { remote } = await (pullRequest as PullRequestModel).githubRepository.ensure();
242-
return PullRequestGitHelper.getPullRequestMergeBase(this._repository, remote, pullRequest);
243-
} catch (e) {
244-
vscode.window.showErrorMessage(`Fetching Pull Request merge base failed: ${formatError(e)}`);
245-
return null;
246-
}
247-
}
248-
249239
async getCommitChangedFiles(pullRequest: IPullRequestModel, commit: Commit): Promise<FileChange[]> {
250240
try {
251241
const { octokit, remote } = await (pullRequest as PullRequestModel).githubRepository.ensure();
@@ -375,17 +365,22 @@ export class PullRequestManager implements IPullRequestManager {
375365
return branch;
376366
}
377367

378-
async fullfillPullRequestCommitInfo(pullRequest: IPullRequestModel): Promise<void> {
379-
if (!pullRequest.base) {
380-
// this one is from search results, which is not complete.
368+
async fullfillPullRequestMissingInfo(pullRequest: IPullRequestModel): Promise<void> {
369+
try {
381370
const { octokit, remote } = await (pullRequest as PullRequestModel).githubRepository.ensure();
382371

383-
const { data } = await octokit.pullRequests.get({
384-
owner: remote.owner,
385-
repo: remote.repositoryName,
386-
number: pullRequest.prNumber
387-
});
388-
pullRequest.update(data);
372+
if (!pullRequest.base) {
373+
const { data } = await octokit.pullRequests.get({
374+
owner: remote.owner,
375+
repo: remote.repositoryName,
376+
number: pullRequest.prNumber
377+
});
378+
pullRequest.update(data);
379+
}
380+
381+
pullRequest.mergeBase = await PullRequestGitHelper.getPullRequestMergeBase(this._repository, remote, pullRequest);
382+
} catch (e) {
383+
vscode.window.showErrorMessage(`Fetching Pull Request merge base failed: ${formatError(e)}`);
389384
}
390385
}
391386

src/view/reviewManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ export class ReviewManager implements vscode.DecorationProvider {
392392
let outdatedComments = this._comments.filter(comment => !comment.position);
393393

394394
const data = await this._prManager.getPullRequestChangedFiles(pr);
395-
await this._prManager.fullfillPullRequestCommitInfo(pr);
395+
await this._prManager.fullfillPullRequestMissingInfo(pr);
396396
let headSha = pr.head.sha;
397-
let mergeBase = await this._prManager.getPullRequestMergeBase(pr);
397+
let mergeBase = pr.mergeBase;
398398

399399
const contentChanges = await parseDiff(data, this._repository, mergeBase);
400400
this._localFileChanges = contentChanges.map(change => {

src/view/treeNodes/pullRequestNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ export class PRNode extends TreeNode {
136136

137137
const comments = await this._prManager.getPullRequestComments(this.pullRequestModel);
138138
const data = await this._prManager.getPullRequestChangedFiles(this.pullRequestModel);
139-
await this._prManager.fullfillPullRequestCommitInfo(this.pullRequestModel);
140-
let mergeBase = await this._prManager.getPullRequestMergeBase(this.pullRequestModel);
139+
await this._prManager.fullfillPullRequestMissingInfo(this.pullRequestModel);
140+
let mergeBase = this.pullRequestModel.mergeBase;
141141
const rawChanges = await parseDiff(data, this.repository, mergeBase);
142142
this._contentChanges = rawChanges.map(change => {
143143
if (change instanceof SlimFileChange) {

0 commit comments

Comments
 (0)