From c163285d0546ae88372fe2f6b325314286bdbbd7 Mon Sep 17 00:00:00 2001 From: Karl-Philipp Wulfert Date: Fri, 30 Nov 2018 11:35:55 +0100 Subject: [PATCH] refactor: consistently handle leading slash --- src/api.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/api.ts b/src/api.ts index 1f2fa2d1..dd14221b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -145,7 +145,7 @@ export class Api { } return this.makeGitLabAPIRequest( - '/projects/' + projectId + '/labels', + 'projects/' + projectId + '/labels', { data: { color: color, @@ -164,7 +164,7 @@ export class Api { * @param title Title of the milestone to create */ public createMilestone(projectId: number, title: string): Promise { - return this.makeGitLabAPIRequest('/projects/' + projectId + '/milestones?title=' + title, { + return this.makeGitLabAPIRequest('projects/' + projectId + '/milestones?title=' + title, { method: 'POST', }); } @@ -193,7 +193,7 @@ export class Api { */ public deleteLabel(projectId: number, name: string): Promise { return this.makeGitLabAPIRequest( - '/projects/' + projectId + '/labels', + 'projects/' + projectId + '/labels', { data: { name: name, @@ -227,7 +227,7 @@ export class Api { } return this.makeGitLabAPIRequest( - '/projects/' + projectId + '/labels', + 'projects/' + projectId + '/labels', { data: { color: newValues.color, @@ -282,7 +282,7 @@ export class Api { */ public getFile(projectId: number, filePath: string, commitish: string): Promise { return this.makeGitLabAPIRequest( - '/projects/' + projectId + '/repository/files/' + + 'projects/' + projectId + '/repository/files/' + encodeURIComponent(filePath).replace('.', '%2E') + '/raw?ref=' + encodeURIComponent(commitish), ); } @@ -385,7 +385,7 @@ export class Api { */ public getTags(projectId: number): Promise { return this.makeGitLabAPIRequest( - '/projects/' + projectId + '/repository/tags', + 'projects/' + projectId + '/repository/tags', ); } @@ -396,6 +396,7 @@ export class Api { * @param _options HTTP method/verb */ public async makeGitLabAPIRequest(url: string, _options?: ApiRequestOptions): Promise { + // remove leading slash url = url.replace(/^\/+/g, ''); const options: ApiRequestOptions = { @@ -483,7 +484,7 @@ export class Api { */ public protectBranch(projectId: number, branch: string): Promise { return this.makeGitLabAPIRequest( - '/projects/' + projectId + '/repository/branches/' + branch + '/protect' + + 'projects/' + projectId + '/repository/branches/' + branch + '/protect' + '?developers_can_push=false&developers_can_merge=false', { method: 'PUT',