Last active
June 13, 2019 04:19
-
-
Save KixPanganiban/ccef745769479ea2470a889fe827f3ef to your computer and use it in GitHub Desktop.
CircleCI Incoming Webhook Script for Rocket.Chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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