Skip to content

Commit

Permalink
Consolidates to *.gitkraken.dev URLs for apis
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Dec 20, 2024
1 parent 32aab62 commit a7ef866
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 63 deletions.
34 changes: 17 additions & 17 deletions src/plus/drafts/draftsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Container } from '../../container';
import type { GitCommit } from '../../git/models/commit';
import type { PullRequest } from '../../git/models/pullRequest';
import { isRepository, Repository } from '../../git/models/repository';
import { isSha, isUncommitted , shortenRevision } from '../../git/models/revision.utils';
import { isSha, isUncommitted, shortenRevision } from '../../git/models/revision.utils';
import type { GitUser } from '../../git/models/user';
import { getRemoteProviderMatcher } from '../../git/remotes/remoteProviders';
import type {
Expand Down Expand Up @@ -123,7 +123,7 @@ export class DraftService implements Disposable {
}

// POST v1/drafts
const createDraftRsp = await this.connection.fetchGkDevApi('v1/drafts', {
const createDraftRsp = await this.connection.fetchGkApi('v1/drafts', {
method: 'POST',
body: JSON.stringify({
type: type,
Expand All @@ -143,7 +143,7 @@ export class DraftService implements Disposable {
type ChangesetResult = { data: DraftChangesetCreateResponse };

// POST /v1/drafts/:draftId/changesets
const createChangesetRsp = await this.connection.fetchGkDevApi(`v1/drafts/${draftId}/changesets`, {
const createChangesetRsp = await this.connection.fetchGkApi(`v1/drafts/${draftId}/changesets`, {
method: 'POST',
body: JSON.stringify({
// parentChangesetId: null,
Expand Down Expand Up @@ -205,7 +205,7 @@ export class DraftService implements Disposable {
}

// POST /v1/drafts/:draftId/publish
const publishRsp = await this.connection.fetchGkDevApi(`v1/drafts/${draftId}/publish`, {
const publishRsp = await this.connection.fetchGkApi(`v1/drafts/${draftId}/publish`, {
method: 'POST',
headers: providerAuthHeader,
body: prEntityIdBody != null ? JSON.stringify(prEntityIdBody) : undefined,
Expand All @@ -216,7 +216,7 @@ export class DraftService implements Disposable {

type Result = { data: DraftResponse };

const draftRsp = await this.connection.fetchGkDevApi(`v1/drafts/${draftId}`, {
const draftRsp = await this.connection.fetchGkApi(`v1/drafts/${draftId}`, {
method: 'GET',
headers: providerAuthHeader,
});
Expand Down Expand Up @@ -324,7 +324,7 @@ export class DraftService implements Disposable {

@log()
async deleteDraft(id: string): Promise<void> {
await this.connection.fetchGkDevApi(`v1/drafts/${id}`, { method: 'DELETE' });
await this.connection.fetchGkApi(`v1/drafts/${id}`, { method: 'DELETE' });
}

@log<DraftService['archiveDraft']>({ args: { 1: opts => JSON.stringify({ ...opts, providerAuth: undefined }) } })
Expand All @@ -347,7 +347,7 @@ export class DraftService implements Disposable {
};
}

const rsp = await this.connection.fetchGkDevApi(`v1/drafts/${draft.id}/archive`, {
const rsp = await this.connection.fetchGkApi(`v1/drafts/${draft.id}/archive`, {
method: 'POST',
body:
options?.archiveReason != null
Expand Down Expand Up @@ -381,7 +381,7 @@ export class DraftService implements Disposable {
}

const [rspResult, changesetsResult] = await Promise.allSettled([
this.connection.fetchGkDevApi(`v1/drafts/${id}`, { method: 'GET', headers: headers }),
this.connection.fetchGkApi(`v1/drafts/${id}`, { method: 'GET', headers: headers }),
this.getChangesets(id),
]);

Expand Down Expand Up @@ -458,7 +458,7 @@ export class DraftService implements Disposable {
};
}

const rsp = await this.connection.fetchGkDevApi(
const rsp = await this.connection.fetchGkApi(
'/v1/drafts',
{
method: 'GET',
Expand Down Expand Up @@ -500,7 +500,7 @@ export class DraftService implements Disposable {
type Result = { data: DraftChangesetResponse[] };

try {
const rsp = await this.connection.fetchGkDevApi(`/v1/drafts/${id}/changesets`, { method: 'GET' });
const rsp = await this.connection.fetchGkApi(`/v1/drafts/${id}/changesets`, { method: 'GET' });
if (!rsp.ok) {
await handleBadDraftResponse(`Unable to open changesets for draft '${id}'`, rsp, scope);
}
Expand Down Expand Up @@ -538,7 +538,7 @@ export class DraftService implements Disposable {
type Result = { data: DraftPatchResponse };

// GET /v1/patches/:patchId
const rsp = await this.connection.fetchGkDevApi(`/v1/patches/${id}`, { method: 'GET' });
const rsp = await this.connection.fetchGkApi(`/v1/patches/${id}`, { method: 'GET' });

if (!rsp.ok) {
await handleBadDraftResponse(`Unable to open patch '${id}'`, rsp, scope);
Expand Down Expand Up @@ -610,7 +610,7 @@ export class DraftService implements Disposable {
type Result = { data: Draft };

try {
const rsp = await this.connection.fetchGkDevApi(`/v1/drafts/${id}`, {
const rsp = await this.connection.fetchGkApi(`/v1/drafts/${id}`, {
method: 'PATCH',
body: JSON.stringify({ visibility: visibility }),
});
Expand All @@ -636,7 +636,7 @@ export class DraftService implements Disposable {
type Result = { data: DraftUser[] };

try {
const rsp = await this.connection.fetchGkDevApi(`/v1/drafts/${id}/users`, { method: 'GET' });
const rsp = await this.connection.fetchGkApi(`/v1/drafts/${id}/users`, { method: 'GET' });

if (rsp?.ok === false) {
await handleBadDraftResponse(`Unable to get users for draft '${id}'`, rsp, scope);
Expand Down Expand Up @@ -664,7 +664,7 @@ export class DraftService implements Disposable {
throw new Error('No changes found');
}

const rsp = await this.connection.fetchGkDevApi(`/v1/drafts/${id}/users`, {
const rsp = await this.connection.fetchGkApi(`/v1/drafts/${id}/users`, {
method: 'POST',
body: JSON.stringify({
id: id,
Expand All @@ -690,7 +690,7 @@ export class DraftService implements Disposable {
async removeDraftUser(id: string, userId: DraftUser['userId']): Promise<boolean> {
const scope = getLogScope();
try {
const rsp = await this.connection.fetchGkDevApi(`/v1/drafts/${id}/users/${userId}`, { method: 'DELETE' });
const rsp = await this.connection.fetchGkApi(`/v1/drafts/${id}/users/${userId}`, { method: 'DELETE' });

if (rsp?.ok === false) {
await handleBadDraftResponse(`Unable to update user ${userId} for draft '${id}'`, rsp, scope);
Expand Down Expand Up @@ -718,7 +718,7 @@ export class DraftService implements Disposable {
async getRepositoryIdentity(draftId: Draft['id'], repoId: GkRepositoryId): Promise<RepositoryIdentity> {
type Result = { data: RepositoryIdentityResponse };

const rsp = await this.connection.fetchGkDevApi(`/v1/drafts/${draftId}/git-repositories/${repoId}`, {
const rsp = await this.connection.fetchGkApi(`/v1/drafts/${draftId}/git-repositories/${repoId}`, {
method: 'GET',
});
const data = ((await rsp.json()) as Result).data;
Expand Down Expand Up @@ -862,7 +862,7 @@ export class DraftService implements Disposable {
});

try {
const rsp = await this.connection.fetchGkDevApi(
const rsp = await this.connection.fetchGkApi(
'v1/drafts/counts',
{
method: 'POST',
Expand Down
6 changes: 3 additions & 3 deletions src/plus/gk/account/authenticationConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class AuthenticationConnection implements Disposable {

let rsp: Response;
try {
rsp = await this.connection.fetchApi('user', undefined, { token: token });
rsp = await this.connection.fetchGkApi('user', undefined, { token: token });
} catch (ex) {
Logger.error(ex, scope);
throw ex;
Expand Down Expand Up @@ -195,7 +195,7 @@ export class AuthenticationConnection implements Disposable {
}
}

const rsp = await this.connection.fetchGkDevApi(
const rsp = await this.connection.fetchGkApi(
'oauth/access_token',
{
method: 'POST',
Expand Down Expand Up @@ -258,7 +258,7 @@ export class AuthenticationConnection implements Disposable {
)
: undefined;

const rsp = await this.connection.fetchGkDevApi('v1/login/auth-exchange', {
const rsp = await this.connection.fetchGkApi('v1/login/auth-exchange', {
method: 'POST',
body: JSON.stringify({
source: 'gitlens',
Expand Down
6 changes: 3 additions & 3 deletions src/plus/gk/account/organizationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class OrganizationService implements Disposable {

let rsp;
try {
rsp = await this.connection.fetchApi(
rsp = await this.connection.fetchGkApi(
'user/organizations-light',
{
method: 'GET',
Expand Down Expand Up @@ -152,7 +152,7 @@ export class OrganizationService implements Disposable {
options?: { force?: boolean },
): Promise<FullOrganization | undefined> {
if (!this._fullOrganizations?.has(id) || options?.force === true) {
const rsp = await this.connection.fetchApi(`organization/${id}`, { method: 'GET' });
const rsp = await this.connection.fetchGkApi(`organization/${id}`, { method: 'GET' });
if (!rsp.ok) {
Logger.error(
'',
Expand Down Expand Up @@ -213,7 +213,7 @@ export class OrganizationService implements Disposable {
if (id == null) return undefined;

if (!this._organizationSettings?.has(id) || options?.force === true) {
const rsp = await this.connection.fetchApi(
const rsp = await this.connection.fetchGkApi(
`v1/organizations/settings`,
{ method: 'GET' },
{ organizationId: id },
Expand Down
6 changes: 3 additions & 3 deletions src/plus/gk/account/subscriptionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export class SubscriptionService implements Disposable {
if (session == null) return;

try {
const rsp = await this.connection.fetchApi('user/reactivate-trial', {
const rsp = await this.connection.fetchGkApi('user/reactivate-trial', {
method: 'POST',
body: JSON.stringify({ client: 'gitlens' }),
});
Expand Down Expand Up @@ -735,7 +735,7 @@ export class SubscriptionService implements Disposable {
if (session == null) return false;

try {
const rsp = await this.connection.fetchApi(
const rsp = await this.connection.fetchGkApi(
'resend-email',
{
method: 'POST',
Expand Down Expand Up @@ -1041,7 +1041,7 @@ export class SubscriptionService implements Disposable {
previewExpiresOn: this._subscription.previewTrial?.expiresOn,
};

const rsp = await this.connection.fetchApi(
const rsp = await this.connection.fetchGkApi(
'gitlens/checkin',
{
method: 'POST',
Expand Down
35 changes: 7 additions & 28 deletions src/plus/gk/serverConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,7 @@ export class ServerConnection implements Disposable {
dispose() {}

@memoize()
private get baseApiUri(): Uri {
if (this.container.env === 'staging') {
return Uri.parse('https://stagingapi.gitkraken.com');
}

if (this.container.env === 'dev') {
return Uri.parse('https://devapi.gitkraken.com');
}

return Uri.parse('https://api.gitkraken.com');
}

getApiUrl(...pathSegments: string[]) {
return Uri.joinPath(this.baseApiUri, ...pathSegments).toString();
}

@memoize()
private get baseGkDevApiUri(): Uri {
private get baseGkApiUri(): Uri {
if (this.container.env === 'staging') {
return Uri.parse('https://staging-api.gitkraken.dev');
}
Expand All @@ -75,8 +58,8 @@ export class ServerConnection implements Disposable {
return Uri.parse('https://api.gitkraken.dev');
}

getGkDevApiUrl(...pathSegments: string[]) {
return Uri.joinPath(this.baseGkDevApiUri, ...pathSegments).toString();
getGkApiUrl(...pathSegments: string[]) {
return Uri.joinPath(this.baseGkApiUri, ...pathSegments).toString();
}

@memoize()
Expand Down Expand Up @@ -133,12 +116,12 @@ export class ServerConnection implements Disposable {
}
}

async fetchApi(path: string, init?: RequestInit, options?: GKFetchOptions): Promise<Response> {
return this.gkFetch(this.getApiUrl(path), init, options);
async fetchGkApi(path: string, init?: RequestInit, options?: GKFetchOptions): Promise<Response> {
return this.gkFetch(this.getGkApiUrl(path), init, options);
}

async fetchApiGraphQL(path: string, request: GraphQLRequest, init?: RequestInit, options?: GKFetchOptions) {
return this.fetchApi(
async fetchGkApiGraphQL(path: string, request: GraphQLRequest, init?: RequestInit, options?: GKFetchOptions) {
return this.fetchGkApi(
path,
{
method: 'POST',
Expand All @@ -149,10 +132,6 @@ export class ServerConnection implements Disposable {
);
}

async fetchGkDevApi(path: string, init?: RequestInit, options?: GKFetchOptions): Promise<Response> {
return this.gkFetch(this.getGkDevApiUrl(path), init, options);
}

private async gkFetch(url: RequestInfo, init?: RequestInit, options?: GKFetchOptions): Promise<Response> {
if (this.requestsAreBlocked) {
throw new RequestsAreBlockedTemporarilyError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CloudIntegrationService {
async getConnections(): Promise<CloudIntegrationConnection[] | undefined> {
const scope = getLogScope();

const providersRsp = await this.connection.fetchGkDevApi(
const providersRsp = await this.connection.fetchGkApi(
'v1/provider-tokens',
{ method: 'GET' },
{ organizationId: false },
Expand Down Expand Up @@ -59,7 +59,7 @@ export class CloudIntegrationService {
}
: { method: 'GET' };

const tokenRsp = await this.connection.fetchGkDevApi(
const tokenRsp = await this.connection.fetchGkApi(
`v1/provider-tokens/${cloudIntegrationType}${refresh ? '/refresh' : ''}`,
reqInitOptions,
{ organizationId: false },
Expand Down Expand Up @@ -100,7 +100,7 @@ export class CloudIntegrationService {
return false;
}

const tokenRsp = await this.connection.fetchGkDevApi(
const tokenRsp = await this.connection.fetchGkApi(
`v1/provider-tokens/${cloudIntegrationType}`,
{ method: 'DELETE' },
{ organizationId: false },
Expand Down
8 changes: 4 additions & 4 deletions src/plus/launchpad/enrichmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class EnrichmentService implements Disposable {
const scope = getLogScope();

try {
const rsp = await this.connection.fetchGkDevApi(`v1/enrich-items/${id}`, { method: 'DELETE' });
const rsp = await this.connection.fetchGkApi(`v1/enrich-items/${id}`, { method: 'DELETE' });

if (!rsp.ok) throw new Error(`Unable to ${context} item '${id}': (${rsp.status}) ${rsp.statusText}`);
} catch (ex) {
Expand All @@ -83,7 +83,7 @@ export class EnrichmentService implements Disposable {
try {
type Result = { data: EnrichedItemResponse[] };

const rsp = await this.connection.fetchGkDevApi('v1/enrich-items', { method: 'GET' });
const rsp = await this.connection.fetchGkApi('v1/enrich-items', { method: 'GET' });
if (cancellation?.isCancellationRequested) throw new CancellationError();

const result = (await rsp.json()) as Result;
Expand Down Expand Up @@ -132,7 +132,7 @@ export class EnrichmentService implements Disposable {
entityUrl: item.url,
};

const rsp = await this.connection.fetchGkDevApi('v1/enrich-items/pin', {
const rsp = await this.connection.fetchGkApi('v1/enrich-items/pin', {
method: 'POST',
body: JSON.stringify(rq),
});
Expand Down Expand Up @@ -183,7 +183,7 @@ export class EnrichmentService implements Disposable {
rq.expiresAt = item.expiresAt;
}

const rsp = await this.connection.fetchGkDevApi('v1/enrich-items/snooze', {
const rsp = await this.connection.fetchGkApi('v1/enrich-items/snooze', {
method: 'POST',
body: JSON.stringify(rq),
});
Expand Down
2 changes: 1 addition & 1 deletion src/plus/workspaces/workspacesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,6 @@ export class WorkspacesApi {
}

private async fetch(request: GraphQLRequest, init?: RequestInit) {
return this.connection.fetchApiGraphQL('api/projects/graphql', request, init);
return this.connection.fetchGkApiGraphQL('api/projects/graphql', request, init);
}
}
4 changes: 3 additions & 1 deletion src/webviews/home/homeWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import type { StartWorkCommandArgs } from '../../plus/startWork/startWork';
import type { ShowInCommitGraphCommandArgs } from '../../plus/webviews/graph/protocol';
import type { Change } from '../../plus/webviews/patchDetails/protocol';
import { showRepositoryPicker } from '../../quickpicks/repositoryPicker';
import { debug } from '../../system/decorators/log';
import type { Deferrable } from '../../system/function';
import { debounce } from '../../system/function';
import { filterMap } from '../../system/iterable';
Expand Down Expand Up @@ -742,7 +743,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe

private subscribeToRepository(repo: Repository): Disposable {
return Disposable.from(
// TODO: advanced confiugration for the watchFileSystem timing
// TODO: advanced configuration for the watchFileSystem timing
repo.watchFileSystem(1000),
repo.onDidChangeFileSystem(() => this.onOverviewRepoChanged('wip')),
repo.onDidChange(e => {
Expand All @@ -764,6 +765,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
);
}

@debug()
private onOverviewRepoChanged(scope: 'repo' | 'wip') {
if (this._invalidateOverview !== 'repo') {
this._invalidateOverview = scope;
Expand Down

0 comments on commit a7ef866

Please sign in to comment.