qiita_team_services 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -1
- data/CHANGELOG.md +5 -0
- data/Rakefile +1 -1
- data/lib/qiita/team/services/hooks/concerns/http_client.rb +3 -6
- data/lib/qiita/team/services/hooks/concerns/slack.rb +16 -3
- data/lib/qiita/team/services/hooks/slack_v2.rb +0 -2
- data/lib/qiita/team/services/version.rb +1 -1
- data/qiita_team_services.gemspec +1 -1
- data/spec/hooks/chatwork_v1_spec.rb +1 -1
- data/spec/hooks/hipchat_v1_spec.rb +1 -1
- data/spec/support/factory_girl.rb +2 -2
- data/spec/support/helpers/slack_hook_helper.rb +18 -0
- data/spec/support/matchers/match_slack_attachments_request.rb +7 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70b69acd1694d493b37c1c671815a050d86eccce
|
4
|
+
data.tar.gz: 72daa651ac2a5dd8ec1b2b8d4f0371cdd61f1652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba5ba03c1ddf0aeeeac635a3a38e9a1525058b7a66ecfce8179fa21fe1f7cbea56eb7251215e4e62eea68c95bb0ecf02dbc0bd245112ca94dfae038068ca590e
|
7
|
+
data.tar.gz: e8051fc83329b6d9f6650873c9d96d8124196759ca88d14e370e9dd0ffbd80cef3174bcaf2306780a2ade269c8779f378fdd63fed35311536aeb22bb55daa08e
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.1
|
3
|
+
|
4
|
+
Style/Alias:
|
5
|
+
EnforcedStyle: prefer_alias_method
|
6
|
+
|
1
7
|
Style/StringLiterals:
|
2
8
|
EnforcedStyle: double_quotes
|
3
9
|
|
@@ -23,5 +29,8 @@ Metrics/MethodLength:
|
|
23
29
|
Metrics/AbcSize:
|
24
30
|
Max: 30
|
25
31
|
|
26
|
-
Style/
|
32
|
+
Style/TrailingCommaInArguments:
|
33
|
+
EnforcedStyleForMultiline: comma
|
34
|
+
|
35
|
+
Style/TrailingCommaInLiteral:
|
27
36
|
EnforcedStyleForMultiline: comma
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ module Qiita::Team::Services
|
|
9
9
|
DEFAULT_HEADERS = {
|
10
10
|
"Content-Type" => "application/json",
|
11
11
|
"User-Agent" => "Qiita:Team",
|
12
|
-
}
|
12
|
+
}.freeze
|
13
13
|
TIMEOUT = 5
|
14
14
|
|
15
15
|
private
|
@@ -48,11 +48,8 @@ module Qiita::Team::Services
|
|
48
48
|
req.headers[key] = value
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
|
-
|
53
|
-
else
|
54
|
-
fail DeliveryError
|
55
|
-
end
|
51
|
+
fail DeliveryError unless resp.success?
|
52
|
+
resp
|
56
53
|
end
|
57
54
|
|
58
55
|
# @return [Symbol] the request format type, `:json` or `:url_encoded`
|
@@ -15,6 +15,7 @@ module Qiita::Team::Services
|
|
15
15
|
|
16
16
|
DEFAULT_ICON_URL = "https://cdn.qiita.com/media/qiita-team-slack-icon.png".freeze
|
17
17
|
ICON_EMOJI_FORMAT = /\A:[^:]+:\z/
|
18
|
+
TEXT_BYTESIZE_MAX = 7500
|
18
19
|
|
19
20
|
included do
|
20
21
|
include HttpClient
|
@@ -54,7 +55,7 @@ module Qiita::Team::Services
|
|
54
55
|
author_icon: event.user.profile_image_url,
|
55
56
|
title: event.item.title,
|
56
57
|
title_link: event.item.url,
|
57
|
-
text: Slacken.translate(event.item.rendered_body),
|
58
|
+
text: truncate(Slacken.translate(event.item.rendered_body), event.item.url),
|
58
59
|
mrkdwn_in: ["text"],
|
59
60
|
],
|
60
61
|
)
|
@@ -105,7 +106,7 @@ module Qiita::Team::Services
|
|
105
106
|
author_name: "@#{event.user.url_name}",
|
106
107
|
author_link: event.user.url,
|
107
108
|
author_icon: event.user.profile_image_url,
|
108
|
-
text: Slacken.translate(event.comment.rendered_body),
|
109
|
+
text: truncate(Slacken.translate(event.comment.rendered_body), event.comment.url),
|
109
110
|
mrkdwn_in: ["text"],
|
110
111
|
],
|
111
112
|
)
|
@@ -141,7 +142,7 @@ module Qiita::Team::Services
|
|
141
142
|
author_name: "@#{event.user.url_name}",
|
142
143
|
author_link: event.user.url,
|
143
144
|
author_icon: event.user.profile_image_url,
|
144
|
-
text: Slacken.translate(event.comment.rendered_body),
|
145
|
+
text: truncate(Slacken.translate(event.comment.rendered_body), event.comment.url),
|
145
146
|
mrkdwn_in: ["text"],
|
146
147
|
],
|
147
148
|
)
|
@@ -288,6 +289,18 @@ module Qiita::Team::Services
|
|
288
289
|
}
|
289
290
|
text.gsub(/[&<>]/, table_for_escape)
|
290
291
|
end
|
292
|
+
|
293
|
+
# Truncate the text to 7500 bytes.
|
294
|
+
# Now, Slack has a bug that we cannot send text larger than 8000 bytes.
|
295
|
+
#
|
296
|
+
# @param text [String]
|
297
|
+
# @param url [String]
|
298
|
+
# @return [String]
|
299
|
+
def truncate(text, url)
|
300
|
+
return text if text.bytesize <= TEXT_BYTESIZE_MAX
|
301
|
+
tail = "...\n<#{url}|Read more at Qiita:Team...>"
|
302
|
+
text.byteslice(0, TEXT_BYTESIZE_MAX - tail.bytesize).scrub("") + tail
|
303
|
+
end
|
291
304
|
end
|
292
305
|
end
|
293
306
|
end
|
data/qiita_team_services.gemspec
CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_development_dependency "pry"
|
38
38
|
spec.add_development_dependency "rake", "~> 10.4"
|
39
39
|
spec.add_development_dependency "rspec", "~> 3.3"
|
40
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
40
|
+
spec.add_development_dependency "rubocop", "~> 0.36.0"
|
41
41
|
spec.add_development_dependency "webmock", "~> 1.21"
|
42
42
|
spec.add_development_dependency "yard", "~> 0.8.7"
|
43
43
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "factory_girl"
|
2
2
|
|
3
3
|
Dir.glob("spec/support/factories/*.rb")
|
4
|
-
|
5
|
-
|
4
|
+
.map { |filepath| filepath.split("/").last.split(".").first }
|
5
|
+
.each { |name| require "support/factories/#{name}" }
|
6
6
|
|
7
7
|
RSpec.configure do |config|
|
8
8
|
config.include FactoryGirl::Syntax::Methods
|
@@ -124,6 +124,12 @@ module Qiita::Team::Services
|
|
124
124
|
let(:user) { build(:user, name: "<Qiitan>") }
|
125
125
|
it_behaves_like "attachments request hook method"
|
126
126
|
end
|
127
|
+
|
128
|
+
context "when the item's body has larger bytesize than the limit" do
|
129
|
+
let(:text_length) { Hooks::Concerns::Slack::TEXT_BYTESIZE_MAX / "あ".bytesize + 1 }
|
130
|
+
let(:resource) { build(:item, rendered_body: "あ" * text_length) }
|
131
|
+
it_behaves_like "attachments request hook method"
|
132
|
+
end
|
127
133
|
end
|
128
134
|
|
129
135
|
%w(became_coediting destroyed updated).each do |action_name|
|
@@ -160,6 +166,12 @@ module Qiita::Team::Services
|
|
160
166
|
let(:user) { build(:user, name: "<Qiitan>") }
|
161
167
|
it_behaves_like "attachments request hook method"
|
162
168
|
end
|
169
|
+
|
170
|
+
context "when the comment's body has larger bytesize than the limit" do
|
171
|
+
let(:text_length) { Hooks::Concerns::Slack::TEXT_BYTESIZE_MAX / "あ".bytesize + 1 }
|
172
|
+
let(:resource) { build(:comment, rendered_body: "あ" * text_length) }
|
173
|
+
it_behaves_like "attachments request hook method"
|
174
|
+
end
|
163
175
|
end
|
164
176
|
|
165
177
|
%w(destroyed updated).each do |action_name|
|
@@ -217,6 +229,12 @@ module Qiita::Team::Services
|
|
217
229
|
let(:user) { build(:user, name: "<Qiitan>") }
|
218
230
|
it_behaves_like "attachments request hook method"
|
219
231
|
end
|
232
|
+
|
233
|
+
context "when the comment's body has larger bytesize than the limit" do
|
234
|
+
let(:text_length) { Hooks::Concerns::Slack::TEXT_BYTESIZE_MAX / "あ".bytesize + 1 }
|
235
|
+
let(:resource) { build(:project_comment, rendered_body: "あ" * text_length) }
|
236
|
+
it_behaves_like "attachments request hook method"
|
237
|
+
end
|
220
238
|
end
|
221
239
|
|
222
240
|
%w(destroyed updated).each do |action_name|
|
@@ -2,6 +2,12 @@ RSpec::Matchers.define :match_slack_attachments_request do
|
|
2
2
|
match do |request_body|
|
3
3
|
request_body.is_a?(Hash) && \
|
4
4
|
request_body.key?(:attachments) && \
|
5
|
-
request_body[:attachments].is_a?(Array)
|
5
|
+
request_body[:attachments].is_a?(Array) && \
|
6
|
+
request_body[:attachments].all?(&method(:text_valid_length?))
|
7
|
+
end
|
8
|
+
|
9
|
+
def text_valid_length?(attachment)
|
10
|
+
attachment[:text].nil? || \
|
11
|
+
attachment[:text].bytesize <= Qiita::Team::Services::Hooks::Concerns::Slack::TEXT_BYTESIZE_MAX
|
6
12
|
end
|
7
13
|
end
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuku Takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel-url_validator
|
@@ -184,14 +184,14 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: 0.36.0
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: 0.36.0
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: webmock
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|