Skip to content

Commit 8aec18f

Browse files
committed
Implements pull request search by its URL on GitLab
(#3788, #3795)
1 parent a450c7d commit 8aec18f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/plus/integrations/providers/gitlab.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ abstract class GitLabIntegrationBase<
163163
});
164164
}
165165

166+
protected override async getProviderPullRequest(
167+
{ accessToken }: AuthenticationSession,
168+
resource: GitLabRepositoryDescriptor,
169+
id: string,
170+
): Promise<PullRequest | undefined> {
171+
return (await this.container.gitlab)?.getPullRequest(
172+
this,
173+
accessToken,
174+
resource.owner,
175+
resource.name,
176+
parseInt(id, 10),
177+
{
178+
baseUrl: this.apiBaseUrl,
179+
},
180+
);
181+
}
182+
166183
protected override async getProviderRepositoryMetadata(
167184
{ accessToken }: AuthenticationSession,
168185
repo: GitLabRepositoryDescriptor,

src/plus/integrations/providers/gitlab/gitlab.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,45 @@ export class GitLabApi implements Disposable {
571571
}
572572
}
573573

574+
@debug<GitLabApi['getPullRequest']>({ args: { 0: p => p.name, 1: '<token>' } })
575+
async getPullRequest(
576+
provider: Provider,
577+
token: string,
578+
owner: string,
579+
repo: string,
580+
id: number,
581+
options?: {
582+
baseUrl?: string;
583+
},
584+
cancellation?: CancellationToken,
585+
): Promise<PullRequest | undefined> {
586+
const scope = getLogScope();
587+
588+
const projectId = await this.getProjectId(provider, token, owner, repo, options?.baseUrl, cancellation);
589+
if (!projectId) return undefined;
590+
591+
try {
592+
const mr = await this.request<GitLabMergeRequestREST>(
593+
provider,
594+
token,
595+
options?.baseUrl,
596+
`v4/projects/${projectId}/merge_requests/${id}`,
597+
{
598+
method: 'GET',
599+
},
600+
cancellation,
601+
scope,
602+
);
603+
if (mr == null) return undefined;
604+
605+
return fromGitLabMergeRequestREST(mr, provider, { owner: owner, repo: repo });
606+
} catch (ex) {
607+
if (ex instanceof RequestNotFoundError) return undefined;
608+
609+
throw this.handleException(ex, provider, scope);
610+
}
611+
}
612+
574613
@debug<GitLabApi['getRepositoryMetadata']>({ args: { 0: p => p.name, 1: '<token>' } })
575614
async getRepositoryMetadata(
576615
provider: Provider,

0 commit comments

Comments
 (0)