Skip to content

Commit 25189ab

Browse files
Cf 4994 (#47)
add support for filtering pagination and limitation for pipelines
1 parent 3f24570 commit 25189ab

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,44 @@ const _ = require('lodash');
55
const { pipeline } = require('../../../../logic').api;
66
const { specifyOutputForSingle, specifyOutputForArray } = require('../../helpers/get');
77
const getRoot = require('../root/get.cmd');
8+
const DEFAULTS = require('../../defaults');
9+
810

911

1012
const command = new Command({
11-
command: 'pipelines [id|name] [repo-owner] [repo-name]',
13+
command: 'pipelines [id]',
1214
description: 'Get pipelines',
1315
builder: (yargs) => {
1416
return yargs
1517
.positional('id', {
16-
describe: 'Pipeline name or id',
18+
describe: 'Pipeline id',
1719
})
18-
.positional('repo-owner', {
20+
.option('repo-owner', {
1921
describe: 'Repository owner',
2022
})
21-
.positional('repo-name', {
23+
.option('repo-name', {
2224
describe: 'Repository name',
25+
})
26+
.option('limit', {
27+
describe: 'Limit amount of returned results',
28+
default: DEFAULTS.GET_LIMIT_RESULTS,
29+
})
30+
.option('page', {
31+
describe: 'Paginated page',
32+
default: DEFAULTS.GET_PAGINATED_PAGE,
33+
})
34+
.option('name', {
35+
describe: 'Filter results by pipeline name',
36+
type: Array,
2337
});
2438
},
2539
handler: async (argv) => {
2640
const id = argv.id;
2741
const repoOwner = argv['repo-owner'];
2842
const repoName = argv['repo-name'];
43+
const name = argv.name;
44+
const limit = argv.limit;
45+
const page = argv.page;
2946

3047
let pipelines;
3148
// TODO:need to decide for one way for error handeling
@@ -34,9 +51,19 @@ const command = new Command({
3451
} else if (id) {
3552
pipelines = await pipeline.getPipelineById(id);
3653
} else if (repoOwner && repoName) {
37-
pipelines = await pipeline.getAllByRepo(repoOwner, repoName);
54+
pipelines = await pipeline.getAllByRepo({
55+
repoOwner,
56+
repoName,
57+
name,
58+
limit,
59+
page,
60+
});
3861
} else {
39-
pipelines = await pipeline.getAll();
62+
pipelines = await pipeline.getAll({
63+
name,
64+
limit,
65+
page,
66+
});
4067
}
4168

4269
if (_.isArray(pipelines)) {

lib/logic/api/pipeline.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ const _extractFieldsForPipelineEntity = pipeline => ({
1313
});
1414

1515

16-
const getAll = async () => {
17-
const options = {
16+
const getAll = async (options) => {
17+
const qs = {
18+
name: options.name,
19+
limit: options.limit,
20+
page: options.page - 1,
21+
};
22+
const RequestOptions = {
1823
url: '/api/pipelines',
24+
qs,
1925
method: 'GET',
2026
};
2127

22-
const result = await sendHttpRequest(options);
28+
const result = await sendHttpRequest(RequestOptions);
2329
const pipelines = [];
2430

2531
_.forEach(result, (pipeline) => {
@@ -36,13 +42,19 @@ const getAll = async () => {
3642
* @param repoName
3743
* @returns {Promise<*>}
3844
*/
39-
const getAllByRepo = async (repoOwner, repoName) => {
40-
const options = {
41-
url: `/api/services/${encodeURIComponent(repoOwner)}/${encodeURIComponent(repoName)}`,
45+
const getAllByRepo = async (options) => {
46+
const qs = {
47+
name: options.name,
48+
limit: options.limit,
49+
page: options.page - 1,
50+
};
51+
const RequestOptions = {
52+
url: `/api/services/${encodeURIComponent(options.repoOwner)}/${encodeURIComponent(options.repoName)}`,
53+
qs,
4254
method: 'GET',
4355
};
4456

45-
const result = await sendHttpRequest(options);
57+
const result = await sendHttpRequest(RequestOptions);
4658
const pipelines = [];
4759

4860
_.forEach(result, (pipeline) => {
@@ -68,7 +80,10 @@ const getAllByRepo = async (repoOwner, repoName) => {
6880
* @returns {Promise<*>}
6981
*/
7082
const getPipelineByNameAndRepo = async (name, repoOwner, repoName) => {
71-
const pipelines = await getAllByRepo(repoOwner, repoName);
83+
const pipelines = await getAllByRepo({
84+
repoOwner,
85+
repoName,
86+
});
7287
const currPipeline = _.find(pipelines, pipeline => pipeline.info.name.toString() === name);
7388

7489
if (!currPipeline) {

0 commit comments

Comments
 (0)