refactor: consistently handle leading slash

This commit is contained in:
Karl-Philipp Wulfert
2018-11-30 11:35:55 +01:00
parent b828bd89ee
commit c163285d05

View File

@@ -145,7 +145,7 @@ export class Api {
} }
return this.makeGitLabAPIRequest( return this.makeGitLabAPIRequest(
'/projects/' + projectId + '/labels', 'projects/' + projectId + '/labels',
{ {
data: { data: {
color: color, color: color,
@@ -164,7 +164,7 @@ export class Api {
* @param title Title of the milestone to create * @param title Title of the milestone to create
*/ */
public createMilestone(projectId: number, title: string): Promise<void> { public createMilestone(projectId: number, title: string): Promise<void> {
return this.makeGitLabAPIRequest('/projects/' + projectId + '/milestones?title=' + title, { return this.makeGitLabAPIRequest('projects/' + projectId + '/milestones?title=' + title, {
method: 'POST', method: 'POST',
}); });
} }
@@ -193,7 +193,7 @@ export class Api {
*/ */
public deleteLabel(projectId: number, name: string): Promise<void> { public deleteLabel(projectId: number, name: string): Promise<void> {
return this.makeGitLabAPIRequest( return this.makeGitLabAPIRequest(
'/projects/' + projectId + '/labels', 'projects/' + projectId + '/labels',
{ {
data: { data: {
name: name, name: name,
@@ -227,7 +227,7 @@ export class Api {
} }
return this.makeGitLabAPIRequest( return this.makeGitLabAPIRequest(
'/projects/' + projectId + '/labels', 'projects/' + projectId + '/labels',
{ {
data: { data: {
color: newValues.color, color: newValues.color,
@@ -282,7 +282,7 @@ export class Api {
*/ */
public getFile(projectId: number, filePath: string, commitish: string): Promise<any> { public getFile(projectId: number, filePath: string, commitish: string): Promise<any> {
return this.makeGitLabAPIRequest( return this.makeGitLabAPIRequest(
'/projects/' + projectId + '/repository/files/' + 'projects/' + projectId + '/repository/files/' +
encodeURIComponent(filePath).replace('.', '%2E') + '/raw?ref=' + encodeURIComponent(commitish), encodeURIComponent(filePath).replace('.', '%2E') + '/raw?ref=' + encodeURIComponent(commitish),
); );
} }
@@ -385,7 +385,7 @@ export class Api {
*/ */
public getTags(projectId: number): Promise<Tag[]> { public getTags(projectId: number): Promise<Tag[]> {
return this.makeGitLabAPIRequest( return this.makeGitLabAPIRequest(
'/projects/' + projectId + '/repository/tags', 'projects/' + projectId + '/repository/tags',
); );
} }
@@ -396,6 +396,7 @@ export class Api {
* @param _options HTTP method/verb * @param _options HTTP method/verb
*/ */
public async makeGitLabAPIRequest(url: string, _options?: ApiRequestOptions): Promise<any> { public async makeGitLabAPIRequest(url: string, _options?: ApiRequestOptions): Promise<any> {
// remove leading slash
url = url.replace(/^\/+/g, ''); url = url.replace(/^\/+/g, '');
const options: ApiRequestOptions = { const options: ApiRequestOptions = {
@@ -483,7 +484,7 @@ export class Api {
*/ */
public protectBranch(projectId: number, branch: string): Promise<Branch> { public protectBranch(projectId: number, branch: string): Promise<Branch> {
return this.makeGitLabAPIRequest( return this.makeGitLabAPIRequest(
'/projects/' + projectId + '/repository/branches/' + branch + '/protect' + 'projects/' + projectId + '/repository/branches/' + branch + '/protect' +
'?developers_can_push=false&developers_can_merge=false', '?developers_can_push=false&developers_can_merge=false',
{ {
method: 'PUT', method: 'PUT',