Skip to content

Commit db14f4a

Browse files
authored
Respect email in git config for PR merge (#6636)
Fixes #6593
1 parent 108970e commit db14f4a

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/github/pullRequestGitHelper.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,20 @@ export class PullRequestGitHelper {
265265
return null;
266266
}
267267

268+
static async getEmail(repository: Repository): Promise<string | undefined> {
269+
try {
270+
const email = await repository.getConfig('user.email');
271+
if (email) {
272+
return email;
273+
}
274+
const globalEmail = await repository.getGlobalConfig('user.email');
275+
return globalEmail;
276+
} catch (e) {
277+
// email config doesn't exist
278+
return undefined;
279+
}
280+
}
281+
268282
private static buildPullRequestMetadata(pullRequest: PullRequestModel) {
269283
return `${pullRequest.base.repositoryCloneUrl.owner}#${pullRequest.base.repositoryCloneUrl.repositoryName}#${pullRequest.number}`;
270284
}

src/github/pullRequestOverview.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
ReviewState,
3333
} from './interface';
3434
import { IssueOverviewPanel } from './issueOverview';
35+
import { PullRequestGitHelper } from './pullRequestGitHelper';
3536
import { PullRequestModel } from './pullRequestModel';
3637
import { PullRequestView } from './pullRequestOverviewCommon';
3738
import { getAssigneesQuickPickItems, getMilestoneFromQuickPick, getProjectFromQuickPick, pickEmail, reviewersQuickPick } from './quickPicks';
@@ -209,7 +210,9 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
209210
this._folderRepositoryManager.mergeQueueMethodForBranch(pullRequestModel.base.ref, pullRequestModel.remote.owner, pullRequestModel.remote.repositoryName),
210211
this._folderRepositoryManager.isHeadUpToDateWithBase(pullRequestModel),
211212
pullRequestModel.getMergeability(),
212-
this._folderRepositoryManager.credentialStore.getIsEmu(pullRequestModel.remote.authProviderId)])
213+
this._folderRepositoryManager.credentialStore.getIsEmu(pullRequestModel.remote.authProviderId),
214+
pullRequestModel.githubRepository.getAuthenticatedUserEmails(),
215+
PullRequestGitHelper.getEmail(this._folderRepositoryManager.repository)])
213216
.then(result => {
214217
const [
215218
pullRequest,
@@ -225,7 +228,9 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
225228
mergeQueueMethod,
226229
isBranchUpToDateWithBase,
227230
mergeability,
228-
isEmu
231+
isEmu,
232+
gitHubEmails,
233+
gitEmail
229234
] = result;
230235
if (!pullRequest) {
231236
throw new Error(
@@ -255,6 +260,8 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
255260
const isUpdateBranchWithGitHubEnabled: boolean = this.isUpdateBranchWithGitHubEnabled();
256261
const continueOnGitHub = isCrossRepository && isInCodespaces();
257262
const reviewState = this.getCurrentUserReviewState(this._existingReviewers, currentUser);
263+
const emailForCommit = isEmu ? undefined : ((gitEmail && gitHubEmails.find(email => email.toLowerCase() === gitEmail.toLowerCase())) ?? currentUser.email);
264+
258265
Logger.debug('pr.initialize', PullRequestOverviewPanel.ID);
259266
const context: Partial<PullRequest> = {
260267
number: pullRequest.number,
@@ -304,7 +311,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
304311
milestone: pullRequest.milestone,
305312
assignees: pullRequest.assignees,
306313
continueOnGitHub,
307-
emailForCommit: isEmu ? undefined : currentUser.email,
314+
emailForCommit,
308315
isAuthor: currentUser.login === pullRequest.author.login,
309316
currentUserReviewState: reviewState,
310317
isDarkTheme: vscode.window.activeColorTheme.kind === vscode.ColorThemeKind.Dark,

0 commit comments

Comments
 (0)