Permalink
Browse files

Rename job-related commands, extract job-related functions from cli a…

…nd jenkins to relevant handlers.
  • Loading branch information...
1 parent bc9240e commit 0a362c87c768610afb6b54abe10d4520bdb27753 @cliffano committed Feb 19, 2014
Showing with 287 additions and 297 deletions.
  1. +7 −0 CHANGELOG.md
  2. +29 −29 conf/commands.json
  3. +11 −72 lib/cli.js
  4. +97 −0 lib/cli/job.js
  5. +1 −1 lib/cli/view.js
  6. +11 −188 lib/jenkins.js
  7. +124 −0 lib/jenkins/job.js
  8. +7 −7 test/cli.js
View
@@ -1,5 +1,12 @@
### 0.2.4-pre
* Add create-view, update-view, and fetch-view-config commands
+* Rename create command to create-job
+* Rename update command to update-job
+* Rename enable command to enable-job
+* Rename disable command to disable-job
+* Rename copy command to copy-job
+* Rename delete command to delete-job
+* Rename config command to fetch-job-config
### 0.2.3
* Add enable and disable commands
View
@@ -56,70 +56,70 @@
{ "name": "job", "rules": [ "notEmpty" ] }
]
},
- "enable": {
- "desc": "Enable a job",
+ "create-job": {
+ "desc": "Create a new job with specified config.xml",
"args": [
- { "name": "job", "rules": [ "notEmpty" ] }
+ { "name": "job", "rules": [ "notEmpty" ] },
+ { "name": "config", "rules": [ "notEmpty" ] }
],
"examples": [
- "nestor enable <job>"
+ "nestor create-job <job> <path/to/config.xml>"
]
},
- "disable": {
- "desc": "Disable a job",
+ "update-job": {
+ "desc": "Update an existing job with specified config.xml",
"args": [
- { "name": "job", "rules": [ "notEmpty" ] }
+ { "name": "job", "rules": [ "notEmpty" ] },
+ { "name": "config", "rules": [ "notEmpty" ] }
],
"examples": [
- "nestor disable <job>"
+ "nestor update-job <job> <path/to/config.xml>"
]
},
- "create": {
- "desc": "Create a new job with specified config.xml",
+ "delete-job": {
+ "desc": "Delete an existing job",
"args": [
- { "name": "job", "rules": [ "notEmpty" ] },
- { "name": "config", "rules": [ "notEmpty" ] }
+ { "name": "job", "rules": [ "notEmpty" ] }
],
"examples": [
- "nestor create <job> <path/to/config.xml>"
+ "nestor delete-job <job>"
]
},
- "update": {
- "desc": "Update an existing job with specified config.xml",
+ "enable-job": {
+ "desc": "Enable a job",
"args": [
- { "name": "job", "rules": [ "notEmpty" ] },
- { "name": "config", "rules": [ "notEmpty" ] }
+ { "name": "job", "rules": [ "notEmpty" ] }
],
"examples": [
- "nestor update <job> <path/to/config.xml>"
+ "nestor enable-job <job>"
]
},
- "copy": {
- "desc": "Copy an existing job",
+ "disable-job": {
+ "desc": "Disable a job",
"args": [
- { "name": "job1", "rules": [ "notEmpty" ] },
- { "name": "job2", "rules": [ "notEmpty" ] }
+ { "name": "job", "rules": [ "notEmpty" ] }
],
"examples": [
- "nestor copy <job1> <job2>"
+ "nestor disable-job <job>"
]
},
- "delete": {
- "desc": "Delete an existing job",
+ "copy-job": {
+ "desc": "Copy an existing job",
"args": [
- { "name": "job", "rules": [ "notEmpty" ] }
+ { "name": "job1", "rules": [ "notEmpty" ] },
+ { "name": "job2", "rules": [ "notEmpty" ] }
],
"examples": [
- "nestor delete <job>"
+ "nestor copy-job <job1> <job2>"
]
},
- "config": {
+ "fetch-job-config": {
"desc": "Fetch the config.xml of an existing job",
"args": [
{ "name": "job", "rules": [ "notEmpty" ] }
],
"examples": [
- "nestor config <job>"
+ "nestor fetch-job-config <job>"
]
},
"create-view": {
View
@@ -15,6 +15,8 @@ var _ = require('lodash'),
NinjaBlocks = require('./notifiers/ninjablocks'),
text = require('bagoftext'),
_url = require('url');
+
+var job = require('./cli/job');
var view = require('./cli/view');
function __exec(args, cb) {
@@ -171,69 +173,6 @@ function _job(name, args) {
__exec(args, execCb);
}
-function _enable(job, configFile, args) {
- function execCb(jenkins) {
- jenkins.enable(job, cli.exitCb(null, function (result) {
- console.log(text.__('Job %s was enabled successfully'), job);
- }));
- }
- __exec(args, execCb);
-}
-
-function _disable(job, configFile, args) {
- function execCb(jenkins) {
- jenkins.disable(job, cli.exitCb(null, function (result) {
- console.log(text.__('Job %s was disabled successfully'), job);
- }));
- }
- __exec(args, execCb);
-}
-
-function _create(job, configFile, args) {
- function execCb(jenkins) {
- jenkins.create(job, configFile, cli.exitCb(null, function (result) {
- console.log(text.__('Job %s was created successfully'), job);
- }));
- }
- __exec(args, execCb);
-}
-
-function _update(job, configFile, args) {
- function execCb(jenkins) {
- jenkins.update(job, configFile, cli.exitCb(null, function (result) {
- console.log(text.__('Job %s was updated successfully'), job);
- }));
- }
- __exec(args, execCb);
-}
-
-function _copy(sourceJob, newJob, args) {
- function execCb(jenkins) {
- jenkins.copy(sourceJob, newJob, cli.exitCb(null, function (result) {
- console.log(text.__('Job %s was copied to job %s'), sourceJob, newJob);
- }));
- }
- __exec(args, execCb);
-}
-
-function _delete(job, args) {
- function execCb(jenkins) {
- jenkins.delete(job, cli.exitCb(null, function (result) {
- console.log(text.__('Job %s was deleted successfully'), job);
- }));
- }
- __exec(args, execCb);
-}
-
-function _config(job, args) {
- function execCb(jenkins) {
- jenkins.config(job, cli.exitCb(null, function (result) {
- console.log(result);
- }));
- }
- __exec(args, execCb);
-}
-
function _queue(args) {
function execCb(jenkins) {
jenkins.queue(cli.exitCb(null, function (result) {
@@ -328,15 +267,15 @@ function exec() {
discover: { action: _discover },
executor: { action: _executor },
job: { action: _job },
- enable: { action: _enable },
- disable: { action: _disable },
- create: { action: _create },
- update: { action: _update },
- copy: { action: _copy },
- 'delete': { action: _delete },
- config: { action: _config },
- 'create-view': { action: view.create(__exec) },
- 'update-view': { action: view.update(__exec) },
+ 'create-job' : { action: job.create(__exec) },
+ 'update-job' : { action: job.update(__exec) },
+ 'enable-job' : { action: job.enable(__exec) },
+ 'disable-job' : { action: job.disable(__exec) },
+ 'copy-job' : { action: job.copy(__exec) },
+ 'delete-job' : { action: job.delete(__exec) },
+ 'fetch-job-config' : { action: job.fetchConfig(__exec) },
+ 'create-view' : { action: view.create(__exec) },
+ 'update-view' : { action: view.update(__exec) },
'fetch-view-config': { action: view.fetchConfig(__exec) },
queue: { action: _queue },
ver: { action: _version },
View
@@ -0,0 +1,97 @@
+var cli = require('bagofcli');
+var fs = require('fs');
+var text = require('bagoftext');
+
+function create(cb) {
+ return function (name, configFile, args) {
+ function resultCb(result) {
+ console.log(text.__('Job %s was created successfully'), name);
+ }
+ function jenkinsCb(jenkins) {
+ var config = fs.readFileSync(configFile).toString();
+ jenkins.createJob(name, config, cli.exitCb(null, resultCb));
+ }
+ cb(args, jenkinsCb);
+ };
+}
+
+function update(cb) {
+ return function (name, configFile, args) {
+ function resultCb(result) {
+ console.log(text.__('Job %s was updated successfully'), name);
+ }
+ function jenkinsCb(jenkins) {
+ var config = fs.readFileSync(configFile).toString();
+ jenkins.updateJob(name, config, cli.exitCb(null, resultCb));
+ }
+ cb(args, jenkinsCb);
+ };
+}
+
+function _delete(cb) {
+ return function (name, args) {
+ function resultCb(result) {
+ console.log(text.__('Job %s was deleted successfully'), name);
+ }
+ function jenkinsCb(jenkins) {
+ jenkins.deleteJob(name, cli.exitCb(null, resultCb));
+ }
+ cb(args, jenkinsCb);
+ };
+}
+
+function enable(cb) {
+ return function (name, args) {
+ function resultCb(result) {
+ console.log(text.__('Job %s was enabled successfully'), name);
+ }
+ function jenkinsCb(jenkins) {
+ jenkins.enableJob(name, cli.exitCb(null, resultCb));
+ }
+ cb(args, jenkinsCb);
+ };
+}
+
+function disable(cb) {
+ return function (name, args) {
+ function resultCb(result) {
+ console.log(text.__('Job %s was disabled successfully'), name);
+ }
+ function jenkinsCb(jenkins) {
+ jenkins.disableJob(name, cli.exitCb(null, resultCb));
+ }
+ cb(args, jenkinsCb);
+ };
+}
+
+function copy(cb) {
+ return function (existingName, newName, args) {
+ function resultCb(result) {
+ console.log(text.__('Job %s was copied to job %s'), existingName, newName);
+ }
+ function jenkinsCb(jenkins) {
+ jenkins.copyJob(existingName, newName, cli.exitCb(null, resultCb));
+ }
+ cb(args, jenkinsCb);
+ };
+}
+
+function fetchConfig(cb) {
+ return function (name, args) {
+ function resultCb(result) {
+ console.log(result);
+ }
+ function jenkinsCb(jenkins) {
+ jenkins.fetchJobConfig(name, cli.exitCb(null, resultCb));
+ }
+ cb(args, jenkinsCb);
+ };
+}
+
+exports.create = create;
+exports.update = update;
+exports.delete = _delete;
+exports.enable = enable;
+exports.disable = disable;
+exports.copy = copy;
+exports.fetchConfig = fetchConfig;
View
@@ -29,7 +29,7 @@ function update(cb) {
}
function fetchConfig(cb) {
- return function (name, configFile, args) {
+ return function (name, args) {
function resultCb(result) {
console.log(result);
}
Oops, something went wrong. Retry.

0 comments on commit 0a362c8

Please sign in to comment.