import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { GitlabAPIResponse, MappedOmit, OneOrNoneOf, PaginationRequestOptions, PaginationTypes, ShowExpanded, Sudo, } from '../infrastructure'; import type { DeployableSchema, DeploymentSchema } from './Deployments'; import { SimpleProjectSchema } from './Projects'; export type EnvironmentTier = 'production' | 'staging' | 'testing' | 'development' | 'other'; export interface EnvironmentSchema extends Record { id: number; name: string; slug: string; external_url: string; state: string; tier: EnvironmentTier; created_at: string; updated_at: string; enable_advanced_logs_querying: boolean; logs_api_path: string; flux_resource_path?: string; kubernetes_namespace?: string; last_deployment: DeploymentSchema; deployable: DeployableSchema; project?: SimpleProjectSchema; auto_stop_at: string | null; description: string | null; auto_stop_setting: string; } export type CondensedEnvironmentSchema = MappedOmit< EnvironmentSchema, 'last_deployment' | 'deployable' >; export type ReviewAppSchema = MappedOmit; export class Environments extends BaseResource { all( projectId: string | number, options?: PaginationRequestOptions

& OneOrNoneOf<{ name: string; search: string }> & { states?: 'available' | 'stopping' | 'stopped'; } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/environments`, options, ); } create( projectId: string | number, name: string, options?: { externalUrl?: string; tier?: EnvironmentTier } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/environments`, { name, ...options, }, ); } edit( projectId: string | number, environmentId: number, options?: { externalUrl?: string; tier?: EnvironmentTier } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.put()( this, endpoint`projects/${projectId}/environments/${environmentId}`, options, ); } remove( projectId: string | number, environmentId: number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.del()( this, endpoint`projects/${projectId}/environments/${environmentId}`, options, ); } removeReviewApps( projectId: string | number, options?: { before?: string; limit?: number; dryRun?: boolean } & Sudo & ShowExpanded, ): Promise< GitlabAPIResponse< { scheduled_entries: ReviewAppSchema[]; unprocessable_entries: ReviewAppSchema[] }, C, E, void > > { return RequestHelper.del<{ scheduled_entries: ReviewAppSchema[]; unprocessable_entries: ReviewAppSchema[]; }>()(this, endpoint`projects/${projectId}/environments/review_apps`, options); } show( projectId: string | number, environmentId: number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/environments/${environmentId}`, options, ); } stop( projectId: string | number, environmentId: number, options?: { force?: string } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/environments/${environmentId}/stop`, options, ); } stopStale( projectId: string | number, before: string, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.post<{ message: string }>()( this, endpoint`projects/${projectId}/environments/stop_stale`, { searchParams: { before }, ...options, }, ); } }