finndropstudios / bitrocket Goto Github PK
View Code? Open in Web Editor NEWBitBucket Integration for Rocket.Chat
BitBucket Integration for Rocket.Chat
Would this extension recognize pushed tag to notify Rocket chat ?
Hello guys!
I'm trying to integrate this into a Rocket Chat instance but I got the following error in Rocket chat logs:
rocketchat_logger rocketchat_logger.js:278 �[31mIntegrations ➔ Incoming WebHook.error script.js:1 function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var config={bitBucketUrl:"https://bitbucket.org/XXXX/YYYYYY",color:"#225159",update:true};var bitBucketUpdate=function(request,i){var text="New "+request.content.refChanges[i].type.toLowerCase()+" on project "+request.content.repository.project.name;var username=request.content.changesets.values[i].toCommit.author.name;var usermail=request.content.changesets.values[i].toCommit.author.emailAddress;var attachment={author_name:username+" ("+usermail+")",title:"Repository \""+request.content.repository.name+"\" in project \""+request.content.repository.project.name+"\" updated",title_link:config["bitBucketUrl"].replace(/\/$/,"")+"/projects/"+request.content.repository.project.key+"/repos/"+request.content.repository.slug+"/browse/",text:username+" updated "+request.content.changesets.values[i].changes.size+(request.content.changeset TypeError: Cannot read property 'forEach' of undefined at Script.process_incoming_request (script.js:1:1531) at evalmachine.<anonymous>:1:8 at ContextifyScript.Script.runInContext (vm.js:59:29) at ContextifyScript.Script.runInNewContext (vm.js:65:15) at Object.runInNewContext (vm.js:135:38) at Object.executeIntegrationRest [as action] (meteor://💻app/packages/rocketchat_integrations.js:2384:22) at Route.share.Route.Route._callEndpoint (meteor://💻app/packages/nimble_restivus.js:358:32) at meteor://💻app/packages/nimble_restivus.js:247:33 at packages/simple_json-routes.js:98:9
At Bitbucket webhook status is success. I think there is a bug on the bitbucket_5_6_native-webhook.js script.
Have you any idea about that?
Thank you
Hello,
I am trying to integrate this script into our rocketchat server and bitbucket server, The configuration looks Ok, but in the Bitbucket logs, I see this:
"POST /scm/px/pxoc.git/git-receive-pack HTTP/1.1" c.a.b.p.h.i.RequestFactoryWebHookProcessorWorker Invalid response from hook 'http://rocketserver:3000/hooks/DAFGaz495ZDcPSjdY/Mpbrm9tSJXikdTaoND5YRcCuHugvuAyxzPrb7QiyTqPNYHWr', repository ID '71', status: '415' / 'Unsupported Media Type'
I turn on debug level on the rocketchat server and dont see anything in the logs.
Any suggestions?
Thanks,
Guru
Is there any plan on adding pull request notifications in to the bitbucket server script.
Configure Bitbucket Server 4.9
Insert script in trigger integration
but give error
[34mI20160922-18:02:09.885(3) rocketchat_integrations api.coffee:167 �[31mIntegrations ➔ Incoming WebHook.error function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var config={bitBucketUrl:'',color:'#225159',update:true};var bitBucketUpdate=function bitBucketUpdate(request,i){var text='New '+request.content.refChanges[i].type.toLowerCase()+' on project '+request.content.repository.project.name;var username=request.content.changesets.values[i].toCommit.author.name;var usermail=request.content.changesets.values[i].toCommit.author.emailAddress;var attachment={author_name:username+' ('+usermail+')',title:'Repository "'+request.content.repository.name+'" in project "'+request.content.repository.project.name+'" updated',title_link:config['bitBucketUrl'].replace(//$/,'')+'/projects/'+request.content.repository.project.key+'/repos/'+request.content.repository.slug+'/browse/',text:username+' updated '+request.content.changesets.values[i].changes.size+(request.content.changesets.values[i].changes.size>1?' files':' file')+' on branch '+request.content.refChanges[i].refId+'` with message:
"'+request.content.changesets.values[i].toCommit.message+'"',color:config['color']!=''?'#'+config['color'].replace('#',''):'#225159'};return{content:{text:text,attachments:[attachment]}}};var Script=function(){function Script(){_classCallCheck(this,Script)}Script.prototype.process_incoming_request=function process_incoming_request(_ref){var request=_ref.request;var result={};request.content.refChanges.forEach(function(change,i){if(config[change.type.toLowerCase()]){switch(change.type){case'UPDATE':result=bitBucketUpdate(request,i);}}});if(result.content!==undefined){return result}};return Script}();
Bitbucket Server 5.11.1
After install BitRocket on rocket channel I receive messages, like:
@username
On repository reponame: empty
UPDATE commitlnik
JSON example:
{"eventKey":"repo:refs_changed","date":"2018-07-02T11:17:33+0300","actor":{"name":"user","emailAddress":"[email protected]","id":253,"displayName":"Username","active":true,"slug":"user","type":"NORMAL"},"repository":{"slug":"ios","id":11,"name":"reponame","scmId":"git","state":"AVAILABLE","statusMessage":"Available","forkable":false,"project":{"key":"projectkey","id":4,"name":"projectname","public":false,"type":"NORMAL"},"public":false},"changes":[{"ref":{"id":"refs/heads/example","displayId":"RG-4813","type":"BRANCH"},"refId":"refs/heads/example","fromHash":"908ea219d206248e93bcc94bf2d97ae6b308b19c","toHash":"6df28443dbfab868706611f9b0710db48b1d7352","type":"UPDATE"}]}
Is there a way to show comments for commit?
for example:
git commit -m "my comment message"
git push
And webhook shows:
@username
On repository reponame: my comment message
UPDATE commitlink
It appears the support for pull request comments (create, update and delete) is no longer working correctly for Cloud. It appears that perhaps the message format has changed. We are seeing an error like:
Cannot read property 'hash' of undefined at Promise.catch (evalmachine.<anonymous>:11:33)
repo:commit_comment_created work correctly, but for pullrequest:comment_created we get a 400 error with a response like:
{
"success": false,
"error": "error-running-script"
}
It is sending the X-Event-Key of pullrequest:comment_created, but looking at the sample payloads under ExamplePayloads, it appears that the payloads have changed.
https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html
In particular, it appears that the "pullrequest_comment_..." payloads no longer align with the code, and it appears that the comment method is being called now instead of the pullrequest_comment... methods. In the comment method, it does not handle "type" of "pullrequest_comment" correctly (where no hash is included in the comment object.
Using your howto for bitbucket server i used https://github.com/FinndropStudios/BitRocket/blob/master/BBServer_POSTReceiveHook.js
as the script, see https://goo.gl/JRZUSG to ensure we are on the same page.
In general the configuration looks like https://goo.gl/LO7kTo
when using the example curl post, i get:
{"success":false,"error":"error-running-script"}%
Pushing to my repo does not trigger anything either. I configured the bitbucket-server as described using the correct plugin and the post hook from rocket.chat: https://goo.gl/Td1bmc
bitbucketUrl is set correctly, however when the issue is posted to rocket chat the url in the link is a concatenation of the rocketchat url along with the bitbucketUrl. i.e. https://rocketchat.urlBitbucket.url/projects/repoPath.
Hello, we're using your RocketChat integration but the pullrequest triggers do not work, it seems like the payload of the BitBucket API changed to just pullrequest
instead of multiple triggers.
I'm attaching an example Payload of pullrequest:created.
{
"pullrequest": {
"merge_commit": null,
"description": "description",
"links": {
"decline": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/pullrequests/76/decline"
},
"commits": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/pullrequests/76/commits"
},
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/pullrequests/76"
},
"comments": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/pullrequests/76/comments"
},
"merge": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/pullrequests/76/merge"
},
"html": {
"href": "https://bitbucket.org/team_name/repo_name/pull-requests/76"
},
"activity": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/pullrequests/76/activity"
},
"diff": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/pullrequests/76/diff"
},
"approve": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/pullrequests/76/approve"
},
"statuses": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/pullrequests/76/statuses"
}
},
"author": {
"username": "user-name",
"type": "user",
"display_name": "name",
"uuid": "{uuid}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/user-name"
},
"html": {
"href": "https://bitbucket.org/user-name/"
},
"avatar": {
"href": "https://bitbucket.org/account/user-name/avatar/32/"
}
}
},
"close_source_branch": false,
"reviewers": [
{
"username": "user",
"type": "user",
"display_name": "user",
"uuid": "{uuid}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/user"
},
"html": {
"href": "https://bitbucket.org/user/"
},
"avatar": {
"href": "https://bitbucket.org/account/user/avatar/32/"
}
}
}
],
"id": 76,
"destination": {
"commit": {
"hash": "e3cc76cadf9e",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/commit/e3cc76cadf9e"
}
}
},
"repository": {
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name"
},
"html": {
"href": "https://bitbucket.org/team_name/repo_name"
},
"avatar": {
"href": "https://bitbucket.org/team_name/repo_name/avatar/32/"
}
},
"type": "repository",
"uuid": "{uuid}",
"full_name": "team_name/repo_name",
"name": "repo_name"
},
"branch": {
"name": "develop"
}
},
"created_on": "2017-05-09T15:22:01.138991+00:00",
"comment_count": 0,
"source": {
"commit": {
"hash": "73a0c96f746a",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name/commit/73a0c96f746a"
}
}
},
"repository": {
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name"
},
"html": {
"href": "https://bitbucket.org/team_name/repo_name"
},
"avatar": {
"href": "https://bitbucket.org/team_name/repo_name/avatar/32/"
}
},
"type": "repository",
"uuid": "{uuid}",
"full_name": "team_name/repo_name",
"name": "repo_name"
},
"branch": {
"name": "branch-name"
}
},
"participants": [
{
"type": "participant",
"role": "REVIEWER",
"approved": false,
"user": {
"username": "user",
"type": "user",
"display_name": "user",
"uuid": "{uuid}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/user"
},
"html": {
"href": "https://bitbucket.org/user/"
},
"avatar": {
"href": "https://bitbucket.org/account/user/avatar/32/"
}
}
}
}
],
"state": "OPEN",
"task_count": 0,
"updated_on": "2017-05-09T15:22:01.224333+00:00",
"reason": "",
"title": "PR Title",
"type": "pullrequest",
"closed_by": null
},
"actor": {
"username": "user-name",
"type": "user",
"display_name": "name",
"uuid": "{uuid}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/user-name"
},
"html": {
"href": "https://bitbucket.org/user-name/"
},
"avatar": {
"href": "https://bitbucket.org/account/user-name/avatar/32/"
}
}
},
"repository": {
"website": "",
"scm": "git",
"uuid": "{uuid}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/team_name/repo_name"
},
"html": {
"href": "https://bitbucket.org/team_name/repo_name"
},
"avatar": {
"href": "https://bitbucket.org/team_name/repo_name/avatar/32/"
}
},
"project": {
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/team_name/projects/AUT"
},
"html": {
"href": "https://bitbucket.org/account/user/team_name/projects/AUT"
},
"avatar": {
"href": "https://bitbucket.org/account/user/team_name/projects/AUT/avatar/32"
}
},
"type": "project",
"uuid": "{uuid}",
"key": "AUT",
"name": "autocredit"
},
"full_name": "team_name/repo_name",
"owner": {
"username": "team_name",
"type": "team",
"display_name": "team-name",
"uuid": "{uuid}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/team_name"
},
"html": {
"href": "https://bitbucket.org/team_name/"
},
"avatar": {
"href": "https://bitbucket.org/account/team_name/avatar/32/"
}
}
},
"type": "repository",
"is_private": true,
"name": "repo_name"
}
}
I have configured Rocket.Chat according to the readme, created webhook at repo but I got empty messages
Bitbucket server 5.5
Rocket.Chat script configuration
const config = {
colorDefault: '#225159',
colorError: '#8D2A12',
colorSuccess: '#14720a',
bitbucketUrl: 'http://my-rocket-chat'
};
const showNotifications = {
'repo:refs_changed': true,
'repo:forked': true,
'repo:comment:added': true,
'repo:comment:edited': true,
'repo:comment:deleted': true,
'pr:opened': true,
'pr:reviewer:approved': true,
'pr:reviewer:unapproved': true,
'pr:reviewer:needs_work': true,
'pr:merged': true,
'pr:declined': true,
'pr:deleted': true,
'pr:comment:added': true,
'pr:comment:deleted': true,
'pr:comment:edited': true
};
function get_basic_info(content) {
const author = {
username: content.actor.name,
displayname: content.actor.displayName
};
const repository = {
name: content.repository.name,
link: config.bitbucketUrl + '/projects/' + content.repository.project.key + '/repos/' + content.repository.name + '/commits'
};
return {
author: author,
repository: repository
};
}
function create_attachement(author, text) {
const attachment = {
author_name: '@'+author.username,
text: text
};
return attachment;
}
const processors = {
repo_refs_changed(content) {
const info = get_basic_info(content);
const updates = [];
for (let change of content.changes) {
let update = {};
update.hash = change.toHash;
update.link = info.repository.link + '/' + change.toHash;
update.type = change.type;
updates.push(update);
}
let text = '';
text += "On repository " + "[" + info.repository.name + "]" + "(" + info.repository.link + ")" + ": " + "\n";
for (let update of updates) {
text += "*" + update.type + "* " + "[" + update.hash.toString().substring(0, 6) + "]" + "(" + update.link + ")\n";
}
return {
content: {
attachments: [create_attachement(info.author, text)],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
repo_forked(content) {
const info = get_basic_info(content);
const fork_name = info.repository.name;
const originlink = config.bitbucketUrl + '/projects/' + content.repository.origin.project.key + '/repos/' + content.repository.origin.name + '/commits'
const fork_link = info.repository.link;
let text = '';
text += "On repository " + "[" + content.repository.origin.name + "]" + "(" + originlink + ")" + ": " + "\n";
text += "*Forked* to " + "[" + fork_name + "]" + "(" + fork_link + ")" + "\n";
return {
content: {
attachments: [create_attachement(info.author, text)],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
repo_comment_added(content) {
const info = get_basic_info(content);
const commithash = content.commit;
const comment = content.comment.text;
let text = '';
text += "On repository " + "[" + info.repository.name + "]" + "(" + info.repository.link + ")" + ": " + "\n";
text += "*Commented* " + "[" + commithash.toString().substring(0, 6) + "]" + "(" + info.repository.link + "/" + commithash + ")\n";
text += "_" + comment + "_\n";
return {
content: {
attachments: [create_attachement(info.author, text)],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
repo_comment_edited(content) {
const info = get_basic_info(content);
const commithash = content.commit;
const comment = content.comment.text;
let text = '';
text += "On repository " + "[" + info.repository.name + "]" + "(" + info.repository.link + ")" + ": " + "\n";
text += "*Edited Comment* " + "[" + commithash.toString().substring(0, 6) + "]" + "(" + info.repository.link + "/" + commithash + ")\n";
text += "~" + content.previousComment + "~\n";
text += "_" + comment + "_\n";
return {
content: {
attachments: [create_attachement(info.author, text)],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
repo_comment_deleted(content) {
const info = get_basic_info(content);
const commithash = content.commit;
const comment = content.comment.text;
let text = '';
text += "On repository " + "[" + info.repository.name + "]" + "(" + info.repository.link + ")" + ": " + "\n";
text += "*Deleted Comment* " + "[" + commithash.toString().substring(0, 6) + "]" + "(" + info.repository.link + "/" + commithash + ")\n";
text += "~" + comment + "~\n";
return {
content: {
attachments: [create_attachement(info.author, text)],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
pr_opened(content) {
const author = {
username: content.actor.name
};
const pullRequest = {
sourcebranch: content.pullRequest.fromRef.id,
destinationbranch: content.pullRequest.toRef.id,
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
sourcerepo: content.pullRequest.fromRef.repository.name,
destrepo: content.pullRequest.toRef.repository.name,
title: content.pullRequest.title,
description: content.pullRequest.description ? content.pullRequest.description : ''
};
const links = {
self: config.bitbucketUrl + '/projects/' + pullRequest.projectKey + '/repos/' + pullRequest.destrepo + '/pull-requests/' + pullRequest.id + '/overview'
};
let text = '';
text += '@' + author.username + ' opened a new pull request:\n';
text += '`' + pullRequest.sourcerepo + '/' + pullRequest.sourcebranch + '` => `' + pullRequest.destrepo + '/' + pullRequest.destinationbranch + '`\n\n';
text += 'Description:\n';
text += pullRequest.description + '\n';
const attachment = {
author_name: '#' + pullRequest.id + ' - ' + pullRequest.title,
author_link: links.self
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
pr_reviewer_approved(content) {
const author = {
username: content.actor.name
};
const pullrequest = {
sourcebranch: content.pullRequest.fromRef.id,
destinationbranch: content.pullRequest.toRef.id,
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
sourcerepo: content.pullRequest.fromRef.repository.name,
destrepo: content.pullRequest.toRef.repository.name,
title: content.pullRequest.title,
description: content.pullRequest.description ? content.pullRequest.description : ''
};
let text = '';
text += '@' + author.username + ' approved a pull request:\n';
text += '`' + pullrequest.sourcerepo + '/' + pullrequest.sourcebranch + '` => `' + pullrequest.destrepo + '/' + pullrequest.destinationbranch + '`\n\n';
const attachment = {
author_name: 'APPROVED: ' + pullrequest.title,
author_link: config.bitbucketUrl + '/projects/' + pullrequest.projectKey + '/repos/' + pullrequest.sourcerepo + '/pull-requests/' + pullrequest.id + '/overview'
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
pr_reviewer_unapproved(content) {
const author = {
username: content.actor.name
};
const pullrequest = {
sourcebranch: content.pullRequest.fromRef.id,
destinationbranch: content.pullRequest.toRef.id,
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
sourcerepo: content.pullRequest.fromRef.repository.name,
destrepo: content.pullRequest.toRef.repository.name,
title: content.pullRequest.title,
description: content.pullRequest.description ? content.pullRequest.description : ''
};
let text = '';
text += '@' + author.username + ' unapproved a pull request:\n';
text += '`' + pullrequest.sourcerepo + '/' + pullrequest.sourcebranch + '` => `' + pullrequest.destrepo + '/' + pullrequest.destinationbranch + '`\n\n';
const attachment = {
author_name: 'UNAPPROVED: ' + pullrequest.title,
author_link: config.bitbucketUrl + '/projects/' + pullrequest.projectKey + '/repos/' + pullrequest.sourcerepo + '/pull-requests/' + pullrequest.id + '/overview'
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
pr_reviewer_needs_work(content) {
const author = {
username: content.actor.name
};
const pullrequest = {
sourcebranch: content.pullRequest.fromRef.id,
destinationbranch: content.pullRequest.toRef.id,
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
sourcerepo: content.pullRequest.fromRef.repository.name,
destrepo: content.pullRequest.toRef.repository.name,
title: content.pullRequest.title,
description: content.pullRequest.description ? content.pullRequest.description : ''
};
let text = '';
text += '@' + author.username + ' says, a pull request needs work:\n';
text += '`' + pullrequest.sourcerepo + '/' + pullrequest.sourcebranch + '` => `' + pullrequest.destrepo + '/' + pullrequest.destinationbranch + '`\n\n';
const attachment = {
author_name: 'NEEDS WORK: ' + pullrequest.title,
author_link: config.bitbucketUrl + '/projects/' + pullrequest.projectKey + '/repos/' + pullrequest.sourcerepo + '/pull-requests/' + pullrequest.id + '/overview'
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorError !== '') ? '#' + config.colorError.replace('#', '') : '#225159')
}
};
},
pr_merged(content) {
const author = {
username: content.actor.name
};
const pullrequest = {
sourcebranch: content.pullRequest.fromRef.id,
destinationbranch: content.pullRequest.toRef.id,
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
sourcerepo: content.pullRequest.fromRef.repository.name,
destrepo: content.pullRequest.toRef.repository.name,
title: content.pullRequest.title,
description: content.pullRequest.description ? content.pullRequest.description : ''
};
let text = '';
text += '@' + author.username + ' merged a pull request:\n';
text += '`' + pullrequest.sourcerepo + '/' + pullrequest.sourcebranch + '` => `' + pullrequest.destrepo + '/' + pullrequest.destinationbranch + '`\n\n';
const attachment = {
author_name: 'MERGED: ' + pullrequest.title,
author_link: config.bitbucketUrl + '/projects/' + pullrequest.projectKey + '/repos/' + pullrequest.sourcerepo + '/pull-requests/' + pullrequest.id + '/overview'
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorSuccess !== '') ? '#' + config.colorSuccess.replace('#', '') : '#225159')
}
};
},
pr_declined(content) {
const author = {
username: content.actor.name
};
const pullrequest = {
sourcebranch: content.pullRequest.fromRef.id,
destinationbranch: content.pullRequest.toRef.id,
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
sourcerepo: content.pullRequest.fromRef.repository.name,
destrepo: content.pullRequest.toRef.repository.name,
title: content.pullRequest.title,
description: content.pullRequest.description ? content.pullRequest.description : ''
};
let text = '';
text += '@' + author.username + ' declined a pull request:\n';
text += '`' + pullrequest.sourcerepo + '/' + pullrequest.sourcebranch + '` => `' + pullrequest.destrepo + '/' + pullrequest.destinationbranch + '`\n\n';
const attachment = {
author_name: 'DECLINED: ' + pullrequest.title,
author_link: config.bitbucketUrl + '/projects/' + pullrequest.projectKey + '/repos/' + pullrequest.sourcerepo + '/pull-requests/' + pullrequest.id + '/overview'
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorError !== '') ? '#' + config.colorError.replace('#', '') : '#225159')
}
};
},
pr_deleted(content) {
const author = {
username: content.actor.name
};
const pullrequest = {
sourcebranch: content.pullRequest.fromRef.id,
destinationbranch: content.pullRequest.toRef.id,
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
sourcerepo: content.pullRequest.fromRef.repository.name,
destrepo: content.pullRequest.toRef.repository.name,
title: content.pullRequest.title,
description: content.pullRequest.description ? content.pullRequest.description : ''
};
let text = '';
text += '@' + author.username + ' deleted a pull request:\n';
text += '`' + pullrequest.sourcerepo + '/' + pullrequest.sourcebranch + '` => `' + pullrequest.destrepo + '/' + pullrequest.destinationbranch + '`\n\n';
const attachment = {
author_name: 'DELETED: ' + pullrequest.title,
author_link: config.bitbucketUrl + '/projects/' + pullrequest.projectKey + '/repos/' + pullrequest.sourcerepo + '/pull-requests/' + pullrequest.id + '/overview'
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorError !== '') ? '#' + config.colorError.replace('#', '') : '#225159')
}
};
},
pr_comment_added(content) {
const pullRequest = {
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
repo: content.pullRequest.fromRef.repository.name
};
const author = {
username: content.actor.name
};
const comment = {
text: content.comment.text
};
let text = '';
text += '@' + author.username + ' added a comment on a pull request:\n';
text += 'Comment:\n';
text += '_' + comment.text + '_\n';
const attachment = {
author_name: content.pullRequest.title,
author_link: config.bitbucketUrl + '/projects/' + pullRequest.projectKey + '/repos/' + pullRequest.repo + '/pull-requests/' + pullRequest.id + '/overview'
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
pr_comment_deleted(content) {
const pullRequest = {
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
repo: content.pullRequest.fromRef.repository.name
};
const author = {
username: content.actor.name
};
const comment = {
text: content.comment.text
};
let text = '';
text += '@' + author.username + ' deleted a comment on a pull request:\n';
text += 'Comment:\n';
text += '~' + comment.text + '~\n';
const attachment = {
author_name: content.pullRequest.title,
author_link: config.bitbucketUrl + '/projects/' + pullRequest.projectKey + '/repos/' + pullRequest.repo + '/pull-requests/' + pullRequest.id + '/overview'
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
},
pr_comment_edited(content) {
const pullRequest = {
projectKey: content.pullRequest.fromRef.repository.project.key,
id: content.pullRequest.id,
repo: content.pullRequest.fromRef.repository.name
};
const author = {
username: content.actor.name
};
const comment = {
text: content.comment.text,
oldText: content.previousComment
};
let text = '';
text += '@' + author.username + ' updated a comment on a pull request:\n';
text += 'Comment:\n';
text += '~' + comment.oldText + '~\n';
text += '_' + comment.text + '_\n';
const attachment = {
author_name: content.pullRequest.title,
author_link: config.bitbucketUrl + '/projects/' + pullRequest.projectKey + '/repos/' + pullRequest.repo + '/pull-requests/' + pullRequest.id + '/overview'
};
return {
content: {
text: text,
attachments: [attachment],
parseUrls: false,
color: ((config.colorDefault !== '') ? '#' + config.colorDefault.replace('#', '') : '#225159')
}
};
}
};
class Script {
/**
* @params {object} request
*/
process_incoming_request({ request }) {
var result = '';
if (showNotifications[request.content.eventKey] === true) {
var func = request.content.eventKey.replace(new RegExp(':', 'g'), '_');
result = processors[func](request.content);
}
return result;
}
}
I get an error after sending request to webhook:
{
"success": false,
"message": "Something went wrong before processing started or the handling of this type of trigger is not implemented. Please consider to disable the trigger or send a bug report."
}
It seems the method parsing json out of date.
Bitbucket Server 5.4 added native webhooks support:
https://confluence.atlassian.com/bitbucketserver/bitbucket-server-5-4-release-notes-935388966.html
This appears to have wider range of hooks points available than the "Web Post Hooks Plugin" currently used, the integration for which appears to currently be broken according to #3, and which any rate does not have the things like PR notification like the Cloud variant. The Bitbucket Server native web hooks appear to be much closer in function to the Bitbucket Cloud hooks.
Regardless of when the actions occur in bitbucket the alert posted to rocketchat always references December 31st 1969 7:00PM.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.