Skip to content

Commit 2a62edb

Browse files
authored
Add enterprise logging and fix api prefix for graphql (#6760)
* Add enterprise logging and fix api prefix for graphql * Don't show sign in badge for GitHub when signed in with Enterprise
1 parent 3316da6 commit 2a62edb

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/github/credentials.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ export class CredentialStore extends Disposable {
212212
}
213213

214214
private async doCreate(options: vscode.AuthenticationGetSessionOptions, additionalScopes: boolean = false): Promise<AuthResult> {
215-
const github = await this.initialize(AuthProvider.github, options, additionalScopes ? SCOPES_WITH_ADDITIONAL : undefined, additionalScopes);
216215
let enterprise: AuthResult | undefined;
217216
const initializeEnterprise = () => this.initialize(AuthProvider.githubEnterprise, options, additionalScopes ? SCOPES_WITH_ADDITIONAL : undefined, additionalScopes);
218217
if (hasEnterpriseUri()) {
@@ -227,8 +226,12 @@ export class CredentialStore extends Disposable {
227226
});
228227
this.context.subscriptions.push(disposable);
229228
}
229+
let github: AuthResult | undefined;
230+
if (!enterprise) {
231+
github = await this.initialize(AuthProvider.github, options, additionalScopes ? SCOPES_WITH_ADDITIONAL : undefined, additionalScopes);
232+
}
230233
return {
231-
canceled: github.canceled || !!(enterprise && enterprise.canceled)
234+
canceled: !!(github && github.canceled) || !!(enterprise && enterprise.canceled)
232235
};
233236
}
234237

@@ -438,14 +441,20 @@ export class CredentialStore extends Disposable {
438441
private async createHub(token: string, authProviderId: AuthProvider): Promise<GitHub> {
439442
let baseUrl = 'https://api.github.com';
440443
let enterpriseServerUri: vscode.Uri | undefined;
444+
Logger.appendLine(`Creating hub for ${isEnterprise(authProviderId) ? 'enterprise' : '.com'}`, CredentialStore.ID);
441445
if (isEnterprise(authProviderId)) {
442446
enterpriseServerUri = getEnterpriseUri();
443447
}
444448

445-
if (enterpriseServerUri && enterpriseServerUri.authority.endsWith('ghe.com')) {
446-
baseUrl = `${enterpriseServerUri.scheme}://api.${enterpriseServerUri.authority}`;
447-
} else if (enterpriseServerUri) {
448-
baseUrl = `${enterpriseServerUri.scheme}://${enterpriseServerUri.authority}/api/v3`;
449+
const isGhe = enterpriseServerUri?.authority.endsWith('ghe.com');
450+
451+
if (enterpriseServerUri) {
452+
Logger.appendLine(`Enterprise server authority ${enterpriseServerUri.authority}`, CredentialStore.ID);
453+
if (isGhe) {
454+
baseUrl = `${enterpriseServerUri.scheme}://api.${enterpriseServerUri.authority}`;
455+
} else {
456+
baseUrl = `${enterpriseServerUri.scheme}://${enterpriseServerUri.authority}/api/v3`;
457+
}
449458
}
450459

451460
let fetchCore: ((url: string, options: { headers?: Record<string, string> }) => any) | undefined;
@@ -470,12 +479,13 @@ export class CredentialStore extends Disposable {
470479
baseUrl: baseUrl,
471480
});
472481

473-
if (enterpriseServerUri) {
474-
baseUrl = `${enterpriseServerUri.scheme}://${enterpriseServerUri.authority}/api`;
482+
let graphQLBaseUrl = baseUrl;
483+
if (enterpriseServerUri && !isGhe) {
484+
graphQLBaseUrl = `${enterpriseServerUri.scheme}://${enterpriseServerUri.authority}/api`;
475485
}
476486

477487
const graphql = new ApolloClient({
478-
link: link(baseUrl, token || ''),
488+
link: link(graphQLBaseUrl, token || ''),
479489
cache: new InMemoryCache(),
480490
defaultOptions: {
481491
query: {

src/github/pullRequestModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
14691469
const { query, remote, schema } = await this.githubRepository.ensure();
14701470

14711471
// hard code the users for selfhost purposes
1472-
const { data } = ((await this.credentialStore.getCurrentUser(this.remote.authProviderId))?.login === 'alexr00') ? await query<PullRequestMergabilityResponse>({
1472+
const { data } = (schema.PullRequestMergeabilityMergeRequirements && ((await this.credentialStore.getCurrentUser(this.remote.authProviderId))?.login === 'alexr00')) ? await query<PullRequestMergabilityResponse>({
14731473
query: schema.PullRequestMergeabilityMergeRequirements,
14741474
variables: {
14751475
owner: remote.owner,

0 commit comments

Comments
 (0)