forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
WebHook Scripting GitHub
Gabriel Engel edited this page Mar 8, 2016
·
5 revisions
We can do 2 types of integrations with GitHub:
- Receive alerts from GitHub (Incoming WebHook)
- Send commands to GitHub and optionally receive a response (Outgoing WebHook)
- Create a new incoming webhook
- Select the channel were you will receive the alerts
- Use this script to receive alerts from new issues, closed issues and comments
if (headers['x-github-event'] === 'ping') {
return {
content: {
text: ':thumbsup: ' + content.zen
}
};
}
if (headers['x-github-event'] === 'issues' && content.action === 'opened') {
var attachment = {
color: 'red',
author_name: 'by ' + content.issue.user.login,
author_link: content.issue.user.html_url,
author_icon: content.issue.user.avatar_url,
fields: []
};
if (content.issue.labels) {
var labels = [];
content.issue.labels.forEach(function(label) {
labels.push(label.name);
});
labels = labels.join(', ');
attachment.fields.push({
title: 'Labels',
value: labels,
short: labels.length <= 40
});
}
if (content.issue.assignee) {
attachment.fields.push({
title: 'Assignee',
value: content.issue.assignee.login,
short: true
});
}
return {
content: {
text: ':triangular_flag_on_post: Issue created [#' + content.issue.number + ' - ' + content.issue.title + '](' + content.issue.html_url + ')',
attachments: [attachment]
}
};
}
if (headers['x-github-event'] === 'issues' && content.action === 'closed') {
var attachment = {
author_name: 'by ' + content.sender.login,
author_link: content.sender.html_url,
author_icon: content.sender.avatar_url
};
return {
content: {
text: ':white_check_mark: Issue closed [#' + content.issue.number + ' - ' + content.issue.title + '](' + content.issue.html_url + ')',
attachments: [attachment]
}
};
}
if (headers['x-github-event'] === 'issue_comment' && content.action === 'created') {
var attachment = {
text: content.comment.body,
author_name: 'by ' + content.comment.user.login,
author_link: content.comment.user.html_url,
author_icon: content.comment.user.avatar_url
};
return {
content: {
text: ':speech_balloon: Comment on issue [#' + content.issue.number + ' - ' + content.issue.title + '](' + content.issue.html_url + ')',
attachments: [attachment]
}
};
}
return {
error: {
success: false,
message: 'Unsupported method'
}
};
- Save the integration
- Go to your repository
settings -> webhooks & services -> add webhook
- Paste your Webhook URL from Rocket.Chat into Payload URL
- Keep Contenty type as
application/json
- Leave Secret empty and save
This script only works for public repositories
- Create a new outgoing webhook
- Select the channel where you will use the commands and receive the responses
- Set URLs as
https://api.github.com/repos/User-Or-Org-Name/Repo-Name
likehttps://api.github.com/repos/RocketChat/Rocket.Chat
- Use this Prepare Outgoing Request script to listen for commands
pr ls
,pr list
andhelp
var match = request.data.text.match(/^pr\s(ls|list)\s*(open|closed|all)?$/);
if (match) {
var u = request.url + '/pulls';
if (match[2]) {
u += '?state='+match[2];
}
return {
url: u,
headers: request.headers,
method: 'GET'
};
}
var match = request.data.text.match(/^help$/);
if (match) {
return {
message: {
text: [
'**GitHub commands**',
'```',
' pr ls|list [open|closed|all] List Pull Requests',
'```'
].join('\n')
}
};
}
- And this Process Outgoing Response to get the response and format for Rocket.Chat
var text = [];
response.content.forEach(function(pr) {
text.push('> '+pr.state+' [#'+pr.number+']('+pr.html_url+') - '+pr.title);
});
return {
content: {
text: text.join('\n'),
parseUrls: false
}
};
- Save your integration
- Mobile app for iPhones, iPads, iPod Touch
- Firefox OS native app
- Using Face to face video conference (aka webrtc)
- Remote Video Monitoring
- Roles and Permissions
- LDAP Authentication
- Creating the First Admin
- Build the Android Cordova Web App and connect to your own Rocket.Chat Server
- Mobile Notifications Gateway Configuration
- WebHooks
- Aliyun
- Docker w/Nginx SSL & Hubot
- Easy, hands off deployment with Ansible
- Deploy with docker
- FreeBSD
- UBUNTU
- CentOS 7 without docker
- Other Linux distributions
- IBM Bluemix
- Heroku
- Nitrous.io
- sloppy.io
- Run Rocket.Chat behind a SSL Reverse Proxy
- Deploy Rocket.Chat without docker
- Windows Deployment
- Update Docker RC and keep old data