Skip to content
Browse files

Merge pull request #1316 from pmotyka/master

Targets query string parameter should act as an override for GITLAB_CHANNEL
  • Loading branch information...
2 parents 9514439 + b0a0412 commit 5ff9287d464a407d68d8b6dcf64984e341266f2c @technicalpickles technicalpickles committed Feb 10, 2014
Showing with 41 additions and 4 deletions.
  1. +3 −2 src/scripts/gitlab.coffee
  2. +38 −2 src/scripts/jenkins.coffee
View
5 src/scripts/gitlab.coffee
@@ -12,7 +12,8 @@
# Put http://<HUBOT_URL>:<PORT>/gitlab/system as your system hook
# Put http://<HUBOT_URL>:<PORT>/gitlab/web as your web hook (per repository)
# You can also append "?targets=%23room1,%23room2" to the URL to control the
-# message destination.
+# message destination. Using the "target" parameter to override the
+# GITLAB_CHANNEL configuration value.
#
# Commands:
# None
@@ -54,7 +55,7 @@ module.exports = (robot) ->
console.log('hook', hook)
user = {}
- user.room = if query.targets then gitlabChannel + ',' + query.targets else gitlabChannel
+ user.room = if query.targets then query.targets else gitlabChannel
user.type = query.type if query.type
switch type
View
40 src/scripts/jenkins.coffee
@@ -16,6 +16,7 @@
# hubot jenkins build <job>, <params> - builds the specified Jenkins job with parameters as key=value&key2=value2
# hubot jenkins list <filter> - lists Jenkins jobs
# hubot jenkins describe <job> - Describes the specified Jenkins job
+# hubot jenkins last <job> - Details about the last build for the specified Jenkins job
#
# Author:
@@ -83,7 +84,7 @@ jenkinsDescribe = (msg) ->
try
content = JSON.parse(body)
response += "JOB: #{content.displayName}\n"
- response += "URL: #{url}/job/#{job}\n"
+ response += "URL: #{content.url}\n"
if content.description
response += "DESCRIPTION: #{content.description}\n"
@@ -115,7 +116,7 @@ jenkinsDescribe = (msg) ->
if not content.lastBuild
return
- path = "#{content.lastBuild.url}/api/json"
+ path = "#{url}/job/#{job}/#{content.lastBuild.number}/api/json"
req = msg.http(path)
if process.env.HUBOT_JENKINS_AUTH
auth = new Buffer(process.env.HUBOT_JENKINS_AUTH).toString('base64')
@@ -141,6 +142,36 @@ jenkinsDescribe = (msg) ->
catch error
msg.send error
+jenkinsLast = (msg) ->
+ url = process.env.HUBOT_JENKINS_URL
+ job = msg.match[1]
+
+ path = "#{url}/job/#{job}/lastBuild/api/json"
+
+ req = msg.http(path)
+
+ if process.env.HUBOT_JENKINS_AUTH
+ auth = new Buffer(process.env.HUBOT_JENKINS_AUTH).toString('base64')
+ req.headers Authorization: "Basic #{auth}"
+
+ req.header('Content-Length', 0)
+ req.get() (err, res, body) ->
+ if err
+ msg.send "Jenkins says: #{err}"
+ else
+ response = ""
+ try
+ content = JSON.parse(body)
+ response += "NAME: #{content.fullDisplayName}\n"
+ response += "URL: #{content.url}\n"
+
+ if content.description
+ response += "DESCRIPTION: #{content.description}\n"
+
+ response += "BUILDING: #{content.building}\n"
+
+ msg.send response
+
jenkinsList = (msg) ->
url = process.env.HUBOT_JENKINS_URL
filter = new RegExp(msg.match[2], 'i')
@@ -184,7 +215,12 @@ module.exports = (robot) ->
robot.respond /j(?:enkins)? describe (.*)/i, (msg) ->
jenkinsDescribe(msg)
+ robot.respond /j(?:enkins)? last (.*)/i, (msg) ->
+ jenkinsLast(msg)
+
robot.jenkins = {
list: jenkinsList,
build: jenkinsBuild
+ describe: jenkinsDescribe
+ last: jenkinsLast
}

0 comments on commit 5ff9287

Please sign in to comment.
Something went wrong with that request. Please try again.