Skip to content

Commit c9b02e6

Browse files
Refactor Pipeline to Pipeline V2 (#186)
1 parent afc5828 commit c9b02e6

File tree

17 files changed

+148
-663
lines changed

17 files changed

+148
-663
lines changed

docs/content/pipelines v2 (beta)/spec.md renamed to docs/content/pipelines/spec.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ spec:
6060
version: "1.0"
6161
kind: "pipeline"
6262
metadata:
63-
name: "my-pipeline-1"
63+
name: "my-pipeline"
6464
spec:
6565
triggers:
6666
- type: "git"
6767
provider: "github"
6868
repo: "codefresh-io/cli"
69-
events: ["push", "pullrequest"]
69+
events: ["push"]
7070
branchRegex: '/./'
7171
contexts: []
7272
variables:
@@ -87,13 +87,13 @@ spec:
8787
version: "1.0"
8888
kind: "pipeline"
8989
metadata:
90-
name: "my-pipeline-1"
90+
name: "my-pipeline"
9191
spec:
9292
triggers:
9393
- type: "git"
9494
provider: "github"
9595
repo: "codefresh-io/cli"
96-
events: ["push", "pullrequest"]
96+
events: ["push"]
9797
branchRegex: '/./'
9898
contexts: []
9999
variables:

lib/interface/cli/commands/pipeline/apply.cmd.js

Lines changed: 0 additions & 80 deletions
This file was deleted.

lib/interface/cli/commands/pipeline2/delete.cmd.js renamed to lib/interface/cli/commands/pipeline/delete.cmd.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ const debug = require('debug')('codefresh:cli:create:pipelines2');
22
const Command = require('../../Command');
33
const CFError = require('cf-errors');
44
const _ = require('lodash');
5-
const { pipeline2: pipeline } = require('../../../../logic').api;
5+
const { pipeline } = require('../../../../logic').api;
66
const deleteRoot = require('../root/delete.cmd');
77

88

99
const command = new Command({
10-
command: 'pipeline-v2 [name]',
11-
aliases: ['pip-v2'],
10+
command: 'pipeline [name]',
11+
aliases: ['pip'],
1212
parent: deleteRoot,
1313
description: 'Delete a pipeline',
1414
webDocs: {
15-
category: 'Pipelines V2 (beta)',
15+
category: 'Pipelines',
1616
title: 'Delete Pipeline',
1717
},
1818
builder: (yargs) => {

lib/interface/cli/commands/pipeline/get.cmd.js

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
1-
const debug = require('debug')('codefresh:cli:create:context');
1+
const debug = require('debug')('codefresh:cli:create:pipelines2');
22
const Command = require('../../Command');
33
const CFError = require('cf-errors');
44
const _ = require('lodash');
5-
const { pipeline } = require('../../../../logic').api;
6-
const { specifyOutputForSingle, specifyOutputForArray } = require('../../helpers/get');
7-
const getRoot = require('../root/get.cmd');
85
const DEFAULTS = require('../../defaults');
6+
const { pipeline } = require('../../../../logic').api;
7+
const { prepareKeyValueFromCLIEnvOption, printError } = require('../../helpers/general');
8+
const { specifyOutputForArray } = require('../../helpers/get');
99

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

1112

1213
const command = new Command({
1314
command: 'pipelines [id..]',
1415
aliases: ['pip', 'pipeline'],
1516
parent: getRoot,
1617
description: 'Get a specific pipeline or an array of pipelines',
17-
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',
1818
webDocs: {
1919
category: 'Pipelines',
2020
title: 'Get Pipeline',
2121
},
2222
builder: (yargs) => {
2323
return yargs
2424
.positional('id', {
25-
describe: 'Pipeline id',
25+
describe: 'Pipeline name/id',
2626
})
27-
.option('repo-owner', {
28-
describe: 'Repository owner',
27+
.option('decrypt-variables', {
28+
alias: 'd',
29+
describe: 'Will decrypt encrypted variables',
2930
})
30-
.option('repo-name', {
31-
describe: 'Repository name',
31+
.option('name', {
32+
describe: 'Filter pipelines by name',
33+
})
34+
.option('label', {
35+
describe: 'Filter by a label',
36+
alias: 'l',
37+
default: [],
3238
})
3339
.option('limit', {
3440
describe: 'Limit amount of returned results',
@@ -37,40 +43,43 @@ const command = new Command({
3743
.option('page', {
3844
describe: 'Paginated page',
3945
default: DEFAULTS.GET_PAGINATED_PAGE,
40-
})
41-
.option('name', {
42-
describe: 'Filter results by pipeline name',
43-
type: Array,
44-
})
45-
.example('codefresh get pipeline ID', 'Get pipeline ID')
46-
.example('codefresh get pipelines', 'Get all pipelines')
47-
.example('codefresh get pipelines --name release', 'Get all pipelines that their name is release')
48-
.example('codefresh get pipelines --repo-name node', "Get all pipelines that are associated with the repository name 'node'");
46+
});
4947
},
5048
handler: async (argv) => {
51-
const pipelineIds = argv.id;
52-
const repoOwner = argv['repo-owner'];
53-
const repoName = argv['repo-name'];
54-
const name = argv.name;
49+
const { id: ids, name, output, d: decryptVariables } = argv;
5550
const limit = argv.limit;
56-
const page = argv.page;
51+
const offset = (argv.page - 1) * limit;
52+
const labels = prepareKeyValueFromCLIEnvOption(argv.label);
53+
54+
debug(`decrypt: ${decryptVariables}`);
55+
if (!_.isEmpty(ids)) {
56+
const pipelines = [];
57+
for (const id of ids) {
58+
try {
59+
const currPipeline = await pipeline.getPipelineByName(id, { decryptVariables });
60+
pipelines.push(currPipeline);
61+
} catch (err) {
62+
if (pipelines.length) {
63+
specifyOutputForArray(output, pipelines);
64+
}
5765

58-
let pipelines = [];
59-
if (!_.isEmpty(pipelineIds)) {
60-
for (const id of pipelineIds) {
61-
const currPipeline = await pipeline.getPipelineById(id);
62-
pipelines.push(currPipeline);
66+
debug(err.toString());
67+
const message = err.toString().includes('not find') ? `Pipeline '${id}' was not found.` : 'Error occurred';
68+
throw new CFError({
69+
cause: err,
70+
message,
71+
});
72+
}
6373
}
74+
specifyOutputForArray(output, pipelines);
6475
} else {
65-
pipelines = await pipeline.getAll({
66-
repoOwner,
67-
repoName,
68-
name,
76+
specifyOutputForArray(output, await pipeline.getAll({
6977
limit,
70-
page,
71-
});
78+
offset,
79+
name,
80+
labels,
81+
}));
7282
}
73-
specifyOutputForArray(argv.output, pipelines);
7483
},
7584
});
7685

lib/interface/cli/commands/pipeline/run.cmd.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const CFError = require('cf-errors');
55
const { prepareKeyValueFromCLIEnvOption, crudFilenameOption } = require('../../helpers/general');
66
const ObjectID = require('mongodb').ObjectID;
77
const { workflow, pipeline, log } = require('../../../../logic').api;
8+
const authManager = require('../../../../logic').auth.manager;
9+
810

911
const run = new Command({
1012
root: true,
11-
command: 'run <id>',
13+
command: 'run <name>',
1214
description: 'Run a pipeline and attach the created workflow logs.',
1315
usage: 'Returns an exit code according to the workflow finish status (Success: 0, Error: 1, Terminated: 2)',
1416
webDocs: {
@@ -21,10 +23,9 @@ const run = new Command({
2123
.option('branch', {
2224
describe: 'Branch',
2325
alias: 'b',
24-
require: true,
2526
})
26-
.positional('id', {
27-
describe: 'Pipeline id',
27+
.positional('name', {
28+
describe: 'Pipeline name',
2829
})
2930
.option('sha', {
3031
describe: 'Set commit sha',
@@ -69,31 +70,25 @@ const run = new Command({
6970
return yargs;
7071
},
7172
handler: async (argv) => {
72-
const pipelineId = argv.id;
73+
const pipelineName = argv.name;
7374
const branch = argv.branch;
7475
const sha = argv.sha;
7576
const noCache = argv['no-cache'];
7677
const resetVolume = argv['reset-volume'];
7778
const variablesFromFile = argv['var-file'];
7879
const contexts = argv['context'];
7980

80-
if (!ObjectID.isValid(pipelineId)) {
81-
throw new CFError({
82-
message: `Passed pipeline id: ${pipelineId} is not valid`,
83-
});
84-
}
85-
8681
try {
87-
await pipeline.getPipelineById(pipelineId);
82+
await pipeline.getPipelineByName(pipelineName);
8883
} catch (err) {
8984
throw new CFError({
90-
message: `Passed pipeline id: ${pipelineId} does not exist`,
85+
message: `Passed pipeline id: ${pipelineName} does not exist`,
9186
});
9287
}
9388

9489
const executionRequests = [];
9590
const executionRequestTemplate = {
96-
pipelineId,
91+
pipelineName,
9792
options: {
9893
noCache,
9994
resetVolume,
@@ -116,8 +111,9 @@ const run = new Command({
116111
executionRequests.push(request);
117112
}
118113

119-
_.forEach(executionRequests, async ({ pipelineId, options }) => {
120-
const workflowId = await pipeline.runPipelineById(pipelineId, options);
114+
_.forEach(executionRequests, async ({ pipelineName, options }) => {
115+
let workflowId;
116+
workflowId = await pipeline.runPipelineByName(pipelineName, options);
121117

122118
if (executionRequests.length === 1) {
123119
if (argv.detach) {

0 commit comments

Comments
 (0)