qiita_team_services 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fef4a03f843aba4fd94b121bb2bc3b167925c41c
4
- data.tar.gz: 4fe8e266110be34bbc07f01dae2a46e4c3f580dc
3
+ metadata.gz: 70b69acd1694d493b37c1c671815a050d86eccce
4
+ data.tar.gz: 72daa651ac2a5dd8ec1b2b8d4f0371cdd61f1652
5
5
  SHA512:
6
- metadata.gz: 581ea55242fad065de959775b300bc189c5ce7828ebb1cb7a3e1c68203e55eac9cfff6cf5dfd5c39be7cc3f645918c0159de0a087040d567842e04fde3cf30bf
7
- data.tar.gz: 5e7d81e6e64d8e27afc29d0fa2772021897981ca0dcdc3d2186cfe696adf4da6a38271edddaff419cb4ec803d6be8f436a5df0a2c8224b69cff774eaef1e71b7
6
+ metadata.gz: ba5ba03c1ddf0aeeeac635a3a38e9a1525058b7a66ecfce8179fa21fe1f7cbea56eb7251215e4e62eea68c95bb0ecf02dbc0bd245112ca94dfae038068ca590e
7
+ data.tar.gz: e8051fc83329b6d9f6650873c9d96d8124196759ca88d14e370e9dd0ffbd80cef3174bcaf2306780a2ade269c8779f378fdd63fed35311536aeb22bb55daa08e
@@ -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/TrailingComma:
32
+ Style/TrailingCommaInArguments:
33
+ EnforcedStyleForMultiline: comma
34
+
35
+ Style/TrailingCommaInLiteral:
27
36
  EnforcedStyleForMultiline: comma
@@ -1,3 +1,8 @@
1
+ # 0.3.7
2
+
3
+ - [#15] Truncate Slack message text to 7500 bytes.
4
+ - [#14] Update outdated rubocop config.
5
+
1
6
  # 0.3.6
2
7
 
3
8
  - [#13] Escape special characters for slack markup.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require "rspec/core/rake_task"
3
3
  require "rubocop/rake_task"
4
4
  require "yard"
5
5
 
6
- YARD_DIR = ".publish"
6
+ YARD_DIR = ".publish".freeze
7
7
 
8
8
  RuboCop::RakeTask.new
9
9
  RSpec::Core::RakeTask.new
@@ -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
- if resp.success?
52
- resp
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
@@ -13,8 +13,6 @@ module Qiita::Team::Services
13
13
  message: :not_slack_url,
14
14
  allow_blank: true }
15
15
 
16
- private
17
-
18
16
  # @note Implement Concerns::HttpClient#url.
19
17
  alias_method :url, :webhook_url
20
18
  end
@@ -1,3 +1,3 @@
1
1
  module Qiita::Team::Services
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7".freeze
3
3
  end
@@ -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.33"
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
@@ -14,7 +14,7 @@ describe Qiita::Team::Services::Hooks::ChatworkV1 do
14
14
  :project_created,
15
15
  :project_updated,
16
16
  :team_member_added,
17
- ]
17
+ ].freeze
18
18
 
19
19
  shared_context "Delivery success" do
20
20
  before do
@@ -13,7 +13,7 @@ describe Qiita::Team::Services::Hooks::HipchatV1 do
13
13
  :project_created,
14
14
  :project_updated,
15
15
  :team_member_added,
16
- ]
16
+ ].freeze
17
17
 
18
18
  shared_context "Delivery success" do
19
19
  before do
@@ -1,8 +1,8 @@
1
1
  require "factory_girl"
2
2
 
3
3
  Dir.glob("spec/support/factories/*.rb")
4
- .map { |filepath| filepath.split("/").last.split(".").first }
5
- .each { |name| require "support/factories/#{name}" }
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.6
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: 2015-12-08 00:00:00.000000000 Z
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: '0.33'
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: '0.33'
194
+ version: 0.36.0
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: webmock
197
197
  requirement: !ruby/object:Gem::Requirement