Skip to content

Commit 9d26c42

Browse files
authored
add filter to 'create trigger' command (#180)
1 parent e3c6771 commit 9d26c42

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

lib/interface/cli/commands/trigger/create.cmd.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
require('debug')('codefresh:cli:create:trigger');
22

33
const Command = require('../../Command');
4-
const createRoot = require('../root/create.cmd')
4+
const createRoot = require('../root/create.cmd');
5+
const { prepareKeyValueFromCLIEnvOption } = require('../../helpers/general');
56
const { trigger } = require('../../../../logic').api;
67

78
const command = new Command({
@@ -16,6 +17,10 @@ const command = new Command({
1617
},
1718
builder: (yargs) => {
1819
yargs
20+
.option('filter', {
21+
describe: 'trigger filter `name=condition` pairs',
22+
default: [],
23+
})
1924
.positional('event-uri', {
2025
describe: '`trigger-event` URI',
2126
require: true,
@@ -31,7 +36,8 @@ const command = new Command({
3136
const pipeline = argv.pipeline;
3237
const eventURI = argv['event-uri'];
3338
/* eslint-enable prefer-destructuring */
34-
await trigger.createTrigger(eventURI, pipeline);
39+
const filters = prepareKeyValueFromCLIEnvOption(argv.filter);
40+
await trigger.createTrigger(eventURI, pipeline, filters);
3541
console.log(`Trigger: ${eventURI} was successfully linked to the pipeline: ${pipeline}`);
3642
},
3743
});

lib/logic/api/trigger.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const _extractTriggerEventEntity = triggerEvent => ({
2828
const _extractTriggerEntity = trigger => ({
2929
event: trigger.event,
3030
pipeline: trigger.pipeline,
31+
filters: trigger.filters,
3132
});
3233

3334
// TRIGGER TYPES
@@ -114,10 +115,13 @@ const getEventTriggers = async (event) => {
114115
return triggers;
115116
};
116117

117-
const createTrigger = async (event, pipeline) => {
118+
const createTrigger = async (event, pipeline, filters) => {
118119
const options = {
119120
url: `/api/hermes/triggers/${event.replace('/', '_slash_')}/${pipeline}`,
120121
method: 'POST',
122+
body: {
123+
filters,
124+
},
121125
};
122126

123127
return sendHttpRequest(options);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.8.40",
3+
"version": "0.8.41",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)