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

Commit 5506f65

Browse files
committed
Merge pull request #306 from bitlove/master
Add rollout script.
2 parents 523428b + 89d4858 commit 5506f65

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/scripts/rollout.coffee

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Rollout REST API interface.
2+
#
3+
# Requires rollout_rest_api endpoint configured in the HUBOT_ROLLOUT_API_URL env var.
4+
#
5+
# Get rollout_rest_api here: https://github.com/jamesgolick/rollout_rest_api
6+
#
7+
# rollout list - Returns a list of available features.
8+
# rollout show <feature> - Shows the current rollout of `feature`.
9+
# rollout activate_user <feature> <user_id> - Activate `feature` for `user_id`.
10+
# rollout deactivate_user <feature> <user_id> - Deactivate `feature` for `user_id`.
11+
# rollout activate_group <feature> <group> - Activate `feature` for `group_id`.
12+
# rollout deactivate_group <feature> <group> - Deactivate `feature` for `group_id`.
13+
# rollout activate_percentage <feature> <percentage> - Activate `feature` for `percentage`% of users.
14+
# rollout deactivate <feature> - Deactivate `feature` all users.
15+
16+
endpoint = process.env.HUBOT_ROLLOUT_API_URL + '/'
17+
18+
show = (msg, feature) ->
19+
msg.http(endpoint + feature + '.json').get() (err, res, body) ->
20+
msg.send body
21+
22+
module.exports = (robot) ->
23+
robot.respond /rollout list$/i, (msg) ->
24+
msg.http(endpoint + 'features.json').get() (err, res, body) ->
25+
json = JSON.parse(body)
26+
msg.send json.sort().join("\n")
27+
28+
robot.respond /rollout show (.*)/i, (msg) ->
29+
show(msg, msg.match[1])
30+
31+
robot.respond /rollout activate_user ([^\s]*) ([^\s]*)/i, (msg) ->
32+
msg.http(endpoint + msg.match[1] + '/users').query(user: msg.match[2]).put() (err, res, body) ->
33+
show(msg, msg.match[1])
34+
35+
robot.respond /rollout deactivate_user ([^\s]*) ([^\s]*)/i, (msg) ->
36+
msg.http(endpoint + msg.match[1] + '/users').query({user: msg.match[2]}).delete() (err, res, body) ->
37+
show(msg, msg.match[1])
38+
39+
robot.respond /rollout activate_group ([^\s]*) ([^\s]*)/i, (msg) ->
40+
msg.http(endpoint + msg.match[1] + '/groups').query(group: msg.match[2]).put() (err, res, body) ->
41+
show(msg, msg.match[1])
42+
43+
robot.respond /rollout deactivate_group ([^\s]*) ([^\s]*)/i, (msg) ->
44+
msg.http(endpoint + msg.match[1] + '/groups').query({group: msg.match[2]}).delete() (err, res, body) ->
45+
show(msg, msg.match[1])
46+
47+
robot.respond /rollout activate_percentage ([^\s]*) ([^\s]*)/i, (msg) ->
48+
msg.http(endpoint + msg.match[1] + '/percentage').query(percentage: msg.match[2]).put() (err, res, body) ->
49+
show(msg, msg.match[1])
50+
51+
robot.respond /rollout deactivate ([^\s]*)/i, (msg) ->
52+
msg.http(endpoint + msg.match[1]).delete() (err, res, body) ->
53+
msg.send("[DONE]")

0 commit comments

Comments
 (0)