import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { GitlabAPIResponse, PaginationRequestOptions, PaginationTypes, ShowExpanded, Sudo, } from '../infrastructure'; export interface BaseExternalStatusCheckSchema extends Record { id: number; name: string; external_url: string; status: string; } export type MergeRequestExternalStatusCheckSchema = BaseExternalStatusCheckSchema; export interface ExternalStatusCheckProtectedBranchesSchema { id: number; project_id: number; name: string; created_at: string; updated_at: string; code_owner_approval_required: boolean; } export interface ProjectExternalStatusCheckSchema extends BaseExternalStatusCheckSchema { project_id: number; protected_branches?: ExternalStatusCheckProtectedBranchesSchema[]; } export class ExternalStatusChecks extends BaseResource { all( projectId: string | number, options: { mergerequestIId: number } & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; all( projectId: string | number, options?: PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; all( projectId: string | number, options?: { mergerequestIId?: number } & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise { const { mergerequestIId, ...opts } = options || {}; let url: string = endpoint`projects/${projectId}`; if (mergerequestIId) { url += endpoint`/merge_requests/${mergerequestIId}/status_checks`; } else { url += '/external_status_checks'; } return RequestHelper.get< (MergeRequestExternalStatusCheckSchema | ProjectExternalStatusCheckSchema)[] >()(this, url, opts); } create( projectId: string | number, name: string, externalUrl: string, options?: { protectedBrancheIds: number[] } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/external_status_checks`, { name, externalUrl, ...options, }, ); } edit( projectId: string | number, externalStatusCheckId: number, options?: { protectedBrancheIds?: number[]; externalUrl?: string; name?: string; } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.put()( this, endpoint`projects/${projectId}/external_status_checks/${externalStatusCheckId}`, options, ); } remove( projectId: string | number, externalStatusCheckId: number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.del()( this, endpoint`projects/${projectId}/external_status_checks/${externalStatusCheckId}`, options, ); } set( projectId: string | number, mergerequestIId: number, sha: string, externalStatusCheckId: number, options?: { status?: 'passed' | 'failed' } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/merge_requests/${mergerequestIId}/status_check_responses`, { sha, externalStatusCheckId, ...options, }, ); } }