Skip to content

Commit

Permalink
Refactor Pipeline to Pipeline V2 (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
itai-codefresh authored Apr 29, 2018
1 parent afc5828 commit c9b02e6
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 663 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ spec:
version: "1.0"
kind: "pipeline"
metadata:
name: "my-pipeline-1"
name: "my-pipeline"
spec:
triggers:
- type: "git"
provider: "github"
repo: "codefresh-io/cli"
events: ["push", "pullrequest"]
events: ["push"]
branchRegex: '/./'
contexts: []
variables:
Expand All @@ -87,13 +87,13 @@ spec:
version: "1.0"
kind: "pipeline"
metadata:
name: "my-pipeline-1"
name: "my-pipeline"
spec:
triggers:
- type: "git"
provider: "github"
repo: "codefresh-io/cli"
events: ["push", "pullrequest"]
events: ["push"]
branchRegex: '/./'
contexts: []
variables:
Expand Down
80 changes: 0 additions & 80 deletions lib/interface/cli/commands/pipeline/apply.cmd.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ const debug = require('debug')('codefresh:cli:create:pipelines2');
const Command = require('../../Command');
const CFError = require('cf-errors');
const _ = require('lodash');
const { pipeline2: pipeline } = require('../../../../logic').api;
const { pipeline } = require('../../../../logic').api;
const deleteRoot = require('../root/delete.cmd');


const command = new Command({
command: 'pipeline-v2 [name]',
aliases: ['pip-v2'],
command: 'pipeline [name]',
aliases: ['pip'],
parent: deleteRoot,
description: 'Delete a pipeline',
webDocs: {
category: 'Pipelines V2 (beta)',
category: 'Pipelines',
title: 'Delete Pipeline',
},
builder: (yargs) => {
Expand Down
81 changes: 45 additions & 36 deletions lib/interface/cli/commands/pipeline/get.cmd.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
const debug = require('debug')('codefresh:cli:create:context');
const debug = require('debug')('codefresh:cli:create:pipelines2');
const Command = require('../../Command');
const CFError = require('cf-errors');
const _ = require('lodash');
const { pipeline } = require('../../../../logic').api;
const { specifyOutputForSingle, specifyOutputForArray } = require('../../helpers/get');
const getRoot = require('../root/get.cmd');
const DEFAULTS = require('../../defaults');
const { pipeline } = require('../../../../logic').api;
const { prepareKeyValueFromCLIEnvOption, printError } = require('../../helpers/general');
const { specifyOutputForArray } = require('../../helpers/get');

const getRoot = require('../root/get.cmd');


const command = new Command({
command: 'pipelines [id..]',
aliases: ['pip', 'pipeline'],
parent: getRoot,
description: 'Get a specific pipeline or an array of pipelines',
usage: 'Passing [id] argument will cause a retrieval of a specific pipeline.\n In case of not passing [id] argument, a list will be returned',
webDocs: {
category: 'Pipelines',
title: 'Get Pipeline',
},
builder: (yargs) => {
return yargs
.positional('id', {
describe: 'Pipeline id',
describe: 'Pipeline name/id',
})
.option('repo-owner', {
describe: 'Repository owner',
.option('decrypt-variables', {
alias: 'd',
describe: 'Will decrypt encrypted variables',
})
.option('repo-name', {
describe: 'Repository name',
.option('name', {
describe: 'Filter pipelines by name',
})
.option('label', {
describe: 'Filter by a label',
alias: 'l',
default: [],
})
.option('limit', {
describe: 'Limit amount of returned results',
Expand All @@ -37,40 +43,43 @@ const command = new Command({
.option('page', {
describe: 'Paginated page',
default: DEFAULTS.GET_PAGINATED_PAGE,
})
.option('name', {
describe: 'Filter results by pipeline name',
type: Array,
})
.example('codefresh get pipeline ID', 'Get pipeline ID')
.example('codefresh get pipelines', 'Get all pipelines')
.example('codefresh get pipelines --name release', 'Get all pipelines that their name is release')
.example('codefresh get pipelines --repo-name node', "Get all pipelines that are associated with the repository name 'node'");
});
},
handler: async (argv) => {
const pipelineIds = argv.id;
const repoOwner = argv['repo-owner'];
const repoName = argv['repo-name'];
const name = argv.name;
const { id: ids, name, output, d: decryptVariables } = argv;
const limit = argv.limit;
const page = argv.page;
const offset = (argv.page - 1) * limit;
const labels = prepareKeyValueFromCLIEnvOption(argv.label);

debug(`decrypt: ${decryptVariables}`);
if (!_.isEmpty(ids)) {
const pipelines = [];
for (const id of ids) {
try {
const currPipeline = await pipeline.getPipelineByName(id, { decryptVariables });
pipelines.push(currPipeline);
} catch (err) {
if (pipelines.length) {
specifyOutputForArray(output, pipelines);
}

let pipelines = [];
if (!_.isEmpty(pipelineIds)) {
for (const id of pipelineIds) {
const currPipeline = await pipeline.getPipelineById(id);
pipelines.push(currPipeline);
debug(err.toString());
const message = err.toString().includes('not find') ? `Pipeline '${id}' was not found.` : 'Error occurred';
throw new CFError({
cause: err,
message,
});
}
}
specifyOutputForArray(output, pipelines);
} else {
pipelines = await pipeline.getAll({
repoOwner,
repoName,
name,
specifyOutputForArray(output, await pipeline.getAll({
limit,
page,
});
offset,
name,
labels,
}));
}
specifyOutputForArray(argv.output, pipelines);
},
});

Expand Down
28 changes: 12 additions & 16 deletions lib/interface/cli/commands/pipeline/run.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const CFError = require('cf-errors');
const { prepareKeyValueFromCLIEnvOption, crudFilenameOption } = require('../../helpers/general');
const ObjectID = require('mongodb').ObjectID;
const { workflow, pipeline, log } = require('../../../../logic').api;
const authManager = require('../../../../logic').auth.manager;


const run = new Command({
root: true,
command: 'run <id>',
command: 'run <name>',
description: 'Run a pipeline and attach the created workflow logs.',
usage: 'Returns an exit code according to the workflow finish status (Success: 0, Error: 1, Terminated: 2)',
webDocs: {
Expand All @@ -21,10 +23,9 @@ const run = new Command({
.option('branch', {
describe: 'Branch',
alias: 'b',
require: true,
})
.positional('id', {
describe: 'Pipeline id',
.positional('name', {
describe: 'Pipeline name',
})
.option('sha', {
describe: 'Set commit sha',
Expand Down Expand Up @@ -69,31 +70,25 @@ const run = new Command({
return yargs;
},
handler: async (argv) => {
const pipelineId = argv.id;
const pipelineName = argv.name;
const branch = argv.branch;
const sha = argv.sha;
const noCache = argv['no-cache'];
const resetVolume = argv['reset-volume'];
const variablesFromFile = argv['var-file'];
const contexts = argv['context'];

if (!ObjectID.isValid(pipelineId)) {
throw new CFError({
message: `Passed pipeline id: ${pipelineId} is not valid`,
});
}

try {
await pipeline.getPipelineById(pipelineId);
await pipeline.getPipelineByName(pipelineName);
} catch (err) {
throw new CFError({
message: `Passed pipeline id: ${pipelineId} does not exist`,
message: `Passed pipeline id: ${pipelineName} does not exist`,
});
}

const executionRequests = [];
const executionRequestTemplate = {
pipelineId,
pipelineName,
options: {
noCache,
resetVolume,
Expand All @@ -116,8 +111,9 @@ const run = new Command({
executionRequests.push(request);
}

_.forEach(executionRequests, async ({ pipelineId, options }) => {
const workflowId = await pipeline.runPipelineById(pipelineId, options);
_.forEach(executionRequests, async ({ pipelineName, options }) => {
let workflowId;
workflowId = await pipeline.runPipelineByName(pipelineName, options);

if (executionRequests.length === 1) {
if (argv.detach) {
Expand Down
Loading

0 comments on commit c9b02e6

Please sign in to comment.