From 41f86e06f2d8c632c1e87e4a7d54869f6fb5be02 Mon Sep 17 00:00:00 2001 From: Sergei Shmakov Date: Thu, 21 Nov 2024 12:50:16 +0100 Subject: [PATCH] Shows GitLab issues (#3779) --- src/plus/integrations/providers/gitlab.ts | 32 ++++++++++++++++--- .../integrations/providers/gitlab/gitlab.ts | 2 +- src/plus/integrations/providers/models.ts | 1 + src/plus/startWork/startWork.ts | 6 +++- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/plus/integrations/providers/gitlab.ts b/src/plus/integrations/providers/gitlab.ts index e5ac02357cb97..eaff45e70f2a3 100644 --- a/src/plus/integrations/providers/gitlab.ts +++ b/src/plus/integrations/providers/gitlab.ts @@ -23,7 +23,7 @@ import type { import { HostingIntegration } from '../integration'; import { fromGitLabMergeRequestProvidersApi } from './gitlab/models'; import type { ProviderPullRequest } from './models'; -import { ProviderPullRequestReviewState, providersMetadata } from './models'; +import { ProviderPullRequestReviewState, providersMetadata, toSearchedIssue } from './models'; import type { ProvidersApi } from './providersApi'; const metadata = providersMetadata[HostingIntegrationId.GitLab]; @@ -243,11 +243,33 @@ abstract class GitLabIntegrationBase< return results; } - protected override searchProviderMyIssues( - _session: AuthenticationSession, - _repos?: GitLabRepositoryDescriptor[], + protected override async searchProviderMyIssues( + { accessToken }: AuthenticationSession, + repos?: GitLabRepositoryDescriptor[], ): Promise { - return Promise.resolve(undefined); + const api = await this.container.gitlab; + const providerApi = await this.getProvidersApi(); + + if (!api || !repos) { + return undefined; + } + + const repoIdsResult = await Promise.allSettled( + repos.map( + (r: GitLabRepositoryDescriptor): Promise => + api.getProjectId(this, accessToken, r.owner, r.name, this.apiBaseUrl, undefined), + ) ?? [], + ); + const repoInput = repoIdsResult + .map(result => (result.status === 'fulfilled' ? result.value : undefined)) + .filter((r): r is string => r != null); + const apiResult = await providerApi.getIssuesForRepos(this.id, repoInput, { + accessToken: accessToken, + }); + + return apiResult.values + .map(issue => toSearchedIssue(issue, this)) + .filter((result): result is SearchedIssue => result != null); } protected override async mergeProviderPullRequest( diff --git a/src/plus/integrations/providers/gitlab/gitlab.ts b/src/plus/integrations/providers/gitlab/gitlab.ts index 9303f781a1b20..a564e16783b2b 100644 --- a/src/plus/integrations/providers/gitlab/gitlab.ts +++ b/src/plus/integrations/providers/gitlab/gitlab.ts @@ -707,7 +707,7 @@ $search: String! } } - private getProjectId( + public getProjectId( provider: Provider, token: string, group: string, diff --git a/src/plus/integrations/providers/models.ts b/src/plus/integrations/providers/models.ts index 47160355aa4eb..3a88ca79bf184 100644 --- a/src/plus/integrations/providers/models.ts +++ b/src/plus/integrations/providers/models.ts @@ -532,6 +532,7 @@ export function toSearchedIssue( labels: issue.labels.map(label => ({ color: label.color ?? undefined, name: label.name })), commentsCount: issue.commentCount ?? undefined, thumbsUpCount: issue.upvoteCount ?? undefined, + body: issue.description ?? undefined, }, }; } diff --git a/src/plus/startWork/startWork.ts b/src/plus/startWork/startWork.ts index 1b799b74975c2..8342bbf2c5902 100644 --- a/src/plus/startWork/startWork.ts +++ b/src/plus/startWork/startWork.ts @@ -65,7 +65,11 @@ export interface StartWorkCommandArgs { source?: Sources; } -export const supportedStartWorkIntegrations = [HostingIntegrationId.GitHub, IssueIntegrationId.Jira]; +export const supportedStartWorkIntegrations = [ + HostingIntegrationId.GitHub, + HostingIntegrationId.GitLab, + IssueIntegrationId.Jira, +]; export type SupportedStartWorkIntegrationIds = (typeof supportedStartWorkIntegrations)[number]; const instanceCounter = getScopedCounter();