-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from codefresh-io/triggers_commands
update cli to work with trigger-events
- Loading branch information
Showing
12 changed files
with
229 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require('debug')('codefresh:cli:create:trigger-event'); | ||
|
||
const Command = require('../../../Command'); | ||
const { trigger } = require('../../../../../logic').api; | ||
const { prepareKeyValueFromCLIEnvOption } = require('../../../helpers/general'); | ||
const createRoot = require('../../root/create.cmd'); | ||
|
||
const command = new Command({ | ||
command: 'trigger-event', | ||
parent: createRoot, | ||
description: 'Create new `trigger-event`', | ||
webDocs: { | ||
category: 'Triggers', | ||
title: 'Create Trigger Event', | ||
}, | ||
builder: (yargs) => { | ||
yargs | ||
.option('type', { | ||
describe: 'trigger-event type', | ||
require: true, | ||
}) | ||
.option('kind', { | ||
describe: 'trigger-event kind', | ||
}) | ||
.option('secret', { | ||
describe: 'trigger-event secret (omit to auto-generate)', | ||
require: true, | ||
default: '!generate', | ||
}) | ||
.option('value', { | ||
describe: 'trigger-event specific values pairs (key=value), as required by trigger-type', | ||
default: [], | ||
}) | ||
.option('context', { | ||
describe: 'context with credentials required to setup event on remote system', | ||
}) | ||
.example('codefresh create trigger-event --type registry --kind dockerhub --secret XYZ1234 --value namespace=codefresh --value name=fortune --context dockerhub', 'Create registry/dockerhub trigger-event'); | ||
}, | ||
handler: async (argv) => { | ||
const values = prepareKeyValueFromCLIEnvOption(argv.value); | ||
const event = await trigger.createEvent(argv.type, argv.kind, argv.secret, values, argv.context); | ||
console.log(`Trigger event: ${event.uri} was successfully created.`); | ||
}, | ||
}); | ||
|
||
module.exports = command; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require('debug')('codefresh:cli:delete:trigger-event'); | ||
|
||
const Command = require('../../../Command'); | ||
const { trigger } = require('../../../../../logic').api; | ||
const deleteRoot = require('../../root/delete.cmd'); | ||
|
||
const command = new Command({ | ||
command: 'trigger-event [event-uri]', | ||
parent: deleteRoot, | ||
description: 'Delete `trigger-event`', | ||
webDocs: { | ||
category: 'Triggers', | ||
title: 'Delete Trigger Event', | ||
}, | ||
builder: (yargs) => { | ||
yargs | ||
.positional('event-uri', { | ||
describe: 'trigger-event URI', | ||
}) | ||
.option('context', { | ||
describe: 'context with credentials required to setup event on remote system', | ||
}) | ||
.example('codefresh delete trigger-event --context dockerhub registry:dockerhub:codefresh:fortune:push', 'Delete registry/dockerhub trigger-event'); | ||
}, | ||
handler: async (argv) => { | ||
await trigger.deleteEvent(argv['event-uri'], argv.context); | ||
console.log(`Trigger event: ${argv['event-uri']} was successfully deleted.`); | ||
}, | ||
}); | ||
|
||
module.exports = command; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
...erface/cli/commands/trigger/create.cmd.js → ...nterface/cli/commands/trigger/link.cmd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require('debug')('codefresh:cli:delete:trigger'); | ||
|
||
const Command = require('../../Command'); | ||
const { trigger } = require('../../../../logic').api; | ||
|
||
const command = new Command({ | ||
root: true, | ||
command: 'unlink <event-uri> <pipeline> [pipelines...]', | ||
description: 'Undefine trigger(s): unlink pipeline(s) from the specified `trigger-event`', | ||
webDocs: { | ||
category: 'Triggers', | ||
title: 'Remove Pipeline Trigger', | ||
}, | ||
builder: (yargs) => { | ||
yargs | ||
.positional('event-uri', { | ||
describe: '`trigger-event` URI (as defined by trigger `type[/kind]`)', | ||
required: true, | ||
}) | ||
.positional('pipeline', { | ||
describe: 'pipeline ID', | ||
required: true, | ||
}) | ||
.example('codefresh unlink registry:dockerhub:codefresh:fortune:push 5a439664af73ad0001f3ece0', 'Remove trigger by unlinking 5a43... pipeline from the DockerHub `codefresh/fortune` `push` event'); | ||
}, | ||
handler: async (argv) => { | ||
/* eslint-disable prefer-destructuring */ | ||
const event = argv['event-uri']; | ||
const pipelines = [].concat(argv.pipeline).concat(argv.pipelines); | ||
/* eslint-enable prefer-destructuring */ | ||
|
||
await trigger.unlinkPipelinesFromEvent(event, pipelines); | ||
console.log(`Trigger: ${eventURI} was unlinked from the pipeline(s): ${pipelines}`); | ||
}, | ||
}); | ||
|
||
module.exports = command; | ||
|
Oops, something went wrong.