Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit c2430a4

Browse files
committed
Merge pull request #1148 from maxbeatty/sprintly-deploy
Add deploy command for Sprint.ly
2 parents eab7d9e + f905ece commit c2430a4

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/scripts/sprintly.coffee

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
# hubot sprintly [product_id] #42 - show item #42
1414
# hubot sprintly [product_id] #42 tasks - list unfinished subtasks of story #42
1515
# hubot sprintly [product_id] <action> #42 - carry out action on item #42 (available actions: start, stop, finish, accept, reject, delete)
16+
# hubot sprintly [product_id] [environment] deploy 4,8,15,16,23,42 - mark items as deployed to an environment
1617
# hubot sprintly token <email:apitoken> - set/update credentials for user (required for other commands to work)
1718
# hubot sprintly default 1234 - set default product_id
19+
# hubot sprintly default_env production - set default environment (used for deploy)
1820
#
1921
# Author:
2022
# lackac
@@ -38,6 +40,11 @@ module.exports = (robot) ->
3840
robot.brain.data.sprintly.product_id = msg.match[1]
3941
msg.send "Default Product ID set to #{msg.match[1]}"
4042

43+
robot.respond /sprintly +default_env +(.*)/i, (msg) ->
44+
robot.brain.data.sprintly ?= {}
45+
robot.brain.data.sprintly.env = msg.match[1]
46+
msg.send "Default environment set to #{msg.match[1]}"
47+
4148
robot.respond /sprintly *(?: +(\d+))?(?: +(backlog|in-progress|completed|accepted))?(?: +(\d+))? *$/i, (msg) ->
4249
query = status: msg.match[2] ? 'in-progress'
4350
query.limit = msg.match[3] if msg.match[3]
@@ -105,6 +112,23 @@ module.exports = (robot) ->
105112
else
106113
msg.send "Something came up: #{body}"
107114

115+
robot.respond /sprintly *(?: +(\d+))?(?: +(.*))?deploy +([\d]+(,[\d]+)*)/i, (msg) ->
116+
query =
117+
environment: msg.match[2] ? msg.robot.brain.data.sprintly?.env
118+
numbers: msg.match[3]
119+
120+
if query.environment?
121+
sprintly(msg).product()
122+
.scope('deploys.json')
123+
.post(qs.stringify(query)) (err, res, body) ->
124+
if res.statusCode < 400
125+
apiRes = JSON.parse body
126+
msg.send "Successfully marked #{apiRes.items.length} items as deployed"
127+
else
128+
msg.send "Something came up: #{body}"
129+
else
130+
msg.send "No environment has been specified, you can set a default with 'sprintly default_env production'"
131+
108132
DummyClient = ->
109133
self = -> this
110134
for method in ['scope', 'query', 'product']
@@ -118,7 +142,7 @@ sprintlyUser = (msg) ->
118142

119143
sprintly = (msg, auth) ->
120144
if auth ?= sprintlyUser(msg).auth
121-
client = msg.http('https://sprint.ly')
145+
client = msg.robot.http('https://sprint.ly')
122146
.header('accept', 'application/json')
123147
.header('authorization', "Basic #{new Buffer(auth).toString('base64')}")
124148
.path('/api')

0 commit comments

Comments
 (0)