Skip to content

Instantly share code, notes, and snippets.

@iterion
Created March 26, 2013 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iterion/5246142 to your computer and use it in GitHub Desktop.
Save iterion/5246142 to your computer and use it in GitHub Desktop.
hubot script to start tddium builds
# Description:
# What you do about Tddium. Utilities to start tddium sessions
# Also contains some utilities I used in debugging (primarily unstick and start)
# I think session listing and stopping of builds is broken
# Credit mostly due to reading Tddium's gems' source.
#
# Dependencies:
# "underscore": "1.4.4"
#
# Commands:
# hubot ignore - what do about tddium
# hubot tddium failed again - try to fix it
_ = require("underscore")
qs = require('querystring');
fail = "http://cdn.memegenerator.net/instances/400x/33771161.jpg"
tddium_api = "api_key_here"
master_id = 5746 #unique id for your build
tddium_url = "https://api.tddium.com/1/"
headers = {
'Content-Type': 'application/json',
"X-tddium-api-key": tddium_api,
"X-tddium-client-version": "tddium_client-0.2.0;tddium-1.7.2"
}
sessions_url = tddium_url + "sessions"
test_executions_url = (session_id, action) ->
sessions_url + "/#{session_id}/test_executions/" + action
module.exports = (robot) ->
robot.respond /ignore/i, (msg) ->
msg.send fail
robot.respond /(tddium\sfailed\sagain|build)/i, (msg) ->
if msg.match[1] == "build"
message = "Starting new TDDIUM build"
else
message = "I'm sorry to hear that, I'll try to build it again"
msg.send message
robot.http(sessions_url)
.headers(headers)
.post({"suite_id": master_id}) (err, res, body) ->
response = JSON.parse body
session_id = response.session.id
msg.send "Session Created (#{session_id})"
post_text = "{\"suite_id\": #{master_id}, \"test_pattern\": null}"
robot.http(test_executions_url(session_id, "register"))
.headers(headers)
.post(post_text) (err, res, body) ->
robot.http(test_executions_url(session_id, "start"))
.headers(headers)
.post({}) (err, res, body) ->
body = JSON.parse body
msg.send "Started #{body.started} tests: #{body.report}"
robot.respond /unstick (\d*)/i, (msg) ->
session_id = msg.match[1]
robot.http(test_executions_url(session_id, "register"))
.headers(headers)
.post("{\"suite_id\": #{master_id}, \"test_pattern\": null}") (err, res, body) ->
msg.send body
robot.respond /start (\d*)/i, (msg) ->
session_id = msg.match[1]
robot.http(test_executions_url(session_id, "start"))
.headers(headers)
.post({}) (err, res, body) ->
msg.send body
robot.respond /stop (\d*)/i, (msg) ->
msg.send "sorry, this doesn't work - I think tddium's api doesn't work for json here?"
session_id = msg.match[1]
url = tddium_url + "reports/#{session_id}/stop"
headers.
robot.http(url)
.headers(headers)
.post({}) (err, res, body) ->
msg.send body
robot.respond /what\'?s\sup\stddium\??|tddium\ssessions/i, (msg) ->
url = tddium_url + "sessions"
url = url + "?{\"active\":true,\"order\":\"date\"}"
robot.http(url)
.headers(headers)
.get() (err, res, body) ->
msg.send body
msg.send url
response = JSON.parse body
sessions = response.sessions
if sessions.length > 0
_.each sessions, (session) ->
msg.send "#{session.id} (#{session.test_execution_stats}): #{session.report}"
else
msg.send "There are no current tddium sessions"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment