MCPcopy
hub / github.com/firecow/gitlab-ci-local / handler

Function handler

src/handler.ts:24–118  ·  view source on GitHub ↗
(args: any, writeStreams: WriteStreams, jobs: Job[] = [], childPipelineDepth = 0)

Source from the content-addressed store, hash-verified

22};
23
24export async function handler (args: any, writeStreams: WriteStreams, jobs: Job[] = [], childPipelineDepth = 0) {
25 assert(childPipelineDepth <= 2, "Parent and child pipelines have a maximum depth of two levels of child pipelines.");
26 const argv = await Argv.build({...args, childPipelineDepth: childPipelineDepth}, writeStreams);
27 const cwd = argv.cwd;
28 const stateDir = argv.stateDir;
29 const file = argv.file;
30 let parser: Parser;
31
32 if (argv.completion) {
33 yargs(process.argv.slice(2)).scriptName("gitlab-ci-local").showCompletionScript();
34 return [];
35 }
36
37 assert(fs.existsSync(`${cwd}/${file}`), `${path.resolve(cwd)}/${file} could not be found`);
38
39 if (argv.preview) {
40 const pipelineIid = await state.getPipelineIid(cwd, stateDir);
41 parser = await Parser.create(argv, writeStreams, pipelineIid, jobs, false);
42 const gitlabData = parser.gitlabData;
43 for (const jobName of Object.keys(gitlabData)) {
44 if (jobName === "stages") {
45 continue;
46 }
47 if (jobName.startsWith(".") || ["include", "after_script", "before_script", "default"].includes(jobName)) {
48 // Remove since these are redundant info which are already "extended" in the jobs
49 delete gitlabData[jobName];
50 }
51 }
52 writeStreams.stdout(`---\n${yaml.dump(gitlabData, {lineWidth: 160})}`);
53 } else if (argv.list || argv.listAll) {
54 const pipelineIid = await state.getPipelineIid(cwd, stateDir);
55 parser = await Parser.create(argv, writeStreams, pipelineIid, jobs);
56 Commander.runList(parser, writeStreams, argv.listAll);
57 } else if (argv.validateDependencyChain) {
58 const pipelineIid = await state.getPipelineIid(cwd, stateDir);
59 parser = await Parser.create(argv, writeStreams, pipelineIid, jobs);
60 Commander.validateDependencyChain(parser);
61 writeStreams.stdout(chalk`{green ✓ All job dependencies are valid}\n`);
62 } else if (argv.listJson) {
63 const pipelineIid = await state.getPipelineIid(cwd, stateDir);
64 parser = await Parser.create(argv, writeStreams, pipelineIid, jobs);
65 Commander.runJson(parser, writeStreams);
66 } else if (argv.listCsv || argv.listCsvAll) {
67 const pipelineIid = await state.getPipelineIid(cwd, stateDir);
68 parser = await Parser.create(argv, writeStreams, pipelineIid, jobs);
69 Commander.runCsv(parser, writeStreams, argv.listCsvAll);
70 } else if (argv.job.length > 0) {
71 assert(argv.stage === null, "You cannot use --stage when starting individual jobs");
72 if (argv.registry) {
73 await Utils.startDockerRegistry(argv);
74 }
75 generateGitIgnore(cwd, stateDir);
76 const time = process.hrtime();
77 let pipelineIid: number;
78 if (argv.needs || argv.onlyNeeds) {
79 pipelineIid = await state.incrementPipelineIid(cwd, stateDir);
80 } else {
81 pipelineIid = await state.getPipelineIid(cwd, stateDir);

Callers 15

startTriggerPipelineMethod · 0.85
index.tsFile · 0.85
cases.test.tsFile · 0.85

Calls 15

generateGitIgnoreFunction · 0.85
cleanupJobResourcesFunction · 0.85
buildMethod · 0.80
createMethod · 0.80
runListMethod · 0.80
runJsonMethod · 0.80
runCsvMethod · 0.80
startDockerRegistryMethod · 0.80
rsyncTrackedFilesMethod · 0.80
runJobsMethod · 0.80
runJobsInStageMethod · 0.80
runPipelineMethod · 0.80

Tested by 1

verifyLogsFunction · 0.68