Skip to content

Commit

Permalink
command list
Browse files Browse the repository at this point in the history
  • Loading branch information
eromano committed Apr 7, 2016
1 parent 95c0557 commit 50679fe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/slackMessageInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class slackMessageInterface {
this.startChannelMessage();
this.listenerRequestStatusBuild();
this.listenerRepositoryListMessage();
this.listenerCommandListMessage();
}

startChannelMessage() {
Expand Down Expand Up @@ -71,6 +72,9 @@ class slackMessageInterface {
}));
}

/**
* Post a message on slack with the list of all the repositories slug when the bot is asked about it
*/
listenerRepositoryListMessage() {
this.bot.on('message', ((message) => {
if (!this.isFromCiAlarmBotMessage(message) && this.isChatMessage(message) &&
Expand All @@ -84,6 +88,19 @@ class slackMessageInterface {
}));
}

/**
* Post a message on slack with the command list when the bot is asked about it
*/
listenerCommandListMessage() {
this.bot.on('message', ((message) => {
if (!this.isFromCiAlarmBotMessage(message) && this.isChatMessage(message) &&
this.isMentioningCiAlarm(message) && this.isCommandListRequest(message)) {

this.postSlackMessageToChannel('Command list: \n • Repository list \n • build status username/example-project');
}
}));
}

/**
* Post a message in the slack general chat
*
Expand Down Expand Up @@ -136,6 +153,10 @@ class slackMessageInterface {
return message.text && message.text.toLowerCase().indexOf('status') > -1;
}

isCommandListRequest(message) {
return message.text && message.text.toLowerCase().indexOf('command list') > -1;
}

colorByStatus(status) {
var color = this.infoColor;

Expand All @@ -144,7 +165,7 @@ class slackMessageInterface {
} else if (status === 'failed') {
color = this.failColor;
}

return color;
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/slackMessageInterfaceGeneralInfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,19 @@ describe('Bot CI General Travis info communication', function () {
done();
}, 50);
});

it('should the bot respond with the command list if asked "command list" ', function (done) {
this.slackMessageInterface.bot.emit('message', {
username: 'Sonikku',
user: 'C3P0',
type: 'message',
text: '<@' + this.slackMessageInterface.bot.self.id + '>: command list'
});

setTimeout(()=> {
expect(this.textCheck).to.be.equal('Command list: \n • Repository list \n • build status username/example-project');// jscs:ignore maximumLineLength
expect(this.colorMessage).to.be.equal(this.slackMessageInterface.infoColor);
done();
}, 50);
});
});
6 changes: 3 additions & 3 deletions test/travisService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Travis Service', function () {

describe('Event', function () {

describe('Should emit an event', function () {
describe('Should emit an success event', function () {
beforeEach(function () {
this.travisAuthStub = sinon.stub(TravisAuth.prototype, 'login', ()=> {
return new Promise(((resolve) => {
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Travis Service', function () {
});
});

describe('Should emit an event', function () {
describe('Should emit an error event', function () {
beforeEach(function () {
this.travisAuthStub = sinon.stub(TravisAuth.prototype, 'login', ()=> {
return new Promise(((resolve) => {
Expand All @@ -104,7 +104,7 @@ describe('Travis Service', function () {
this.travisGetAccountInfo.restore();
});

it('Should emit an event travis:login:error when the login is NOT ok', function (done) {
it('travis:login:error when the login is NOT ok', function (done) {
var spyEventLoginError = sinon.spy();

this.travisService = new TravisService('fake-github-token');
Expand Down

0 comments on commit 50679fe

Please sign in to comment.