Skip to content
Snippets Groups Projects
Commit 3af7942b authored by michael.minelli's avatar michael.minelli Committed by michael.minelli
Browse files

SharedGitlabManager => Add getUserById and ByUsername functions

parent cb2f81e5
Branches
No related tags found
No related merge requests found
import axios from 'axios'; import axios from 'axios';
import SharedConfig from '../config/SharedConfig'; import SharedConfig from '../config/SharedConfig';
import * as GitlabCore from '@gitbeaker/core'; import * as GitlabCore from '@gitbeaker/core';
import { GitbeakerRequestError } from '@gitbeaker/requester-utils'; import { GitbeakerRequestError } from '@gitbeaker/requester-utils';
import { Gitlab, PipelineSchema } from '@gitbeaker/rest'; import { Gitlab, PipelineSchema, UserSchema } from '@gitbeaker/rest';
import GitlabToken from '../types/Gitlab/GitlabToken'; import GitlabToken from '../types/Gitlab/GitlabToken';
import { StatusCodes } from 'http-status-codes'; import { StatusCodes } from 'http-status-codes';
class SharedGitlabManager { class SharedGitlabManager {
...@@ -50,6 +50,35 @@ class SharedGitlabManager { ...@@ -50,6 +50,35 @@ class SharedGitlabManager {
return response.data; return response.data;
} }
public async getUserById(id: number): Promise<UserSchema | undefined> {
try {
return await this.executeGitlabRequest(async () => {
const user = await this.api.Users.show(id);
return user.id === id ? user : undefined;
});
} catch ( e ) {
return undefined;
}
}
public async getUserByUsername(username: string): Promise<UserSchema | undefined> {
try {
return await this.executeGitlabRequest(async () => {
const user = await this.api.Users.all({
username: username,
maxPages: 1,
perPage : 1
});
return user.length > 0 && user[0].username === username ? user[0] : undefined;
});
} catch ( e ) {
return undefined;
}
}
async getRepositoryPipelines(repoId: number, branch: string = 'main'): Promise<Array<PipelineSchema>> { async getRepositoryPipelines(repoId: number, branch: string = 'main'): Promise<Array<PipelineSchema>> {
return await this.executeGitlabRequest(async () => { return await this.executeGitlabRequest(async () => {
return await this.api.Pipelines.all(repoId, { return await this.api.Pipelines.all(repoId, {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment