Justin Dalrymple d9cd4c9a91 refactor: 💡 Migrated to a monorepo structure
Gitbeaker has been split up into 5 subpackages: gitbeaker-core, gitbeaker-node, gitbeaker-cli, gitbeaker-browser and gitbeaker-requester-utils.

gitbeaker-[node,cli,browser] are enviroment
specific sub packages. For example, if you want to use gitbeaker in a NodeJS environment, use gitbeaker-node. gitbeaker-core is where all the
base logic exists, and gitbeaker-requester-utils is a collection of utility functions for making custom requester libraries.

BREAKING CHANGE: 🧨 This migration requires users to import specific subpackages. For NodeJS
usage, that would be @gitbeaker/node.
2020-02-02 16:53:54 +01:00

90 lines
2.7 KiB
TypeScript

import {
BaseRequestOptions,
BaseService,
PaginatedRequestOptions,
RequestHelper,
Sudo,
} from '../infrastructure';
import { DeploymentSchema } from './Deployments';
import { ProjectSchemaDefault, ProjectSchemaCamelized } from './Projects';
// ref: https://docs.gitlab.com/12.6/ee/api/environments.html#list-environments
export type EnvironmentSchema = EnvironmentSchemaDefault | EnvironmentSchemaCamelized;
export interface EnvironmentSchemaDefault {
id: number;
name: string;
slug?: string;
external_url?: string;
project?: ProjectSchemaDefault;
state?: string;
}
export interface EnvironmentSchemaCamelized {
id: number;
name: string;
slug?: string;
externalUrl?: string;
project?: ProjectSchemaCamelized;
state?: string;
}
export type EnvironmentDetailSchema =
| EnvironmentDetailSchemaDefault
| EnvironmentDetailSchemaCamelized;
export interface EnvironmentDetailSchemaDefault extends EnvironmentSchemaDefault {
last_deployment?: DeploymentSchema;
deployable?: DeploymentSchema;
}
export interface EnvironmentDetailSchemaCamelized extends EnvironmentSchemaCamelized {
lastDeployment?: DeploymentSchema;
deployable?: DeploymentSchema;
}
export class Environments extends BaseService {
all(projectId: string | number, options?: PaginatedRequestOptions): Promise<EnvironmentSchema[]> {
const pId = encodeURIComponent(projectId);
return RequestHelper.get(this, `projects/${pId}/environments`, options) as Promise<
EnvironmentSchema[]
>;
}
show(
projectId: string | number,
environmentId: number,
options?: Sudo,
): Promise<EnvironmentDetailSchema> {
const [pId, eId] = [projectId, environmentId].map(encodeURIComponent);
return RequestHelper.get(this, `projects/${pId}/environments/${eId}`, options) as Promise<
EnvironmentDetailSchema
>;
}
create(projectId: string | number, options?: BaseRequestOptions) {
const pId = encodeURIComponent(projectId);
return RequestHelper.post(this, `projects/${pId}/environments`, options);
}
edit(projectId: string | number, environmentId: number, options?: BaseRequestOptions) {
const [pId, eId] = [projectId, environmentId].map(encodeURIComponent);
return RequestHelper.put(this, `projects/${pId}/environments/${eId}`, options);
}
remove(projectId: string | number, environmentId: number, options?: Sudo) {
const [pId, eId] = [projectId, environmentId].map(encodeURIComponent);
return RequestHelper.del(this, `projects/${pId}/environments/${eId}`, options);
}
stop(projectId: string | number, environmentId: number, options?: Sudo) {
const [pId, eId] = [projectId, environmentId].map(encodeURIComponent);
return RequestHelper.post(this, `projects/${pId}/environments/${eId}/stop`, options);
}
}