Skip to content

Commit

Permalink
Implements pull request search by its URL on GitLab
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Nov 25, 2024
1 parent e19e0b0 commit 15120ab
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/plus/integrations/providers/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ abstract class GitLabIntegrationBase<
});
}

protected override async getProviderPullRequest(
{ accessToken }: AuthenticationSession,
resource: GitLabRepositoryDescriptor,
id: string,
): Promise<PullRequest | undefined> {
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,
Expand Down
39 changes: 39 additions & 0 deletions src/plus/integrations/providers/gitlab/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,45 @@ export class GitLabApi implements Disposable {
}
}

@debug<GitLabApi['getPullRequest']>({ args: { 0: p => p.name, 1: '<token>' } })
async getPullRequest(
provider: Provider,
token: string,
owner: string,
repo: string,
id: number,
options?: {
baseUrl?: string;
},
cancellation?: CancellationToken,
): Promise<PullRequest | undefined> {
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<GitLabMergeRequestREST>(
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<GitLabApi['getRepositoryMetadata']>({ args: { 0: p => p.name, 1: '<token>' } })
async getRepositoryMetadata(
provider: Provider,
Expand Down

0 comments on commit 15120ab

Please sign in to comment.