Skip to content

Commit

Permalink
add filter to 'create trigger' command (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexei-led authored Mar 25, 2018
1 parent e3c6771 commit 9d26c42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/interface/cli/commands/trigger/create.cmd.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require('debug')('codefresh:cli:create:trigger');

const Command = require('../../Command');
const createRoot = require('../root/create.cmd')
const createRoot = require('../root/create.cmd');
const { prepareKeyValueFromCLIEnvOption } = require('../../helpers/general');
const { trigger } = require('../../../../logic').api;

const command = new Command({
Expand All @@ -16,6 +17,10 @@ const command = new Command({
},
builder: (yargs) => {
yargs
.option('filter', {
describe: 'trigger filter `name=condition` pairs',
default: [],
})
.positional('event-uri', {
describe: '`trigger-event` URI',
require: true,
Expand All @@ -31,7 +36,8 @@ const command = new Command({
const pipeline = argv.pipeline;
const eventURI = argv['event-uri'];
/* eslint-enable prefer-destructuring */
await trigger.createTrigger(eventURI, pipeline);
const filters = prepareKeyValueFromCLIEnvOption(argv.filter);
await trigger.createTrigger(eventURI, pipeline, filters);
console.log(`Trigger: ${eventURI} was successfully linked to the pipeline: ${pipeline}`);
},
});
Expand Down
6 changes: 5 additions & 1 deletion lib/logic/api/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const _extractTriggerEventEntity = triggerEvent => ({
const _extractTriggerEntity = trigger => ({
event: trigger.event,
pipeline: trigger.pipeline,
filters: trigger.filters,
});

// TRIGGER TYPES
Expand Down Expand Up @@ -114,10 +115,13 @@ const getEventTriggers = async (event) => {
return triggers;
};

const createTrigger = async (event, pipeline) => {
const createTrigger = async (event, pipeline, filters) => {
const options = {
url: `/api/hermes/triggers/${event.replace('/', '_slash_')}/${pipeline}`,
method: 'POST',
body: {
filters,
},
};

return sendHttpRequest(options);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.8.40",
"version": "0.8.41",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit 9d26c42

Please sign in to comment.