Skip to content

Commit

Permalink
Fix invalid email address on EMU (#5983)
Browse files Browse the repository at this point in the history
Fixes #5842
  • Loading branch information
alexr00 committed May 2, 2024
1 parent 6defd3a commit 0328241
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/github/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface GitHub {
octokit: LoggingOctokit;
graphql: LoggingApolloClient;
currentUser?: Promise<IAccount>;
isEmu?: Promise<boolean>;
}

interface AuthResult {
Expand Down Expand Up @@ -347,18 +348,33 @@ export class CredentialStore implements vscode.Disposable {
return (await this._githubAPI?.currentUser)?.login === username || (await this._githubEnterpriseAPI?.currentUser)?.login == username;
}

public async getIsEmu(authProviderId: AuthProvider): Promise<boolean> {
const github = this.getHub(authProviderId);
return !!(await github?.isEmu);
}

public getCurrentUser(authProviderId: AuthProvider): Promise<IAccount> {
const github = this.getHub(authProviderId);
const octokit = github?.octokit;
return (octokit && github?.currentUser)!;
}

private setCurrentUser(github: GitHub): void {
github.currentUser = new Promise(resolve => {
const getUser: ReturnType<typeof github.octokit.api.users.getAuthenticated> = new Promise(resolve => {
github.octokit.call(github.octokit.api.users.getAuthenticated, {}).then(result => {
resolve(result);
});
});
github.currentUser = new Promise(resolve => {
getUser.then(result => {
resolve(convertRESTUserToAccount(result.data));
});
});
github.isEmu = new Promise(resolve => {
getUser.then(result => {
resolve(result.data.plan?.name === 'emu_user');
});
});
}

private async getSession(authProviderId: AuthProvider, getAuthSessionOptions: vscode.AuthenticationGetSessionOptions, scopes: string[], requireScopes: boolean): Promise<{ session: vscode.AuthenticationSession | undefined, isNew: boolean, scopes: string[] }> {
Expand Down
8 changes: 5 additions & 3 deletions src/github/pullRequestOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
this._folderRepositoryManager.getOrgTeamsCount(pullRequestModel.githubRepository),
this._folderRepositoryManager.mergeQueueMethodForBranch(pullRequestModel.base.ref, pullRequestModel.remote.owner, pullRequestModel.remote.repositoryName),
this._folderRepositoryManager.isHeadUpToDateWithBase(pullRequestModel),
pullRequestModel.getMergeability()])
pullRequestModel.getMergeability(),
this._folderRepositoryManager.credentialStore.getIsEmu(pullRequestModel.remote.authProviderId)])
.then(result => {
const [
pullRequest,
Expand All @@ -212,7 +213,8 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
orgTeamsCount,
mergeQueueMethod,
isBranchUpToDateWithBase,
mergeability
mergeability,
isEmu
] = result;
if (!pullRequest) {
throw new Error(
Expand Down Expand Up @@ -290,7 +292,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
milestone: pullRequest.milestone,
assignees: pullRequest.assignees,
continueOnGitHub,
emailForCommit: currentUser.email,
emailForCommit: isEmu ? undefined : currentUser.email,
isAuthor: currentUser.login === pullRequest.author.login,
currentUserReviewState: reviewState,
isDarkTheme: vscode.window.activeColorTheme.kind === vscode.ColorThemeKind.Dark,
Expand Down

0 comments on commit 0328241

Please sign in to comment.