refactor: adjust existing methods for greater scopes

This commit is contained in:
Karl-Philipp Wulfert
2019-02-05 15:45:16 +01:00
parent e4cf8dac78
commit 80fd3aa42e

View File

@@ -173,25 +173,29 @@ 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',
}); });
} }
/** /**
* Create a note/comment in an issue * Create a note (comment) in an issue/merge request
* *
* @param projectId Project ID, the issue belongs to * @param projectId Project ID, the issue belongs to
* @param issueIid IID of the issue to create the note in * @param scope Scope of the note
* @param iid IID of the issue/merge request to create the note in
* @param body Body of the note to create * @param body Body of the note to create
*/ */
public createNote(projectId: number, issueIid: number, body: string): Promise<void> { public createNote(projectId: number, scope: Scope, iid: number, body: string): Promise<void> {
return this.makeGitLabAPIRequest(`projects/${projectId}/issues/${issueIid}/notes`, { return this.makeGitLabAPIRequest(
data: { `projects/${projectId}/${scope}/${iid}/notes`,
body, {
data: {
body,
},
method: 'POST',
}, },
method: 'POST', );
});
} }
/** /**
@@ -340,30 +344,45 @@ export class Api {
* @param projectId ID of the project to get the labels for * @param projectId ID of the project to get the labels for
*/ */
public getLabels(projectId: number): Promise<Label[]> { public getLabels(projectId: number): Promise<Label[]> {
return this.makeGitLabAPIRequest( return this.makeGitLabAPIRequest(`projects/${projectId}/labels`);
'projects/' + projectId + '/labels',
);
} }
/** /**
* Get members of a group or a project * Get members of a group or a project
* *
* @param scope Scope of the ID * @param scope MembershipScope of the ID
* @param id ID of the group or project * @param id ID of the group or project
*/ */
public getMembers(scope: 'groups' | 'projects', id: number): Promise<Member[]> { public getMembers(scope: MembershipScope, id: number): Promise<Member[]> {
return this.makeGitLabAPIRequest( return this.makeGitLabAPIRequest(`${scope}/${id}/members`);
scope + '/' + id + '/members',
);
} }
/** /**
* Get merge requests for a project * Get a merge request approval
* *
* @param projectId Project ID to get merge requests for * @param projectId ID of the project the merge request belongs to
* @param mergeRequestIid IID of the merge request
*/ */
public getMergeRequestsForProject(projectId: number): Promise<MergeRequest[]> { public getMergeRequestApproval(projectId: number, mergeRequestIid: number): Promise<MergeRequestApproval> {
return this.makeGitLabAPIRequest('projects/' + projectId + '/merge_requests?state=opened'); return this.makeGitLabAPIRequest(`/projects/${projectId}/merge_requests/${mergeRequestIid}/approvals`);
}
/**
* Get merge requests of a group or a project
*
* @param scope MembershipScope of the ID
* @param id ID of the group or project
* @param state State to filter the merge requests by
*/
public getMergeRequests(scope: MembershipScope,
id: number,
state: MergeRequestState | MergeRequestState[]): Promise<MergeRequest[]> {
// join a list of states with commas
if (Array.isArray(state)) {
state = state.join(',') as MergeRequestState;
}
return this.makeGitLabAPIRequest(`${scope}/${id}/merge_requests?state=${state}`);
} }
/** /**