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

Sonar => Resolve issues

parent 7fd43ba4
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ class SharedAssignmentHelper { ...@@ -23,7 +23,7 @@ class SharedAssignmentHelper {
const pipelines = await GlobalHelper.sharedGitlabManager.getRepositoryPipelines(repositoryId, 'main'); const pipelines = await GlobalHelper.sharedGitlabManager.getRepositoryPipelines(repositoryId, 'main');
if ( pipelines.length > 0 ) { if ( pipelines.length > 0 ) {
const lastPipeline = pipelines[0]; const lastPipeline = pipelines[0];
if ( lastPipeline.status != GitlabPipelineStatus.SUCCESS.valueOf() ) { if ( lastPipeline.status !== GitlabPipelineStatus.SUCCESS.valueOf() ) {
return { return {
isPublishable: false, isPublishable: false,
lastPipeline : lastPipeline, lastPipeline : lastPipeline,
......
...@@ -23,14 +23,14 @@ class SharedGitlabManager { ...@@ -23,14 +23,14 @@ class SharedGitlabManager {
this.setToken(token); this.setToken(token);
} }
private async executeGitlabRequest<T>(request: () => Promise<T>): Promise<T> { private async executeGitlabRequest<T>(request: () => Promise<T>, refreshTokenIfNeeded: boolean = true): Promise<T> {
try { try {
return await request(); return await request();
} catch ( error ) { } catch ( error ) {
if ( this.refreshTokenFunction && error instanceof GitbeakerRequestError && error.cause?.response.status === StatusCodes.UNAUTHORIZED ) { if ( this.refreshTokenFunction && refreshTokenIfNeeded && error instanceof GitbeakerRequestError && error.cause?.response.status === StatusCodes.UNAUTHORIZED ) {
this.setToken(await this.refreshTokenFunction()); this.setToken(await this.refreshTokenFunction());
return await request(); return this.executeGitlabRequest(request, false);
} else { } else {
throw error; throw error;
} }
...@@ -84,11 +84,7 @@ class SharedGitlabManager { ...@@ -84,11 +84,7 @@ class SharedGitlabManager {
} }
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 this.executeGitlabRequest(() => this.api.Pipelines.all(repoId, { ref: branch }));
return await this.api.Pipelines.all(repoId, {
ref: branch
});
});
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment