Skip to content

Instantly share code, notes, and snippets.

@KixPanganiban
Last active June 13, 2019 04:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KixPanganiban/ccef745769479ea2470a889fe827f3ef to your computer and use it in GitHub Desktop.
Save KixPanganiban/ccef745769479ea2470a889fe827f3ef to your computer and use it in GitHub Desktop.
CircleCI Incoming Webhook Script for Rocket.Chat
/**
* CircleCI Incoming Webhook Script for Rocket.Chat
* @author <github.com/kixpanganiban>
*/
class Script {
process_incoming_request({ request }) {
const statusMaps = {
'success': 'passed all tests',
'no_tests': 'has no tests',
'fixed': 'has been fixed',
'failed': 'has failed'
};
let status = request.content.payload.status;
let prettyStatus = (status in statusMaps) ? statusMaps[status] : 'has status: ' + status;
let author = request.content.payload.committer_name;
let authorEmail = request.content.payload.committer_email;
let branch = request.content.payload.branch;
let repo = request.content.payload.reponame;
let color = status === "success" ? "#95f442" : "#f44242";
let buildUrl = request.content.payload.build_url;
let commit = request.content.payload.subject;
let commitBody = request.content.payload.body;
let commitId = request.content.payload.vcs_revision.slice(0, 7);
return {
content:{
attachments: [{
title: author + '\'s build on ' + repo + ' (' + branch + ') ' + prettyStatus + '!',
title_link: buildUrl,
text: commit + ' (' + commitId + ' by ' + authorEmail + ')',
color: color,
fields: []
}]
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment