GitLab API Venturial
npm install @venturialstd/gitlabbash
npm install @venturialstd/gitlab
or
yarn add @venturialstd/gitlab
`
---
Basic Usage
$3
You can create a client anywhere in your project and pass the host and token:
`ts
import { Injectable } from "@nestjs/common";
import { GitlabClient, GitlabProjectService } from "@venturialstd/gitlab";
import { HttpService } from "@nestjs/axios";
@Injectable()
export class GitlabClientProvider {
private client: GitlabClient;
private projectService: GitlabProjectService;
constructor(private readonly httpService: HttpService) {}
private async getClient(host: string, token: string) {
if (!this.client) {
this.client = new GitlabClient(this.httpService, { host, token });
}
return this.client;
}
async getProjectService() {
if (!this.projectService)
this.projectService = new GitlabProjectService(await this.getClient());
return this.projectService;
}
}
`
---
$3
`ts
import { Injectable } from "@nestjs/common";
import { GitlabClientProvider } from "./gitlab-client.provider";
import { GitlabClient } from "@venturialstd/gitlab-sdk";
@Injectable()
export class HarveyGitlabService {
constructor(private readonly gitlabClientProvider: GitlabClientProvider) {}
async reviewMergeRequest(projectName: string) {
const gitlabProjectService =
await this.gitlabClientProvider.getProjectService();
const mergeRequests =
await gitlabProjectService.getMergeRequests(projectId);
return mergeRequests;
}
}
`
---
API
$3
| Method | Parameters | Description |
| ------------------------------------------------------------ | ---------------------------------------------------- | -------------------------------------------- |
| getMergeRequests(projectId: string) | projectId | Returns a list of open merge requests |
| getMergeRequestDiff(projectId: string, mrId: string) | projectId, mrId | Returns the raw diff of a merge request |
| getFile(projectId: string, filePath: string, ref?: string) | projectId, filePath, optional ref (default "main") | Returns the raw content of a repository file |
---
Notes
- Requires @nestjs/axios and rxjs` as peer dependencies.