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

GitlabManager => Add functions to get tree of a repo and for get a file

parent e907ab8c
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,9 @@ import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility';
import ApiRequest from '../types/ApiRequest';
import GitlabUser from '../shared/types/Gitlab/GitlabUser';
import GitlabRoutes from '../shared/types/Gitlab/GitlabRoutes';
import GitlabTreeFile from '../shared/types/Gitlab/GitlabTreeFile';
import parseLinkHeader from 'parse-link-header';
import GitlabFile from '../shared/types/Gitlab/GitlabFile';
class GitlabManager {
......@@ -145,6 +148,45 @@ class GitlabManager {
return response.data;
}
async getRepositoryTree(repoId: number, recursive: boolean = true, branch: string = 'main'): Promise<Array<GitlabTreeFile>> {
let address: string | undefined = this.getApiUrl(GitlabRoutes.REPOSITORY_TREE).replace('{{id}}', String(repoId));
let params: any = {
pagination: 'keyset',
recursive : recursive,
per_page : 100,
ref : branch
};
let results: Array<GitlabTreeFile> = [];
while ( params !== undefined ) {
const response = await axios.get<Array<GitlabTreeFile>>(address, {
params: params
});
results.push(...response.data);
if ( 'link' in response.headers ) {
const link = parseLinkHeader(response.headers['link']);
params = link.next;
} else {
params = undefined;
}
}
return results;
}
async getFile(repoId: number, filePath: string, branch: string = 'main'): Promise<GitlabFile> {
const response = await axios.get<GitlabFile>(this.getApiUrl(GitlabRoutes.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), {
params: {
ref: branch
}
});
return response.data;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment