Refactor bb notify and add inprogress#31
Conversation
makes more sense this way
| }, jobInfo, client, function() { /*noop*/ }); | ||
| }; | ||
| var doneListener = function(data) { | ||
| key = data.id ? 'job/' + data.id : ''; |
There was a problem hiding this comment.
Not sure on the keys..need testing.
|
in a few days, if you dont mind |
|
No problem |
|
@knownasilya function resultHandler(client, emitter, jobInfo) {
var key = makeId();
var prepareListener = function (data) {
emitter.removeListener('job.prepare', prepareListener);
notifyBitbucketBuild({
key: key,
url: jobInfo.projectUrl + key,
description: buildState.INPROGRESS,
state: buildState.INPROGRESS
}, jobInfo, client, function() { /*noop*/ });
};
var doneListener = function(data) {
var id = data.id ? 'job/' + data.id : '';
emitter.removeListener('job.done', doneListener);
resultCommentor(client, jobInfo, data, key, id);
};
emitter.on('job.prepare', prepareListener);
emitter.on('job.done', doneListener);
}
function notifyBitbucketBuild(content, jobInfo, client, cb) {
var buildUrl;
if (jobInfo.trigger === 'pullrequestJob') {
buildUrl = API + 'repositories/' + jobInfo.repositoryFullName + '/pullrequests/' + jobInfo.id + '/comments';
} else if (jobInfo.trigger === 'commitJob') {
buildUrl = API2 + 'repositories' + jobInfo.repositoryFullName + 'commit/' + jobInfo.id + '/statuses/build';
}
client.post(buildUrl, content, cb.bind(this, client, jobInfo));
}
function resultCommentor(client, jobInfo, data, key, id) {
var phase = data.phases;
var message;
var state;
if (jobInfo.trigger === 'pullrequestJob') {
if (phase.test.exitCode !== 0) {
message = ':x: ' + buildState.FAILED + ' ' + jobInfo.projectUrl + id;
} else if (phase.deploy.exitCode !== 0) {
message = ':x: ' + buildState.FAILED + ' ' + jobInfo.projectUrl + id;
} else if (phase.test.exitCode === 0 && phase.deploy.exitCode === 0) {
message = ':star: ' + buildState.SUCCESSFUL + ' ' + jobInfo.projectUrl + id;
}
notifyBitbucketBuild({
content: message
}, jobInfo, client, deleteCommentsByAuthor);
} else if (jobInfo.trigger === 'commitJob') {
if (phase.test.exitCode !== 0) {
state = buildState.FAILED;
} else if (phase.deploy.exitCode !== 0) {
state = buildState.FAILED;
} else if (phase.test.exitCode === 0 && phase.deploy.exitCode === 0) {
state = buildState.SUCCESSFUL;
}
notifyBitbucketBuild({
key: key,
url: jobInfo.projectUrl + id,
description: state,
state: state
}, jobInfo, client, function() { /*noop*/ });
}
}
function deleteCommentsByAuthor(client, jobInfo, err, data, res) {
var author = JSON.parse(data).username;
client.get(API2 + 'repositories/' + jobInfo.repositoryFullName + '/pullrequests/' + jobInfo.id + '/comments', function(err, data, res) {
var commentArray = data.values;
commentArray.forEach(function(item, i) {
if (item.user.username === author) {
if (i < commentArray.length -1) {
client.del(API + 'repositories/' + jobInfo.repositoryFullName + '/pullrequests/' + jobInfo.id + '/comments/' + item.id, function () {});
}
}
});
});
}
function makeId() {
return Math.random().toString(36).substr(2, 18);
}it works fine. ps. sorry for that, i really dont want to make new pr |
|
@knownasilya please tell is there some progress with this stuff? looks like i got one more fix, but it would be better to do it after this refactor |
|
Sorry, I haven't had time to update the PR. I can make you a collaborator so you can work on this branch if you want? |
|
I also have some troubles with time but lets try to do it together :) |
In response to #30
WIP.
Would like @nomean42 to test.