Skip to content

Commit

Permalink
unknown status repo
Browse files Browse the repository at this point in the history
  • Loading branch information
eromano committed Apr 6, 2016
1 parent 666b1ba commit 95c0557
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/slackMessageInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ class slackMessageInterface {

if (repoName) {
this.ciService.getLastBuildStatusByRepository(repoName).then((statusBuild)=> {
statusBuild = statusBuild ? statusBuild : 'unknown';
this.postSlackMessageToChannel('Hi <@' + message.user + '> the build Status is ' + statusBuild + '!', 'Ci status', this.colorByStatus(statusBuild));
},(error)=> {
}, (error)=> {
this.postSlackMessageToChannel(error.toString(), 'Ci status', this.failColor);
});
}else {
} else {
this.postSlackMessageToChannel('Maybe you want use the command : "status username/example-project" but you forgot to add the repository slug', 'Ci status', this.infoColor);// jscs:ignore maximumLineLength
}
}
Expand Down Expand Up @@ -112,7 +113,7 @@ class slackMessageInterface {

getRepositoriesNameInMessage(message) {
var statusPos = message.text.toLowerCase().indexOf('status');
var afterStatus = message.text.toLowerCase().substr(statusPos + 6,message.length);
var afterStatus = message.text.toLowerCase().substr(statusPos + 6, message.length);
var allPhrasesSeparateBySpace = afterStatus.split(' ');
if (allPhrasesSeparateBySpace && allPhrasesSeparateBySpace.length > 1) {
return allPhrasesSeparateBySpace[1].trim();
Expand All @@ -136,14 +137,14 @@ class slackMessageInterface {
}

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

if (status === 'passed') {
color = this.successColor;
} else if (status === 'failed') {
color = this.failColor;
} else {
color = this.infoColor;
}

return color;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/mockObjects/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class repository {
return [
this.createRepository({slug: 'fakeuser/fake-project1'}),
this.createRepository({slug: 'fakeuser/fake-project2', last_build_state: 'failed'}),
this.createRepository({slug: 'fakeuser/fake-project3'})
this.createRepository({slug: 'fakeuser/fake-project3', last_build_state: ''})
];
}

Expand Down
21 changes: 21 additions & 0 deletions test/slackMessageInterfaceBotStatusNotify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,25 @@ describe('Bot CI build communication', function () {

});

it('should the bot respond with the Unknown Build status if asked "build status" and travis not ha this repo in the CI', function (done) {
var repos = Repository.createRepositoriesList();
nock('https://api.travis-ci.org:443')
.get('/repos/mbros')
.reply(200, {repos});

this.slackMessageInterface.bot.emit('message', {
username: 'Sonikku',
user: 'C3P0',
type: 'message',
text: '<@' + this.slackMessageInterface.bot.self.id + '>: status fakeuser/fake-project3'
});

setTimeout(()=> {
expect(this.textCheck).to.be.equal('Hi <@C3P0> the build Status is unknown!');
expect(this.colorMessage).to.be.equal(this.slackMessageInterface.infoColor);
done();
}, 50);

});

});

0 comments on commit 95c0557

Please sign in to comment.