qiita_team_services 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/qiita/team/services/hooks/concerns/slack.rb +19 -78
- data/lib/qiita/team/services/hooks/webhook.rb +1 -1
- data/lib/qiita/team/services/version.rb +1 -1
- data/spec/support/helpers/slack_hook_helper.rb +39 -3
- data/spec/support/matchers/match_slack_text_request.rb +8 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4da9ccfe481121e812f461f312a74732edfeb956
|
4
|
+
data.tar.gz: 16dcd0bf7ab843d2ab25cf2fcef6a0a3f9bb47eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cead78f4002f9b6e63aa33528d1e32fb80da1cc2050a594023c74b3da4439c8c00503dea184e85bb10bac0f57d9ecb4bd5c0737e64e2ae4b12e52283c3fb9d36
|
7
|
+
data.tar.gz: 77802d7473b8dd267a16af6caa0bc6397ea6c824af27f7e4a867715924b754850cfb039178cf82a45c16d0187dfb1ccf74653c7918171f997eb8c8a18be06c97
|
@@ -35,8 +35,7 @@ module Qiita::Team::Services
|
|
35
35
|
|
36
36
|
# @return [void]
|
37
37
|
def ping
|
38
|
-
|
39
|
-
send_message(attachments: [fallback: fallback, pretext: fallback])
|
38
|
+
send_message(text: "Test message sent from Qiita:Team")
|
40
39
|
rescue DeliveryError
|
41
40
|
nil
|
42
41
|
end
|
@@ -65,12 +64,8 @@ module Qiita::Team::Services
|
|
65
64
|
# @return [void]
|
66
65
|
# @raise [Qiita::Team::Services::DeliveryError]
|
67
66
|
def item_updated(event)
|
68
|
-
fallback = "#{user_link(event.user)} updated #{item_link(event.item)}"
|
69
67
|
send_message(
|
70
|
-
|
71
|
-
fallback: fallback,
|
72
|
-
pretext: fallback,
|
73
|
-
],
|
68
|
+
text: "#{user_link(event.user)} updated #{item_link(event.item)}",
|
74
69
|
)
|
75
70
|
end
|
76
71
|
|
@@ -78,12 +73,8 @@ module Qiita::Team::Services
|
|
78
73
|
# @return [void]
|
79
74
|
# @raise [Qiita::Team::Services::DeliveryError]
|
80
75
|
def item_became_coediting(event)
|
81
|
-
fallback = "#{user_link(event.user)} changed #{item_link(event.item)} to coedit mode"
|
82
76
|
send_message(
|
83
|
-
|
84
|
-
fallback: fallback,
|
85
|
-
pretext: fallback,
|
86
|
-
],
|
77
|
+
text: "#{user_link(event.user)} changed #{item_link(event.item)} to coedit mode",
|
87
78
|
)
|
88
79
|
end
|
89
80
|
|
@@ -91,12 +82,8 @@ module Qiita::Team::Services
|
|
91
82
|
# @return [void]
|
92
83
|
# @raise [Qiita::Team::Services::DeliveryError]
|
93
84
|
def item_destroyed(event)
|
94
|
-
fallback = "#{user_link(event.user)} deleted #{event.item.title}"
|
95
85
|
send_message(
|
96
|
-
|
97
|
-
fallback: fallback,
|
98
|
-
pretext: fallback,
|
99
|
-
],
|
86
|
+
text: "#{user_link(event.user)} deleted #{event.item.title}",
|
100
87
|
)
|
101
88
|
end
|
102
89
|
|
@@ -127,26 +114,17 @@ module Qiita::Team::Services
|
|
127
114
|
# @return [void]
|
128
115
|
# @raise [Qiita::Team::Services::DeliveryError]
|
129
116
|
def item_comment_updated(event)
|
130
|
-
|
131
|
-
|
132
|
-
send_message(
|
133
|
-
attachments: [
|
134
|
-
fallback: fallback,
|
135
|
-
pretext: fallback,
|
136
|
-
],
|
137
|
-
)
|
117
|
+
text = "#{user_link(event.user)} updated a #{comment_link(event.comment)}"
|
118
|
+
text << " on #{item_link(event.item)}"
|
119
|
+
send_message(text: text)
|
138
120
|
end
|
139
121
|
|
140
122
|
# @param event [Qiita::Team::Services::Events::ItemCommentDestroyed]
|
141
123
|
# @return [void]
|
142
124
|
# @raise [Qiita::Team::Services::DeliveryError]
|
143
125
|
def item_comment_destroyed(event)
|
144
|
-
fallback = "#{user_link(event.user)} deleted a comemnt on #{item_link(event.item)}"
|
145
126
|
send_message(
|
146
|
-
|
147
|
-
fallback: fallback,
|
148
|
-
pretext: fallback,
|
149
|
-
],
|
127
|
+
text: "#{user_link(event.user)} deleted a comemnt on #{item_link(event.item)}",
|
150
128
|
)
|
151
129
|
end
|
152
130
|
|
@@ -172,26 +150,17 @@ module Qiita::Team::Services
|
|
172
150
|
# @return [void]
|
173
151
|
# @raise [Qiita::Team::Services::DeliveryError]
|
174
152
|
def project_comment_updated(event)
|
175
|
-
|
176
|
-
|
177
|
-
send_message(
|
178
|
-
attachments: [
|
179
|
-
fallback: fallback,
|
180
|
-
pretext: fallback,
|
181
|
-
],
|
182
|
-
)
|
153
|
+
text = "#{user_link(event.user)} updated a #{comment_link(event.comment)}"
|
154
|
+
text << " on #{project_link(event.project)}"
|
155
|
+
send_message(text: text)
|
183
156
|
end
|
184
157
|
|
185
158
|
# @param event [Qiita::Team::Services::Events::ProjectCommentDestroyed]
|
186
159
|
# @return [void]
|
187
160
|
# @raise [Qiita::Team::Services::DeliveryError]
|
188
161
|
def project_comment_destroyed(event)
|
189
|
-
fallback = "#{user_link(event.user)} deleted a comemnt on #{project_link(event.project)}"
|
190
162
|
send_message(
|
191
|
-
|
192
|
-
fallback: fallback,
|
193
|
-
pretext: fallback,
|
194
|
-
],
|
163
|
+
text: "#{user_link(event.user)} deleted a comemnt on #{project_link(event.project)}",
|
195
164
|
)
|
196
165
|
end
|
197
166
|
|
@@ -199,12 +168,8 @@ module Qiita::Team::Services
|
|
199
168
|
# @return [void]
|
200
169
|
# @raise [Qiita::Team::Services::DeliveryError]
|
201
170
|
def team_member_added(event)
|
202
|
-
fallback = "#{user_link(event.member)} was added to the #{team_link(event.team)} team"
|
203
171
|
send_message(
|
204
|
-
|
205
|
-
fallback: fallback,
|
206
|
-
pretext: fallback,
|
207
|
-
],
|
172
|
+
text: "#{user_link(event.member)} was added to the #{team_link(event.team)} team",
|
208
173
|
)
|
209
174
|
end
|
210
175
|
|
@@ -212,12 +177,8 @@ module Qiita::Team::Services
|
|
212
177
|
# @return [void]
|
213
178
|
# @raise [Qiita::Team::Services::DeliveryError]
|
214
179
|
def team_member_removed(event)
|
215
|
-
fallback = "#{event.member.name} was removed from the #{team_link(event.team)} team"
|
216
180
|
send_message(
|
217
|
-
|
218
|
-
fallback: fallback,
|
219
|
-
pretext: fallback,
|
220
|
-
],
|
181
|
+
text: "#{event.member.name} was removed from the #{team_link(event.team)} team",
|
221
182
|
)
|
222
183
|
end
|
223
184
|
|
@@ -225,12 +186,8 @@ module Qiita::Team::Services
|
|
225
186
|
# @return [void]
|
226
187
|
# @raise [Qiita::Team::Services::DeliveryError]
|
227
188
|
def project_created(event)
|
228
|
-
fallback = "#{user_link(event.user)} created #{project_link(event.project)} project"
|
229
189
|
send_message(
|
230
|
-
|
231
|
-
fallback: fallback,
|
232
|
-
pretext: fallback,
|
233
|
-
],
|
190
|
+
text: "#{user_link(event.user)} created #{project_link(event.project)} project",
|
234
191
|
)
|
235
192
|
end
|
236
193
|
|
@@ -238,12 +195,8 @@ module Qiita::Team::Services
|
|
238
195
|
# @return [void]
|
239
196
|
# @raise [Qiita::Team::Services::DeliveryError]
|
240
197
|
def project_updated(event)
|
241
|
-
fallback = "#{user_link(event.user)} updated #{project_link(event.project)} project"
|
242
198
|
send_message(
|
243
|
-
|
244
|
-
fallback: fallback,
|
245
|
-
pretext: fallback,
|
246
|
-
],
|
199
|
+
text: "#{user_link(event.user)} updated #{project_link(event.project)} project",
|
247
200
|
)
|
248
201
|
end
|
249
202
|
|
@@ -251,12 +204,8 @@ module Qiita::Team::Services
|
|
251
204
|
# @return [void]
|
252
205
|
# @raise [Qiita::Team::Services::DeliveryError]
|
253
206
|
def project_destroyed(event)
|
254
|
-
fallback = "#{user_link(event.user)} deleted #{project_link(event.project)} project"
|
255
207
|
send_message(
|
256
|
-
|
257
|
-
fallback: fallback,
|
258
|
-
pretext: fallback,
|
259
|
-
],
|
208
|
+
text: "#{user_link(event.user)} deleted #{project_link(event.project)} project",
|
260
209
|
)
|
261
210
|
end
|
262
211
|
|
@@ -264,12 +213,8 @@ module Qiita::Team::Services
|
|
264
213
|
# @return [void]
|
265
214
|
# @raise [Qiita::Team::Services::DeliveryError]
|
266
215
|
def project_archived(event)
|
267
|
-
fallback = "#{user_link(event.user)} archived #{project_link(event.project)} project"
|
268
216
|
send_message(
|
269
|
-
|
270
|
-
fallback: fallback,
|
271
|
-
pretext: fallback,
|
272
|
-
],
|
217
|
+
text: "#{user_link(event.user)} archived #{project_link(event.project)} project",
|
273
218
|
)
|
274
219
|
end
|
275
220
|
|
@@ -277,12 +222,8 @@ module Qiita::Team::Services
|
|
277
222
|
# @return [void]
|
278
223
|
# @raise [Qiita::Team::Services::DeliveryError]
|
279
224
|
def project_activated(event)
|
280
|
-
fallback = "#{user_link(event.user)} activated #{project_link(event.project)} project"
|
281
225
|
send_message(
|
282
|
-
|
283
|
-
fallback: fallback,
|
284
|
-
pretext: fallback,
|
285
|
-
],
|
226
|
+
text: "#{user_link(event.user)} activated #{project_link(event.project)} project",
|
286
227
|
)
|
287
228
|
end
|
288
229
|
|
@@ -28,6 +28,15 @@ module Qiita::Team::Services
|
|
28
28
|
:team_member_removed,
|
29
29
|
].freeze
|
30
30
|
|
31
|
+
EVENT_NAMES_TO_SEND_WITH_ATTACHMENTS = [
|
32
|
+
:item_comment_created,
|
33
|
+
:item_created,
|
34
|
+
:project_comment_created,
|
35
|
+
].freeze
|
36
|
+
|
37
|
+
EVENT_NAMES_TO_SEND_WITH_TEXT =
|
38
|
+
(EXPECTED_AVAILABLE_EVENT_NAMES - EVENT_NAMES_TO_SEND_WITH_ATTACHMENTS).freeze
|
39
|
+
|
31
40
|
included do
|
32
41
|
shared_examples "Slack hook" do |hook:|
|
33
42
|
describe ".service_name" do
|
@@ -51,9 +60,9 @@ module Qiita::Team::Services
|
|
51
60
|
send(hook).ping
|
52
61
|
end
|
53
62
|
|
54
|
-
it "sends
|
63
|
+
it "sends proper text message" do
|
55
64
|
expect(send(hook)).to receive(:send_message) do |request_body|
|
56
|
-
expect(request_body).to
|
65
|
+
expect(request_body).to match_slack_text_request
|
57
66
|
end.once
|
58
67
|
subject
|
59
68
|
end
|
@@ -71,7 +80,34 @@ module Qiita::Team::Services
|
|
71
80
|
end
|
72
81
|
end
|
73
82
|
|
74
|
-
|
83
|
+
EVENT_NAMES_TO_SEND_WITH_TEXT.each do |event_name|
|
84
|
+
describe "##{event_name}" do
|
85
|
+
subject do
|
86
|
+
send(hook).public_send(event_name, public_send("#{event_name}_event"))
|
87
|
+
end
|
88
|
+
|
89
|
+
it "sends proper text message" do
|
90
|
+
expect(send(hook)).to receive(:send_message) do |request_body|
|
91
|
+
expect(request_body).to match_slack_text_request
|
92
|
+
end.once
|
93
|
+
subject
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when message is delivered successfully" do
|
97
|
+
include_context "Delivery success"
|
98
|
+
|
99
|
+
it { expect { subject }.not_to raise_error }
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when message is not delivered successfully" do
|
103
|
+
include_context "Delivery fail"
|
104
|
+
|
105
|
+
it { expect { subject }.to raise_error(Qiita::Team::Services::DeliveryError) }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
EVENT_NAMES_TO_SEND_WITH_ATTACHMENTS.each do |event_name|
|
75
111
|
describe "##{event_name}" do
|
76
112
|
subject do
|
77
113
|
send(hook).public_send(event_name, public_send("#{event_name}_event"))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qiita_team_services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuku Takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel-url_validator
|
@@ -302,6 +302,7 @@ files:
|
|
302
302
|
- spec/support/helpers/http_client_stub_helper.rb
|
303
303
|
- spec/support/helpers/slack_hook_helper.rb
|
304
304
|
- spec/support/matchers/match_slack_attachments_request.rb
|
305
|
+
- spec/support/matchers/match_slack_text_request.rb
|
305
306
|
- spec/support/resources/base.rb
|
306
307
|
- spec/support/resources/comment.rb
|
307
308
|
- spec/support/resources/item.rb
|