Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update provider apis package #43

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"watch:firefox": "yarn run set-manifest:firefox:force && yarn watch"
},
"dependencies": {
"@gitkraken/provider-apis": "0.19.1",
"@gitkraken/provider-apis": "0.22.7",
"@tanstack/query-async-storage-persister": "5.32.0",
"@tanstack/react-query": "5.32.0",
"@tanstack/react-query-persist-client": "5.32.0",
Expand Down
18 changes: 7 additions & 11 deletions src/popup/components/FocusView.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import type { GitPullRequest } from '@gitkraken/provider-apis';
import type { GitPullRequest, PullRequestBucket, PullRequestWithUniqueID } from '@gitkraken/provider-apis';
import { GitProviderUtils } from '@gitkraken/provider-apis';
import { useQueryClient } from '@tanstack/react-query';
import React, { useEffect, useMemo, useState } from 'react';
import { storage } from 'webextension-polyfill';
import { getGitKrakenDeepLinkUrl } from '../../deepLink';
import { ProviderMeta } from '../../providers';
import { GKDotDevUrl } from '../../shared';
import type {
FocusViewSupportedProvider,
GitPullRequestWithUniqueID,
PullRequestBucketWithUniqueIDs,
} from '../../types';
import type { FocusViewSupportedProvider } from '../../types';
import { useFocusViewConnectedProviders, useFocusViewDataQuery, usePullRequestDraftCountsQuery } from '../hooks';
import { ConnectAProvider } from './ConnectAProvider';
import { ExternalLink } from './ExternalLink';

type PullRequestRowProps = {
userId: string;
pullRequest: GitPullRequestWithUniqueID;
pullRequest: PullRequestWithUniqueID;
provider: FocusViewSupportedProvider;
draftCount?: number;
};
Expand Down Expand Up @@ -74,7 +70,7 @@ const PullRequestRow = ({ userId, pullRequest, provider, draftCount = 0 }: PullR
<ExternalLink
className="pr-drafts-badge text-disabled"
href={`${GKDotDevUrl}/drafts/suggested-change/${encodeURIComponent(
btoa(pullRequest.uniqueId),
btoa(pullRequest.uuid),
)}?source=browserExtension`}
title={`View code suggestion${draftCount === 1 ? '' : 's'} on gitkraken.dev`}
>
Expand All @@ -88,7 +84,7 @@ const PullRequestRow = ({ userId, pullRequest, provider, draftCount = 0 }: PullR

type BucketProps = {
userId: string;
bucket: PullRequestBucketWithUniqueIDs;
bucket: PullRequestBucket;
provider: FocusViewSupportedProvider;
prDraftCountsByEntityID?: Record<string, { count: number } | undefined>;
};
Expand All @@ -106,7 +102,7 @@ const Bucket = ({ userId, bucket, provider, prDraftCountsByEntityID }: BucketPro
userId={userId}
pullRequest={pullRequest}
provider={provider}
draftCount={prDraftCountsByEntityID?.[pullRequest.uniqueId]?.count}
draftCount={prDraftCountsByEntityID?.[pullRequest.uuid]?.count}
/>
))}
</div>
Expand Down Expand Up @@ -238,7 +234,7 @@ export const FocusView = ({ userId }: { userId: string }) => {
<Bucket
key={bucket.id}
userId={userId}
bucket={bucket as PullRequestBucketWithUniqueIDs}
bucket={bucket}
provider={selectedProvider}
prDraftCountsByEntityID={prDraftCountsQuery.data}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/popup/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ export const useFocusViewDataQuery = (
export const usePullRequestDraftCountsQuery = (
userId: string,
selectedProvider: FocusViewSupportedProvider | null | undefined,
pullRequests: { uniqueId: string }[] | undefined,
pullRequests: { uuid: string }[] | undefined,
) => {
let prUniqueIds: string[] = [];
if (selectedProvider === 'github' && pullRequests?.length) {
prUniqueIds = pullRequests.map(pr => pr.uniqueId);
prUniqueIds = pullRequests.map(pr => pr.uuid);
}

return useQuery({
Expand Down
31 changes: 20 additions & 11 deletions src/providers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { AzureDevOps, Bitbucket, GitHub, GitLab } from '@gitkraken/provider-apis';
import {
AzureDevOps,
Bitbucket,
EntityIdentifierProviderType,
EntityIdentifierUtils,
EntityType,
GitHub,
GitLab,
} from '@gitkraken/provider-apis';
import { fetchProviderToken } from './gkApi';
import type { FocusViewData, FocusViewSupportedProvider, Provider, ProviderToken } from './types';

Expand Down Expand Up @@ -27,13 +35,14 @@ const fetchGitHubFocusViewData = async (token: ProviderToken) => {
providerUser: providerUser,
pullRequests: pullRequests.map(pr => ({
...pr,
uniqueId: JSON.stringify([
token.domain ? 'githubEnterprise' : 'github',
'pr',
'1',
token.domain || '',
pr.graphQLId || pr.id,
]),
uuid: EntityIdentifierUtils.encode({
provider: token.domain
? EntityIdentifierProviderType.GithubEnterprise
: EntityIdentifierProviderType.Github,
entityType: EntityType.PullRequest,
domain: token.domain,
entityId: pr.graphQLId || pr.id,
}),
})),
};
};
Expand All @@ -50,7 +59,7 @@ const fetchGitLabFocusViewData = async (token: ProviderToken) => {
username: providerUser.username,
});

return { providerUser: providerUser, pullRequests: pullRequests.map(pr => ({ ...pr, uniqueId: '' })) };
return { providerUser: providerUser, pullRequests: pullRequests.map(pr => ({ ...pr, uuid: '' })) };
};

const fetchBitbucketFocusViewData = async (token: ProviderToken) => {
Expand All @@ -62,7 +71,7 @@ const fetchBitbucketFocusViewData = async (token: ProviderToken) => {
userId: providerUser.id,
});

return { providerUser: providerUser, pullRequests: pullRequests.map(pr => ({ ...pr, uniqueId: '' })) };
return { providerUser: providerUser, pullRequests: pullRequests.map(pr => ({ ...pr, uuid: '' })) };
};

const fetchAzureFocusViewData = async (token: ProviderToken) => {
Expand All @@ -82,7 +91,7 @@ const fetchAzureFocusViewData = async (token: ProviderToken) => {
projects: projects.map(project => ({ ...project, project: project.name })),
});

return { providerUser: providerUser, pullRequests: pullRequests.map(pr => ({ ...pr, uniqueId: '' })) };
return { providerUser: providerUser, pullRequests: pullRequests.map(pr => ({ ...pr, uuid: '' })) };
};

export const fetchFocusViewData = async (provider: FocusViewSupportedProvider): Promise<FocusViewData | null> => {
Expand Down
10 changes: 2 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Account, GitPullRequest, PullRequestBucket } from '@gitkraken/provider-apis';
import type { Account, PullRequestWithUniqueID } from '@gitkraken/provider-apis';

export interface User {
id: string;
Expand Down Expand Up @@ -31,17 +31,11 @@ export type FocusViewSupportedProvider =
| 'bitbucket'
| 'azure';

export type GitPullRequestWithUniqueID = GitPullRequest & { uniqueId: string };

export type PullRequestBucketWithUniqueIDs = Omit<PullRequestBucket, 'pullRequests'> & {
pullRequests: GitPullRequestWithUniqueID[];
};

export type PullRequestDraftCounts = Record<string, { count: number } | undefined>;

export type FocusViewData = {
providerUser: Account;
pullRequests: GitPullRequestWithUniqueID[];
pullRequests: PullRequestWithUniqueID[];
};

export interface ProviderConnection {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.44.0.tgz#961a5903c74139390478bdc808bcde3fc45ab7af"
integrity sha512-Ag+9YM4ocKQx9AarydN0KY2j0ErMHNIocPDrVo8zAE44xLTjEtz81OdR68/cydGtk6m6jDb5Za3r2useMzYmSw==

"@gitkraken/provider-apis@0.19.1":
version "0.19.1"
resolved "https://registry.npmjs.org/@gitkraken/provider-apis/-/provider-apis-0.19.1.tgz#221556650aa3a0ff6f6841bbd603ca9641c1bce7"
integrity sha512-itXor6oELNOe3szzyBhKymS7KuBoDZQMZQh0Ohyp5fnv6W97nOqCmumtOmCYjRH509MMBLp6YBUT+tzRShItKw==
"@gitkraken/provider-apis@0.22.7":
version "0.22.7"
resolved "https://registry.npmjs.org/@gitkraken/provider-apis/-/provider-apis-0.22.7.tgz#f217e1d275b578c33a38ce03564a10ee6b6b3e2c"
integrity sha512-twLjzIahStD4FkI10UxxikLLocE0r9IkX2qPjZiBfhyZbGKVdnFEdYdbZaeKOxTt87T6LyTPhdGnRLMrZfCWpA==
dependencies:
js-base64 "3.7.5"
node-fetch "2.7.0"
Expand Down
Loading