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

GitlabManager => Add getRepositoryLastCommit function

parent c8590e80
No related branches found
No related tags found
No related merge requests found
......@@ -14,9 +14,16 @@ import GitlabRoute from '../shared/types/Gitlab/GitlabRoute';
import SharedConfig from '../shared/config/SharedConfig';
import GitlabProfile from '../shared/types/Gitlab/GitlabProfile';
import GitlabRelease from '../shared/types/Gitlab/GitlabRelease';
import { CommitSchema, Gitlab } from '@gitbeaker/rest';
import logger from '../shared/logging/WinstonLogger';
class GitlabManager {
readonly api = new Gitlab({
host : SharedConfig.gitlab.URL,
token: Config.gitlab.account.token
});
private getApiUrl(route: GitlabRoute): string {
return `${ SharedConfig.gitlab.apiURL }${ route }`;
}
......@@ -75,6 +82,21 @@ class GitlabManager {
return response.data;
}
async getRepositoryLastCommit(repoId: number, branch: string = 'main'): Promise<CommitSchema | undefined> {
try {
const commits = await this.api.Commits.all(repoId, {
refName : branch,
maxPages: 1,
perPage : 1
});
return commits.length > 0 ? commits[0] : undefined;
} catch ( e ) {
logger.error(e);
return undefined;
}
}
async createRepository(name: string, description: string, visibility: string, initializeWithReadme: boolean, namespace: number, sharedRunnersEnabled: boolean, wikiEnabled: boolean, import_url: string): Promise<GitlabRepository> {
const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoute.REPOSITORY_CREATE), {
name : name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment