Skip to content

Commit efe2a57

Browse files
Updates gkdev links for logged-in cases
1 parent 51d03bd commit efe2a57

File tree

3 files changed

+49
-54
lines changed

3 files changed

+49
-54
lines changed

src/container.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -938,14 +938,6 @@ export class Container {
938938
return uri;
939939
}
940940

941-
getGkDevExchangeUri(token: string, successPath: string, failurePath?: string): Uri {
942-
return Uri.joinPath(this.baseGkDevUri, `api/exchange/${token}`).with({
943-
query: `success=${encodeURIComponent(successPath)}${
944-
failurePath ? `&failure=${encodeURIComponent(failurePath)}` : ''
945-
}`,
946-
});
947-
}
948-
949941
generateWebGkDevUrl(path?: string): string {
950942
return this.getGkDevUri(path, '?source=gitlens').toString();
951943
}

src/plus/gk/account/subscriptionService.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@ export class SubscriptionService implements Disposable {
502502

503503
try {
504504
const exchangeToken = await this.container.accountAuthentication.getExchangeToken();
505-
void env.openExternal(this.container.getGkDevExchangeUri(exchangeToken, 'account'));
505+
await openUrl(this.container.getGkDevUri('account', `token=${exchangeToken}`).toString(true));
506506
} catch (ex) {
507507
Logger.error(ex, scope);
508-
void env.openExternal(this.container.getGkDevUri('account'));
508+
await openUrl(this.container.getGkDevUri('account').toString(true));
509509
}
510510
}
511511

@@ -762,15 +762,6 @@ export class SubscriptionService implements Disposable {
762762

763763
const hasAccount = this._subscription.account != null;
764764

765-
const successUri = await env.asExternalUri(
766-
Uri.parse(
767-
`${env.uriScheme}://${this.container.context.extension.id}/${
768-
hasAccount ? SubscriptionUpdatedUriPathPrefix : LoginUriPathPrefix
769-
}`,
770-
),
771-
);
772-
query.set('success_uri', successUri.toString(true));
773-
774765
const promoCode = getApplicablePromo(this._subscription.state)?.code;
775766
if (promoCode != null) {
776767
query.set('promoCode', promoCode);
@@ -791,11 +782,15 @@ export class SubscriptionService implements Disposable {
791782
const token = await this.container.accountAuthentication.getExchangeToken(
792783
SubscriptionUpdatedUriPathPrefix,
793784
);
794-
const purchasePath = `purchase/checkout?${query.toString()}`;
795-
if (!(await openUrl(this.container.getGkDevExchangeUri(token, purchasePath).toString(true)))) return;
796-
} else if (
797-
!(await openUrl(this.container.getGkDevUri('purchase/checkout', query.toString()).toString(true)))
798-
) {
785+
query.set('token', token);
786+
} else {
787+
const successUri = await env.asExternalUri(
788+
Uri.parse(`${env.uriScheme}://${this.container.context.extension.id}/${LoginUriPathPrefix}`),
789+
);
790+
query.set('success_uri', successUri.toString(true));
791+
}
792+
793+
if (!(await openUrl(this.container.getGkDevUri('purchase/checkout', query.toString()).toString(true)))) {
799794
return;
800795
}
801796
} catch (ex) {

src/plus/integrations/integrationService.ts

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,22 @@ export class IntegrationService implements Disposable {
151151

152152
try {
153153
const exchangeToken = await this.container.accountAuthentication.getExchangeToken();
154-
await openUrl(
155-
this.container
156-
.getGkDevExchangeUri(exchangeToken, `settings/integrations?source=gitlens`)
157-
.toString(true),
158-
);
154+
if (
155+
!(await openUrl(
156+
this.container
157+
.getGkDevUri('settings/integrations', `source=gitlens&token=${exchangeToken}`)
158+
.toString(true),
159+
))
160+
) {
161+
return;
162+
}
159163
} catch (ex) {
160164
Logger.error(ex, scope);
161-
await env.openExternal(this.container.getGkDevUri('settings/integrations', 'source=gitlens'));
165+
if (
166+
!(await openUrl(this.container.getGkDevUri('settings/integrations', 'source=gitlens').toString(true)))
167+
) {
168+
return;
169+
}
162170
}
163171
take(
164172
window.onDidChangeWindowState,
@@ -238,31 +246,31 @@ export class IntegrationService implements Disposable {
238246
}
239247
}
240248

241-
const callbackUri = await env.asExternalUri(
242-
Uri.parse(
243-
`${env.uriScheme}://${this.container.context.extension.id}/${CloudIntegrationAuthenticationUriPathPrefix}`,
244-
),
245-
);
246-
query += `&redirect_uri=${encodeURIComponent(callbackUri.toString(true))}`;
247-
248-
if (account != null) {
249-
try {
250-
const exchangeToken = await this.container.accountAuthentication.getExchangeToken();
251-
if (
252-
!(await openUrl(
253-
this.container.getGkDevExchangeUri(exchangeToken, `connect?${query}`).toString(true),
254-
))
255-
) {
256-
return false;
257-
}
258-
} catch (ex) {
259-
Logger.error(ex, scope);
260-
if (!(await openUrl(this.container.getGkDevUri('connect', query).toString(true)))) {
261-
return false;
262-
}
249+
const baseQuery = query;
250+
try {
251+
if (account != null) {
252+
const token = await this.container.accountAuthentication.getExchangeToken(
253+
CloudIntegrationAuthenticationUriPathPrefix,
254+
);
255+
256+
query += `&token=${token}`;
257+
} else {
258+
const callbackUri = await env.asExternalUri(
259+
Uri.parse(
260+
`${env.uriScheme}://${this.container.context.extension.id}/${CloudIntegrationAuthenticationUriPathPrefix}`,
261+
),
262+
);
263+
query += `&redirect_uri=${encodeURIComponent(callbackUri.toString(true))}`;
264+
}
265+
266+
if (!(await openUrl(this.container.getGkDevUri('connect', query).toString(true)))) {
267+
return false;
268+
}
269+
} catch (ex) {
270+
Logger.error(ex, scope);
271+
if (!(await openUrl(this.container.getGkDevUri('connect', baseQuery).toString(true)))) {
272+
return false;
263273
}
264-
} else if (!(await openUrl(this.container.getGkDevUri('connect', query).toString(true)))) {
265-
return false;
266274
}
267275

268276
const deferredCallback = promisifyDeferred<Uri, string | undefined>(

0 commit comments

Comments
 (0)