import { BaseResource } from '@gitbeaker/requester-utils' ; import { UserSchema } from './Users' ; import { BaseRequestOptions , endpoint , PaginatedRequestOptions , RequestHelper , Sudo , } from '../infrastructure' ; export interface PipelineTriggerSchema extends Record < string , unknown > { id : number ; description : string ; created_at : string ; last_used ? : string ; token : string ; updated_at : string ; owner : Pick < UserSchema , 'id' | 'name' | 'created_at' > ; } export class Triggers < C extends boolean = false > extends BaseResource < C > { add ( projectId , options ? ) { return RequestHelper . post < PipelineTriggerSchema > ( ) ( this , endpoint `projects/${ projectId }/triggers` , options ) ; } all ( projectId , options ? ) { return RequestHelper . get < PipelineTriggerSchema [ ] > ( ) ( this , endpoint `projects/${ projectId }/triggers` , options ) ; } edit ( projectId , triggerId , options ? ) { return RequestHelper . put < PipelineTriggerSchema > ( ) ( this , endpoint `projects/${ projectId }/triggers/${ triggerId }` , options ) ; } pipeline ( projectId , ref , token , { variables } = { } ) { const hapiVariables = { } ; if ( variables ) { Object . entries ( variables ) . forEach ( ( [ k , v ] ) => { hapiVariables [ `variables[${ k }]` ] = v ; } ) ; } return RequestHelper . post ( ) ( this , endpoint `projects/${ projectId }/trigger/pipeline` , { isForm : true , ref , token , ... hapiVariables , } ) ; } remove ( projectId , triggerId , options ? ) { return RequestHelper . del ( ) ( this , endpoint `projects/${ projectId }/triggers/${ triggerId }` , options ) ; } show ( projectId , triggerId , options ? ) { return RequestHelper . get < PipelineTriggerSchema > ( ) ( this , endpoint `projects/${ projectId }/triggers/${ triggerId }` , options ) ; } }