diff --git a/src/plus/integrations/providers/gitlab.ts b/src/plus/integrations/providers/gitlab.ts index e5ac02357cb97..2265550567162 100644 --- a/src/plus/integrations/providers/gitlab.ts +++ b/src/plus/integrations/providers/gitlab.ts @@ -140,6 +140,23 @@ abstract class GitLabIntegrationBase< }); } + protected override async getProviderPullRequest( + { accessToken }: AuthenticationSession, + resource: GitLabRepositoryDescriptor, + id: string, + ): Promise { + return (await this.container.gitlab)?.getPullRequest( + this, + accessToken, + resource.owner, + resource.name, + parseInt(id, 10), + { + baseUrl: this.apiBaseUrl, + }, + ); + } + protected override async getProviderRepositoryMetadata( { accessToken }: AuthenticationSession, repo: GitLabRepositoryDescriptor, diff --git a/src/plus/integrations/providers/gitlab/gitlab.ts b/src/plus/integrations/providers/gitlab/gitlab.ts index 9303f781a1b20..276182c6a2b1e 100644 --- a/src/plus/integrations/providers/gitlab/gitlab.ts +++ b/src/plus/integrations/providers/gitlab/gitlab.ts @@ -571,6 +571,45 @@ export class GitLabApi implements Disposable { } } + @debug({ args: { 0: p => p.name, 1: '' } }) + async getPullRequest( + provider: Provider, + token: string, + owner: string, + repo: string, + id: number, + options?: { + baseUrl?: string; + }, + cancellation?: CancellationToken, + ): Promise { + const scope = getLogScope(); + + const projectId = await this.getProjectId(provider, token, owner, repo, options?.baseUrl, cancellation); + if (!projectId) return undefined; + + try { + const mr = await this.request( + provider, + token, + options?.baseUrl, + `v4/projects/${projectId}/merge_requests/${id}`, + { + method: 'GET', + }, + cancellation, + scope, + ); + if (mr == null) return undefined; + + return fromGitLabMergeRequestREST(mr, provider, { owner: owner, repo: repo }); + } catch (ex) { + if (ex instanceof RequestNotFoundError) return undefined; + + throw this.handleException(ex, provider, scope); + } + } + @debug({ args: { 0: p => p.name, 1: '' } }) async getRepositoryMetadata( provider: Provider,