diff options
Diffstat (limited to 'model/pipeline/builder.ts')
-rw-r--r-- | model/pipeline/builder.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/model/pipeline/builder.ts b/model/pipeline/builder.ts new file mode 100644 index 0000000..e95e89c --- /dev/null +++ b/model/pipeline/builder.ts @@ -0,0 +1,53 @@ +import { Pipeline, PipelineStage } from '.'; +import { FetchCodeJob } from '../job'; +import { PipelineImpl } from './impl'; + +export interface PipelineBuilder { + addStage(stage: PipelineStage): PipelineBuilder; + build(): Pipeline; +} + +export abstract class BasePipelineBuilder implements PipelineBuilder { + protected readonly stages: Array<PipelineStage> = []; + + public addStage(stage: PipelineStage): PipelineBuilder { + this.stages.push(stage); + return this; + } + + public build() { + return new PipelineImpl(this.stages); + } +} + +export class DefaultGitHookPipelineBuilder extends BasePipelineBuilder { + constructor( + private readonly remoteUrl = process.env.remote!, + rev = process.env.rev!, + private readonly ref = process.env.ref!, + ) { + super(); + + this.addStage({ + parallelJobs: [ + <FetchCodeJob>{ + type: 'fetch_code.ts', + arguments: { + remoteUrl, + checkout: rev, + path: this.getSourceDestination(), + }, + }, + ], + }); + } + + public getSourceDestination() { + return this.remoteUrl.split('/').at(-1) ?? 'src'; + } + + public getBranch(): string | undefined { + const branchRefPrefix = 'refs/heads/'; + return this.ref.split(branchRefPrefix).at(1); + } +} |