Skip to content

Commit

Permalink
Merge pull request #19 from hubot-js/development
Browse files Browse the repository at this point in the history
Version 2.1.0
  • Loading branch information
robsonbittencourt authored May 27, 2017
2 parents d7c0ee8 + 8ac67cc commit 285d028
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: node_js

node_js:
- 7.1.0
- 7.7.2

script:
- npm run lint
- npm test

after_success:
- npm run coveralls
Expand Down
16 changes: 8 additions & 8 deletions config/categories.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
{
"key": "jenkins",
"name": "Jenkins Jobs",
"description": "To use Jenkins jobs use the following commands:",
"visible": true
}
]
[
{
"key": "jenkins",
"name": "jenkins:categories.name",
"description": "jenkins:categories.description",
"visible": true
}
]
14 changes: 7 additions & 7 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
[
{
"speak": "Okay, I'll ask you some questions. If you need more details <https://github.com/hubot-js/gear-jenkins#configurations|*click here*>."
"speak": "jenkins:configuration.start"
},

{
"speak": "_*Do you use Jenkins with authentication?*_",
"speak": "jenkins:configuration.firstQuestion",
"expectedResponses": [
{
"response": "Yes",
"response": "jenkins:yes",
"iteration": {
"speak": "_*What is the Jenkins url?*_ The url should have this format: http://user:authToken@jenkinsUrl. \nIf you do not want to make this setting now, keeping the current value, type *skip*.",
"speak": "jenkins:configuration.url.question.auth",
"handler": "src/configHandler/url-handler"
}
},

{
"response": "No",
"response": "jenkins:no",
"iteration": {
"speak": "_*What is the Jenkins url?*_ Just use the Jenkins access url. \nIf you do not want to make this setting now, keeping the current value, type *skip*.",
"speak": "jenkins:configuration.url.question.noAuth",
"handler": "src/configHandler/url-handler"
}
}
]
},

{
"speak": "All right. Jenkins configured."
"speak": "jenkins:configuration.allright"
}
]
22 changes: 11 additions & 11 deletions config/tasks.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[
{
"trigger": "hubot start job $",
"handler": "start-job",
"category": "jenkins",
"description": "To start a job use the command next to replacing $ by job name.",
"options": {
"message": "<!channel|channel> Alright. I'll start the job"
}
}
]
[
{
"trigger": "jenkins:tasks.trigger",
"handler": "start-job",
"category": "jenkins",
"description": "jenkins:tasks.description",
"options": {
"message": "jenkins:tasks.options.message"
}
}
]
36 changes: 36 additions & 0 deletions locales/en-US/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"notFoundedJob": "Sorry I could not find the job *{{job}}*",
"errorOnStartJob": "Sorry I could not start the job *{{job}}*. See the error in the logs.",
"configuration": {
"start": "Okay, I'll ask you some questions. If you need more details <https://github.com/hubot-js/gear-jenkins#configurations|*click here*>.",
"firstQuestion": "_*Do you use Jenkins with authentication?*_",
"url": {
"question": {
"auth": "_*What is the Jenkins url?*_ The url should have this format: http://user:authToken@jenkinsUrl. \nIf you do not want to make this setting now, keeping the current value, type *skip*.",
"noAuth": "_*What is the Jenkins url?*_ Just use the Jenkins access url. \nIf you do not want to make this setting now, keeping the current value, type *skip*."
},
"responds": "Url responds. Apparently everything is alright. :champagne:",
"notResponds": "I could not check the url. Something is wrong. :disappointed: Check if the url is correct."
},
"skip": "skip",
"allright": "All right. Jenkins configured."
},
"log": {
"error": {
"onCall": "Error on call Jenkins"
}
},
"yes": "Yes",
"no": "No",
"categories": {
"name": "Jenkins Jobs",
"description": "To use Jenkins jobs use the following commands:"
},
"tasks": {
"trigger": "start job $",
"description": "To start a job use the command next to replacing $ by job name.",
"options": {
"message": "<!channel|channel> Alright. I'll start the job"
}
}
}
36 changes: 36 additions & 0 deletions locales/pt-BR/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"notFoundedJob": "Desculpe não consegui encontrar o job *{{job}}*",
"errorOnStartJob": "Desculpa não consegui iniciar o job *{{job}}*. Veja o erro nos logs.",
"configuration": {
"start": "Certo, eu vou lhe fazer algumas perguntas. Se você precisar de mais detalhes <https://github.com/hubot-js/gear-jenkins#configurations|*clique aqui*>.",
"firstQuestion": "_*Você usa o Jenkins com autenticação?*_",
"url": {
"question": {
"auth": "_*Qual é a sua url do Jenkins?*_ A url deve ter este formato: http://usuario:tokenDeAutenticacao@jenkinsUrl. \nSe você não quiser fazer esta configuração agora, mantendo o valor atual, digite *pular*.",
"noAuth": "_*Qual é a sua url do Jenkins?*_ Simplesmente use a sua url de acesso ao Jenkins. \nSe você não quiser fazer esta configuração agora, mantendo o valor atual, digite *pular*."
},
"responds": "A url responde. Aparentemente está tudo certo. :champagne:",
"notResponds": "Eu não consegui verificar a url. Algo está errado. :disappointed: Verifique se a url está correta."
},
"skip": "pular",
"allright": "Tudo certo. Jenkins configurado."
},
"log": {
"error": {
"onCall": "Erro ao chamar o Jenkins"
}
},
"yes": "Sim",
"no": "Não",
"categories": {
"name": "Jenkins Jobs",
"description": "Para usar os jobs do Jenkins utilize os seguintes comandos:"
},
"tasks": {
"trigger": "iniciar job $",
"description": "Para iniciar um job use o comando a seguir substituindo $ pelo nome do job.",
"options": {
"message": "<!channel|channel> Tudo certo. Eu vou iniciar o job"
}
}
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gear-jenkins",
"version": "2.0.0",
"version": "2.1.0",
"description": "A Hubot Gear for handle Jenkins tasks",
"main": "/src/jenkins.js",
"scripts": {
Expand All @@ -26,20 +26,20 @@
"homepage": "https://github.com/hubot-js/gear-jenkins#readme",
"dependencies": {
"jenkins": "^0.20.0",
"sqlite": "^2.2.3",
"q": "^1.4.1",
"request-promise": "^4.1.1"
"sqlite": "^2.8.0",
"q": "^2.0.3",
"request-promise": "^4.2.1"
},
"devDependencies": {
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"sinon": "^1.17.6",
"sinon-as-promised": "4.0.2",
"mocha": "^3.2.0",
"proxyquire": "^1.7.10",
"sinon": "^1.17.7",
"sinon-as-promised": "^4.0.3",
"mocha": "^3.4.1",
"proxyquire": "^1.8.0",
"istanbul": "^0.4.5",
"coveralls": "^2.11.15",
"eslint": "^3.11.1",
"coveralls": "^2.13.1",
"eslint": "^3.19.0",
"eslint-config-hubot-js": "^1.0.4"
}
}
8 changes: 4 additions & 4 deletions src/configHandler/url-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ const request = require('request-promise');

