-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtravisci.coffee
More file actions
67 lines (56 loc) · 1.58 KB
/
travisci.coffee
File metadata and controls
67 lines (56 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Description
# <description of the scripts functionality>
#
# Dependencies:
# "<module name>": "<module version>"
#
# Configuration:
# LIST_OF_ENV_VARS_TO_SET
#
# Commands:
# hubot <trigger> - <what the respond trigger does>
# <trigger> - <what the hear trigger does>
#
# Notes:
# <optional notes required for the script>
#
# Author:
# <github username of the original script author>
class MessageBuilder
constructor: (payload) ->
@json = JSON.parse(payload)
repository: ->
"#{@json["repository"]["owner_name"]}/#{@json["repository"]["name"]}@#{@json["branch"]}"
number: ->
@json["number"]
author_name: ->
@json["author_name"]
commit: ->
@json["commit"].substr(0, 7)
build_url: ->
@json["build_url"]
step: ->
switch @json["status_message"]
when "Pending"
"✍ Build started"
when "Passed", "Fixed"
"☀ Build #{@json["status_message"].toLowerCase()}"
when "Broken", "Still Failing"
"☂ Build #{@json["status_message"].toLowerCase()}"
else
"☢ Unknown build status"
text: ->
"""
#{this.step()} \##{this.number()} (#{this.commit()}) of #{this.repository()} by #{this.author_name()}
#{this.build_url()}
"""
querystring = require('querystring')
module.exports = (robot) ->
robot.router.post "/hubot/travisci", (req, res) ->
query = querystring.parse(req._parsedUrl.query)
user = {}
user.room = query.room if query.room
user.type = query.type if query.type
message = new MessageBuilder(req.body.payload)
robot.send user, message.text()
res.end ""