Skip to content

Commit

Permalink
Added needs option.
Browse files Browse the repository at this point in the history
  • Loading branch information
firecow committed May 4, 2020
1 parent 4110820 commit 563d009
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,23 @@ export class Commander {
}
}

static async runSingleJob(parser: Parser, jobName: string) {
static async runSingleJob(parser: Parser, jobName: string, needs: boolean) {
const jobs: Job[] = [];
const stageNames = parser.getStageNames();
const foundJob = parser.getJobByName(jobName);
jobs.push(foundJob);
let needs: string[] = [];
if (foundJob.needs) needs = needs.concat(foundJob.needs);

// Recursive backwards traversal to find parant needs.
while (needs.length > 0) {
const need = needs.pop();
if (need) {
const needJob = parser.getJobByName(need);
jobs.unshift(needJob);
if (needJob.needs) needs = needs.concat(needJob.needs);

if (needs) {
// Recursive backwards traversal to find parant needs.
let needed: string[] = [];
if (foundJob.needs) needed = needed.concat(foundJob.needs);
while (needed.length > 0) {
const need = needed.pop();
if (need) {
const needJob = parser.getJobByName(need);
jobs.unshift(needJob);
if (needJob.needs) needed = needed.concat(needJob.needs);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/default_cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.handler = async(argv: any) => {
if (argv.job) {
const pipelineIid = predefinedVariables.getPipelineIid(cwd);
const parser = new Parser(cwd, pipelineIid);
await Commander.runSingleJob(parser, argv.job as string);
await Commander.runSingleJob(parser, argv.job as string, argv.needs as boolean);
} else {
predefinedVariables.incrementPipelineIid(cwd);
const pipelineIid = predefinedVariables.getPipelineIid(cwd);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const argv = yargs
.option("list", {type: "string", description: "List jobs and job information", requiresArg: false})
.option("cwd", {type: "string", description: "Path to a gitlab-ci.yml", requiresArg: true})
.option("completion", {type: "string", description: "Generate bash completion script", requiresArg: false})
.option("needs", {type: "boolean", description: "Run needed jobs, when executing a single job", requiresArg: false})
.completion("completion", false, async (current, a) => {
const cwd = a.cwd as string || process.cwd();
const pipelineIid = predefinedVariables.getPipelineIid(cwd);
Expand Down

0 comments on commit 563d009

Please sign in to comment.