mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
refactor: use stricter types and backticks for strings
This commit is contained in:
64
src/api.ts
64
src/api.ts
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 StApps
|
* Copyright (C) 2018, 2019 StApps
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the Free
|
* under the terms of the GNU General Public License as published by the Free
|
||||||
* Software Foundation, version 3.
|
* Software Foundation, version 3.
|
||||||
@@ -19,15 +19,23 @@ import {
|
|||||||
Branch,
|
Branch,
|
||||||
Group,
|
Group,
|
||||||
Issue,
|
Issue,
|
||||||
|
IssueState,
|
||||||
Label,
|
Label,
|
||||||
Member,
|
Member,
|
||||||
|
MembershipScope,
|
||||||
MergeRequest,
|
MergeRequest,
|
||||||
|
MergeRequestApproval,
|
||||||
|
MergeRequestState,
|
||||||
Milestone,
|
Milestone,
|
||||||
Project,
|
Project,
|
||||||
|
Scope,
|
||||||
Tag,
|
Tag,
|
||||||
TreeFile,
|
TreeFile,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instance of logger
|
||||||
|
*/
|
||||||
export const logger = new Logger();
|
export const logger = new Logger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,8 +67,8 @@ export interface ApiRequestOptions {
|
|||||||
*/
|
*/
|
||||||
export interface ApiGetIssuesOptions {
|
export interface ApiGetIssuesOptions {
|
||||||
groupId?: number;
|
groupId?: number;
|
||||||
milestone?: 'Meeting' | 'Backlog' | 'No Milestone';
|
milestone?: 'Backlog' | 'No Milestone';
|
||||||
state?: 'opened' | 'closed';
|
state?: IssueState;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,17 +110,17 @@ export class Api {
|
|||||||
/**
|
/**
|
||||||
* Add member to a group or a project
|
* Add member to 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
|
||||||
* @param userId ID of the user
|
* @param userId ID of the user
|
||||||
* @param accessLevel Access level for the new member in the scope
|
* @param accessLevel Access level for the new member in the scope
|
||||||
*/
|
*/
|
||||||
public addMember(scope: 'groups' | 'projects',
|
public addMember(scope: MembershipScope,
|
||||||
id: number,
|
id: number,
|
||||||
userId: number,
|
userId: number,
|
||||||
accessLevel: AccessLevel): Promise<Member> {
|
accessLevel: AccessLevel): Promise<Member> {
|
||||||
return this.makeGitLabAPIRequest(
|
return this.makeGitLabAPIRequest(
|
||||||
scope + '/' + id + '/members',
|
`${scope}/${id}/members`,
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
access_level: accessLevel,
|
access_level: accessLevel,
|
||||||
@@ -132,7 +140,7 @@ export class Api {
|
|||||||
*/
|
*/
|
||||||
public createIssue(projectId: number, title: string, description: string): Promise<Issue> {
|
public createIssue(projectId: number, title: string, description: string): Promise<Issue> {
|
||||||
return this.makeGitLabAPIRequest(
|
return this.makeGitLabAPIRequest(
|
||||||
'projects/' + projectId + '/issues',
|
`projects/${projectId}/issues`,
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
description: description,
|
description: description,
|
||||||
@@ -157,7 +165,7 @@ export class Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.makeGitLabAPIRequest(
|
return this.makeGitLabAPIRequest(
|
||||||
'projects/' + projectId + '/labels',
|
`projects/${projectId}/labels`,
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
color: color,
|
color: color,
|
||||||
@@ -215,12 +223,12 @@ export class Api {
|
|||||||
/**
|
/**
|
||||||
* Delete a member from a group or a project
|
* Delete a member from 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
|
||||||
* @param userId ID of the user
|
* @param userId ID of the user
|
||||||
*/
|
*/
|
||||||
public deleteMember(scope: 'groups' | 'projects', id: number, userId: number): Promise<void> {
|
public deleteMember(scope: MembershipScope, id: number, userId: number): Promise<void> {
|
||||||
return this.makeGitLabAPIRequest(scope + '/' + id + '/members/' + userId, {method: 'DELETE'});
|
return this.makeGitLabAPIRequest(`${scope}/${id}/members/${userId}`, {method: 'DELETE'});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -236,7 +244,7 @@ export class Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.makeGitLabAPIRequest(
|
return this.makeGitLabAPIRequest(
|
||||||
'projects/' + projectId + '/labels',
|
`projects/${projectId}/labels`,
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
color: newValues.color,
|
color: newValues.color,
|
||||||
@@ -252,17 +260,17 @@ export class Api {
|
|||||||
/**
|
/**
|
||||||
* Edit member in a group or a project
|
* Edit member in 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
|
||||||
* @param userId ID of the user
|
* @param userId ID of the user
|
||||||
* @param accessLevel Access level for the member in the scope
|
* @param accessLevel Access level for the member in the scope
|
||||||
*/
|
*/
|
||||||
public editMember(scope: 'groups' | 'projects',
|
public editMember(scope: MembershipScope,
|
||||||
id: number,
|
id: number,
|
||||||
userId: number,
|
userId: number,
|
||||||
accessLevel: AccessLevel): Promise<Member> {
|
accessLevel: AccessLevel): Promise<Member> {
|
||||||
return this.makeGitLabAPIRequest(
|
return this.makeGitLabAPIRequest(
|
||||||
scope + '/' + id + '/members',
|
`${scope}/${id}/members`,
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
access_level: accessLevel,
|
access_level: accessLevel,
|
||||||
@@ -279,7 +287,7 @@ export class Api {
|
|||||||
* @param projectId Project ID to get branches for
|
* @param projectId Project ID to get branches for
|
||||||
*/
|
*/
|
||||||
public getBranchesForProject(projectId: number): Promise<Branch[]> {
|
public getBranchesForProject(projectId: number): Promise<Branch[]> {
|
||||||
return this.makeGitLabAPIRequest('projects/' + projectId + '/repository/branches');
|
return this.makeGitLabAPIRequest(`projects/${projectId}/repository/branches`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -291,7 +299,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),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -302,7 +310,7 @@ export class Api {
|
|||||||
* @param projectId ID of the project
|
* @param projectId ID of the project
|
||||||
*/
|
*/
|
||||||
public getFileList(projectId: number): Promise<TreeFile[]> {
|
public getFileList(projectId: number): Promise<TreeFile[]> {
|
||||||
return this.makeGitLabAPIRequest('projects/' + projectId + '/repository/tree');
|
return this.makeGitLabAPIRequest(`projects/${projectId}/repository/tree`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -375,7 +383,7 @@ export class Api {
|
|||||||
* @param projectId Project ID to get milestones for
|
* @param projectId Project ID to get milestones for
|
||||||
*/
|
*/
|
||||||
public getMilestonesForProject(projectId: number): Promise<Milestone[]> {
|
public getMilestonesForProject(projectId: number): Promise<Milestone[]> {
|
||||||
return this.makeGitLabAPIRequest('projects/' + projectId + '/milestones');
|
return this.makeGitLabAPIRequest(`projects/${projectId}/milestones`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -384,7 +392,7 @@ export class Api {
|
|||||||
* @param groupId Group ID to get projects for
|
* @param groupId Group ID to get projects for
|
||||||
*/
|
*/
|
||||||
public getProjectsForGroup(groupId: number): Promise<Project[]> {
|
public getProjectsForGroup(groupId: number): Promise<Project[]> {
|
||||||
return this.makeGitLabAPIRequest('groups/' + groupId + '/projects');
|
return this.makeGitLabAPIRequest(`groups/${groupId}/projects`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -403,7 +411,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`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,8 +510,8 @@ 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' +
|
/* tslint:disable-next-line:max-line-length */
|
||||||
'?developers_can_push=false&developers_can_merge=false',
|
`projects/${projectId}/repository/branches/${branch}/protect?developers_can_push=false&developers_can_merge=false`,
|
||||||
{
|
{
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
},
|
},
|
||||||
@@ -516,9 +524,9 @@ export class Api {
|
|||||||
* @param issue Issue to set milestone for
|
* @param issue Issue to set milestone for
|
||||||
* @param userId ID of the milestone to set for the issue
|
* @param userId ID of the milestone to set for the issue
|
||||||
*/
|
*/
|
||||||
public setAssigneeForIssue(issue: any, userId: number): Promise<Issue> {
|
public setAssigneeForIssue(issue: Issue, userId: number): Promise<Issue> {
|
||||||
return this.makeGitLabAPIRequest(
|
return this.makeGitLabAPIRequest(
|
||||||
'projects/' + issue.project_id + '/issues/' + issue.iid + '?assignee_ids=' + userId,
|
`projects/${issue.project_id}/issues/${issue.iid}?assignee_ids=${userId}`,
|
||||||
{
|
{
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
},
|
},
|
||||||
@@ -531,10 +539,10 @@ export class Api {
|
|||||||
* @param issue Issue to set milestone for
|
* @param issue Issue to set milestone for
|
||||||
* @param milestoneId ID of the milestone to set for the issue
|
* @param milestoneId ID of the milestone to set for the issue
|
||||||
*/
|
*/
|
||||||
public setMilestoneForIssue(issue: any, milestoneId: number): Promise<Issue> {
|
public setMilestoneForIssue(issue: Issue, milestoneId: number): Promise<Issue> {
|
||||||
if (milestoneId === null) {
|
if (milestoneId === null) {
|
||||||
return this.makeGitLabAPIRequest(
|
return this.makeGitLabAPIRequest(
|
||||||
'projects/' + issue.project_id + '/issues/' + issue.iid + '?milestone_id=',
|
`projects/${issue.project_id}/issues/${issue.iid}?milestone_id=`,
|
||||||
{
|
{
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
},
|
},
|
||||||
@@ -542,7 +550,7 @@ export class Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.makeGitLabAPIRequest(
|
return this.makeGitLabAPIRequest(
|
||||||
'projects/' + issue.project_id + '/issues/' + issue.iid + '?milestone_id=' + milestoneId,
|
`projects/${issue.project_id}/issues/${issue.iid}?milestone_id=${milestoneId}`,
|
||||||
{
|
{
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user