exports.handle = handle;

function handle(awnser) {
function handle(hubot, awnser) {
const deferred = Q.defer();

if (awnser === 'skip') {
if (awnser === hubot.i18n('jenkins:configuration.skip')) {
deferred.resolve();
return deferred.promise;
}

const url = getUrl(awnser);
const successMessage = 'Url responds. Apparently everything is alright. :champagne:';
const errorMessage = 'I could not check the url. Something is wrong. :disappointed: Check if the url is correct.';
const successMessage = 'jenkins:configuration.url.responds';
const errorMessage = 'jenkins:configuration.url.notResponds';

db.getDb().then(database => database.run('UPDATE config SET url = ?', url));

Expand Down
6 changes: 3 additions & 3 deletions src/handlers/start-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function start(hubot, message, task, job) {
hubot.speak(message, task.options.message);
}, (error) => {
if (error.notFound) {
hubot.speak(message, `Sorry I could not find the job *${job}*`);
hubot.speak(message, 'jenkins:notFoundedJob', { job });
} else {
hubot.logDetailedError('Error on call Jenkins', error);
hubot.speak(message, `Sorry I could not start the job *${job}*. See the error in the logs.`);
hubot.logDetailedError('jenkins:log.error.onCall', error);
hubot.speak(message, 'jenkins:errorOnStartJob', { job });
}
});
}
22 changes: 15 additions & 7 deletions test/configHandlers/url-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ describe('Handle with url configuration', () => {
let dbStub;
let requestStub;

const hubot = {
i18n() {}
};

const hubotStub = sinon.stub(hubot, 'i18n');

beforeEach(() => {
const runStub = sinon.stub().resolves();
runSpy = sinon.spy(runStub);
Expand All @@ -28,7 +34,7 @@ describe('Handle with url configuration', () => {
const urlHandler = getUrlHandler(dbStub, requestStub);
const url = '<http://www.jenkins.com|www.jenkins.com>';

return urlHandler.handle(url).then(() => {
return urlHandler.handle(hubot, url).then(() => {
expect(runSpy.calledWithExactly('UPDATE config SET url = ?', 'http://www.jenkins.com')).to.be.true;
});
});
Expand All @@ -37,32 +43,32 @@ describe('Handle with url configuration', () => {
const urlHandler = getUrlHandler(dbStub, requestStub);
const url = '<http://jenkins.com>';

return urlHandler.handle(url).then(() => {
return urlHandler.handle(hubot, url).then(() => {
expect(runSpy.calledWithExactly('UPDATE config SET url = ?', 'http://jenkins.com')).to.be.true;
});
});
});

describe('Verify informed url', () => {
it('and return error message when url do not respond', () => {
const errorMessage = 'I could not check the url. Something is wrong. :disappointed: Check if the url is correct.';
const errorMessage = 'jenkins:configuration.url.notResponds';

requestStub = sinon.stub().rejects(errorMessage);

const urlHandler = getUrlHandler(dbStub, requestStub);

const promise = urlHandler.handle('url');
const promise = urlHandler.handle(hubot, 'url');

return expect(promise).to.be.rejectedWith(errorMessage);
});

it('and return success message when url respond', () => {
const successMessage = 'Url responds. Apparently everything is alright. :champagne:';
const successMessage = 'jenkins:configuration.url.responds';
requestStub = sinon.stub().resolves(successMessage);

const urlHandler = getUrlHandler(dbStub, requestStub);

const promise = urlHandler.handle('url');
const promise = urlHandler.handle(hubot, 'url');

return expect(promise).to.be.eventually.equal(successMessage);
});
Expand All @@ -72,7 +78,9 @@ describe('Handle with url configuration', () => {
it('when get skip word and do not save config', () => {
const csrfHandler = getUrlHandler(dbStub, requestStub);

const promise = csrfHandler.handle('skip').then(() => {
hubotStub.withArgs('jenkins:configuration.skip').returns('skip');

const promise = csrfHandler.handle(hubot, 'skip').then(() => {
expect(runSpy.called).to.be.false;
});

Expand Down
7 changes: 3 additions & 4 deletions test/handlers/start-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Call job', () => {
const startJob = getStartJob(callJobStub);

return startJob.handle(hubot, message, task, ['deploy-job']).then(() => {
expect(speakSpy.calledWith(message, 'Sorry I could not find the job *deploy-job*')).to.be.true;
expect(speakSpy.calledWith(message, 'jenkins:notFoundedJob')).to.be.true;
});
});
});
Expand All @@ -70,8 +70,7 @@ describe('Call job', () => {
const startJob = getStartJob(callJobStub);

return startJob.handle(hubot, message, task, ['deploy-job']).then(() => {
expect(speakSpy.calledWith(message,
'Sorry I could not start the job *deploy-job*. See the error in the logs.')).to.be.true;
expect(speakSpy.calledWith(message, 'jenkins:errorOnStartJob')).to.be.true;
});
});

Expand All @@ -81,7 +80,7 @@ describe('Call job', () => {
const startJob = getStartJob(callJobStub);

return startJob.handle(hubot, message, task, ['deploy-job']).then(() => {
expect(logDetailedErrorSpy.calledWith('Error on call Jenkins', error)).to.be.true;
expect(logDetailedErrorSpy.calledWith('jenkins:log.error.onCall', error)).to.be.true;
});
});
});
Expand Down

0 comments on commit 285d028

Please sign in to comment.