Skip to content

Commit

Permalink
fix: API changed in node-jenkins 1.0.0 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
taisukeh authored Mar 28, 2023
1 parent 2fa7f32 commit 66d9295
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class JenkinsExecutor extends Executor {
*/
_jenkinsCommand(options, callback) {
// To pass arguments as an array, we need to use apply
this.jenkinsClient[options.module][options.action].apply(
this.jenkinsClient[options.module],
options.params.concat([callback])
);
this.jenkinsClient[options.module][options.action]
.apply(this.jenkinsClient[options.module], options.params)
.then(result => callback(null, result))
.catch(error => callback(error));
}

/**
Expand All @@ -45,14 +45,14 @@ class JenkinsExecutor extends Executor {
const jobExists = await this.breaker.runCommand({
module: 'job',
action: 'exists',
params: [{ name: jobName }]
params: [jobName]
});
const action = jobExists ? 'config' : 'create';

return this.breaker.runCommand({
module: 'job',
action,
params: [{ name: jobName, xml }]
params: [jobName, xml]
});
}

Expand All @@ -67,7 +67,7 @@ class JenkinsExecutor extends Executor {
const job = await this.breaker.runCommand({
module: 'job',
action: 'get',
params: [{ name: jobName }]
params: [jobName]
});

if (!job) {
Expand All @@ -78,13 +78,13 @@ class JenkinsExecutor extends Executor {
await this.breaker.runCommand({
module: 'queue',
action: 'cancel',
params: [{ number: job.queueItem.id }]
params: [job.queueItem.id]
});
} else if (job.lastBuild && job.lastBuild.number) {
await this.breaker.runCommand({
module: 'build',
action: 'stop',
params: [{ name: jobName, number: job.lastBuild.number }]
params: [jobName, job.lastBuild.number]
});
await this._jenkinsJobWaitStop(jobName, 0);
}
Expand All @@ -106,7 +106,7 @@ class JenkinsExecutor extends Executor {
const job = await this.breaker.runCommand({
module: 'job',
action: 'get',
params: [{ name: jobName }]
params: [jobName]
});

if (job && job.lastCompletedBuild && job.lastCompletedBuild.number) {
Expand Down Expand Up @@ -328,7 +328,7 @@ class JenkinsExecutor extends Executor {
return this.breaker.runCommand({
module: 'job',
action: 'destroy',
params: [{ name: jobName }]
params: [jobName]
});
}

Expand Down
23 changes: 10 additions & 13 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,19 @@ describe('index', () => {
createOpts = {
module: 'job',
action: 'create',
params: [{ name: jobName, xml: fakeXml }]
params: [jobName, fakeXml]
};

configOpts = {
module: 'job',
action: 'config',
params: [{ name: jobName, xml: fakeXml }]
params: [jobName, fakeXml]
};

existsOpts = {
module: 'job',
action: 'exists',
params: [{ name: jobName }]
params: [jobName]
};

buildOpts = {
Expand Down Expand Up @@ -349,19 +349,19 @@ describe('index', () => {
getOpts = {
module: 'job',
action: 'get',
params: [{ name: jobName }]
params: [jobName]
};

stopOpts = {
module: 'build',
action: 'stop',
params: [{ name: jobName, number: buildNumber }]
params: [jobName, buildNumber]
};

destroyOpts = {
module: 'job',
action: 'destroy',
params: [{ name: jobName }]
params: [jobName]
};
});

Expand Down Expand Up @@ -773,15 +773,12 @@ rm -f docker-compose.yml
});

it('calls jenkins function correctly', done => {
jenkinsMock.job.exists.yieldsAsync(null, false);
jenkinsMock.job.create.yieldsAsync(null);
jenkinsMock.job.build.yieldsAsync(null);
jenkinsMock.job.exists.resolves(false);
jenkinsMock.job.create.resolves(null);
jenkinsMock.job.build.resolves(null);

executor.start(config).then(() => {
assert.calledWith(jenkinsMock.job.create, {
name: jobName,
xml: fakeXml
});
assert.calledWith(jenkinsMock.job.create, jobName, fakeXml);
assert.calledWith(jenkinsMock.job.build, {
name: jobName,
parameters: buildParams
Expand Down

0 comments on commit 66d9295

Please sign in to comment.