From d4791f3d357634daf506fb8f91cc5332a794c421 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Fri, 20 Jun 2025 14:53:38 -0700 Subject: Move to nodejs --- model/pipeline/builder.ts | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 model/pipeline/builder.ts (limited to 'model/pipeline/builder.ts') 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 = []; + + 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: [ + { + 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); + } +} -- cgit v1.2.3-70-g09d2