Skip to content

Commit c76cdcd

Browse files
author
Ben Lavender
committed
Bump version to protocol version
1 parent 4b523de commit c76cdcd

4 files changed

Lines changed: 68 additions & 5 deletions

File tree

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ChatopsControllers
22

3-
Rails helpers for JSON-RPC based easy chatops.
3+
Rails helpers for easy, JSON-RPC based chatops.
44

55
A minimal controller example:
66

@@ -22,7 +22,7 @@ Some routing boilerplate is required in `config/routes.rb`:
2222

2323
```ruby
2424
Rails.application.routes.draw do
25-
post "/_chatops/:action", controller: "anonymous"
25+
post "/_chatops/:chatop", controller: "anonymous", action: :execute_chatop
2626
get "/_chatops" => "chatops#list"
2727
end
2828
```
@@ -103,3 +103,64 @@ foo` and `.echo foo in staging` to use two different servers to run `.echo foo`.
103103
script/bootstrap
104104
script/test
105105
```
106+
107+
## Upgrading from early versions
108+
109+
Early versions of RPC chatops had two major changes:
110+
111+
##### They used Rails' dynamic `:action` routing, which was depcrated in Rails 5.
112+
113+
To work around this, you need to update your router boilerplate:
114+
115+
This:
116+
117+
```ruby
118+
post "/_chatops/:action", controller: "anonymous"
119+
```
120+
121+
Becomes this:
122+
123+
```ruby
124+
post "/_chatops/:chatop", controller: "anonymous", action: :execute_chatop
125+
```
126+
127+
#####
128+
129+
They did not require a prefix. Version 2 of the Chatops RPC protocol assumes a unique prefix for each endpoint. This decision was made for several reasons:
130+
131+
* The previous suffix-based system creates semantic ambiguities with keyword arguments
132+
* Prefixes allow big improvements to `.help`
133+
* Prefixes make regex-clobbering impossible
134+
135+
To upgrade to version 2, upgrade to version 2.x of this gem. To migrate:
136+
137+
* Migrate your chatops to remove any prefixes you have:
138+
139+
```ruby
140+
chatop :foo, "help", /ci build whatever/, do "yay" end
141+
```
142+
143+
Becomes:
144+
145+
```ruby
146+
chatop :foo, "help", /build whatever/, do "yay" end
147+
```
148+
149+
* Update your tests:
150+
151+
```ruby
152+
chat "ci build foobar"
153+
```
154+
155+
Becomes:
156+
157+
```ruby
158+
chat "build foobar"
159+
```
160+
161+
* Remove and re-add your endpoint with a prefix:
162+
163+
```
164+
.rpc delete https://my-endpoint.dev
165+
.rpc add https://my-endpoint.dev with prefix ci
166+
```

lib/chatops/controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def list
1515
namespace: self.class.chatops_namespace,
1616
help: self.class.chatops_help,
1717
error_response: self.class.chatops_error_response,
18-
methods: chatops }
18+
methods: chatops,
19+
version: "2" }
1920
end
2021

2122
def process(*args)

lib/chatops_controller/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ChatopsController
2-
VERSION = "0.2.0"
2+
VERSION = "2.0.0"
33
end

spec/lib/chatops/controller_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
116116
"params" => [],
117117
"path" => "foobar"
118118
}
119-
}
119+
},
120+
"version" => "2"
120121
})
121122
end
122123

0 commit comments

Comments
 (0)