mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2025-12-15 18:56:18 +00:00
refactor: adjust existing methods for greater scopes
This commit is contained in:
61
src/api.ts
61
src/api.ts
@@ -173,25 +173,29 @@ export class Api {
|
||||
* @param title Title of the milestone to create
|
||||
*/
|
||||
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',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
*/
|
||||
public createNote(projectId: number, issueIid: number, body: string): Promise<void> {
|
||||
return this.makeGitLabAPIRequest(`projects/${projectId}/issues/${issueIid}/notes`, {
|
||||
data: {
|
||||
body,
|
||||
public createNote(projectId: number, scope: Scope, iid: number, body: string): Promise<void> {
|
||||
return this.makeGitLabAPIRequest(
|
||||
`projects/${projectId}/${scope}/${iid}/notes`,
|
||||
{
|
||||
data: {
|
||||
body,
|
||||
},
|
||||
method: 'POST',
|
||||
},
|
||||
method: 'POST',
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -340,30 +344,45 @@ export class Api {
|
||||
* @param projectId ID of the project to get the labels for
|
||||
*/
|
||||
public getLabels(projectId: number): Promise<Label[]> {
|
||||
return this.makeGitLabAPIRequest(
|
||||
'projects/' + projectId + '/labels',
|
||||
);
|
||||
return this.makeGitLabAPIRequest(`projects/${projectId}/labels`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public getMembers(scope: 'groups' | 'projects', id: number): Promise<Member[]> {
|
||||
return this.makeGitLabAPIRequest(
|
||||
scope + '/' + id + '/members',
|
||||
);
|
||||
public getMembers(scope: MembershipScope, id: number): Promise<Member[]> {
|
||||
return this.makeGitLabAPIRequest(`${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[]> {
|
||||
return this.makeGitLabAPIRequest('projects/' + projectId + '/merge_requests?state=opened');
|
||||
public getMergeRequestApproval(projectId: number, mergeRequestIid: number): Promise<MergeRequestApproval> {
|
||||
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}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user