Skip to content

Commit b356dea

Browse files
add support for workflow filters (#46)
add support for filtering pagination and limitation workflows
1 parent 25189ab commit b356dea

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const Command = require('../../Command');
33
const CFError = require('cf-errors');
44
const _ = require('lodash');
55
const DEFAULTS = require('../../defaults');
6-
const { workflow } = require('../../../../logic').api;
6+
const { workflow , pipeline } = require('../../../../logic').api;
77
const { specifyOutputForSingle, specifyOutputForArray } = require('../../helpers/get');
88
const getRoot = require('../root/get.cmd');
99

@@ -22,22 +22,63 @@ const command = new Command({
2222
.option('page', {
2323
describe: 'Paginated page',
2424
default: DEFAULTS.GET_PAGINATED_PAGE,
25+
})
26+
.option('status', {
27+
describe: 'Filter results by statuses',
28+
type: Array,
29+
choices: ['error', 'running', 'success', 'terminated'],
30+
})
31+
.option('trigger', {
32+
describe: 'Filter results by triggers',
33+
type: Array,
34+
choices: ['build', 'launch'],
35+
})
36+
.option('pipeline-id', {
37+
describe: 'Filter results by pipeline id',
38+
type: Array,
39+
default: [],
40+
})
41+
.option('pipeline-name', {
42+
describe: 'Filter results by pipeline name',
43+
type: Array,
44+
default: [],
2545
});
46+
2647
},
2748
handler: async (argv) => {
2849
const workflowId = argv.id;
2950
const limit = argv.limit;
3051
const page = argv.page;
52+
const status = argv.status;
53+
const trigger = argv.trigger;
54+
const pipelineNames = !_.isArray(argv['pipeline-name']) ? [(argv['pipeline-name'])] : argv['pipeline-name'];
55+
const pipelineIds = !_.isArray(argv['pipeline-id']) ? [(argv['pipeline-id'])] : argv['pipeline-id'];
3156

3257
let workflows;
3358
// TODO:need to decide for one way for error handeling
3459
if (workflowId) {
3560
workflows = await workflow.getWorkflowById(workflowId);
3661
specifyOutputForSingle(argv.output, workflows);
3762
} else {
63+
if (_.isEmpty(pipelineIds) && !_.isEmpty(pipelineNames)) {
64+
const pipelines = await pipeline.getAll();
65+
_.forEach(pipelineNames, (pipelineName) => {
66+
const matchPipelines = _.find(pipelines, pipeline => pipeline.info.name.toString() === pipelineName);
67+
if (_.isArray(matchPipelines)) {
68+
_.forEach(matchPipelines, (currPipeline) => {
69+
pipelineIds.push(currPipeline.info.id);
70+
});
71+
} else {
72+
pipelineIds.push(matchPipelines.info.id);
73+
}
74+
});
75+
}
3876
workflows = await workflow.getWorkflows({
3977
limit,
4078
page,
79+
status,
80+
trigger,
81+
pipelineIds,
4182
});
4283
specifyOutputForArray(argv.output, workflows);
4384
}

lib/logic/api/workflow.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ const getWorkflows = async (options) => {
3939
const qs = {
4040
limit: options.limit,
4141
page: options.page,
42+
status: options.status,
43+
trigger: options.trigger,
44+
service: options.pipelineIds,
4245
};
4346

4447
const RequestOptions = {

0 commit comments

Comments
 (0)