slack-ruby-block-kit 0.8.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.deepsource.toml +15 -0
  3. data/.github/workflows/ci.yml +33 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +23 -1
  6. data/.rubocop_todo.yml +10 -0
  7. data/CHANGELOG.md +93 -0
  8. data/Gemfile +14 -1
  9. data/README.md +3 -1
  10. data/lib/slack/block_kit.rb +46 -2
  11. data/lib/slack/block_kit/blocks.rb +12 -0
  12. data/lib/slack/block_kit/composition/confirmation_dialog.rb +16 -0
  13. data/lib/slack/block_kit/composition/option.rb +6 -1
  14. data/lib/slack/block_kit/composition/option_group.rb +2 -2
  15. data/lib/slack/block_kit/element/button.rb +3 -11
  16. data/lib/slack/block_kit/element/channels_select.rb +3 -11
  17. data/lib/slack/block_kit/element/checkboxes.rb +53 -0
  18. data/lib/slack/block_kit/element/conversations_select.rb +3 -11
  19. data/lib/slack/block_kit/element/date_picker.rb +3 -9
  20. data/lib/slack/block_kit/element/external_select.rb +3 -12
  21. data/lib/slack/block_kit/element/multi_channels_select.rb +5 -14
  22. data/lib/slack/block_kit/element/multi_conversations_select.rb +5 -14
  23. data/lib/slack/block_kit/element/multi_external_select.rb +5 -14
  24. data/lib/slack/block_kit/element/multi_static_select.rb +18 -25
  25. data/lib/slack/block_kit/element/multi_users_select.rb +5 -14
  26. data/lib/slack/block_kit/element/overflow_menu.rb +4 -11
  27. data/lib/slack/block_kit/element/radio_buttons.rb +53 -0
  28. data/lib/slack/block_kit/element/static_select.rb +20 -25
  29. data/lib/slack/block_kit/element/timepicker.rb +49 -0
  30. data/lib/slack/block_kit/element/users_select.rb +3 -11
  31. data/lib/slack/block_kit/layout/header.rb +29 -0
  32. data/lib/slack/block_kit/layout/image.rb +1 -4
  33. data/lib/slack/block_kit/layout/input.rb +198 -3
  34. data/lib/slack/block_kit/layout/section.rb +21 -1
  35. data/lib/slack/block_kit/version.rb +7 -0
  36. data/lib/slack/surfaces/home.rb +35 -0
  37. data/lib/slack/surfaces/message.rb +34 -0
  38. data/lib/slack/surfaces/modal.rb +76 -0
  39. data/slack-ruby-block-kit.gemspec +1 -18
  40. metadata +20 -138
  41. data/.circleci/config.yml +0 -49
  42. data/Gemfile.lock +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba4b59b1f8d591f6560563d913833ea5193d3c0ad1ff46e30b4484949d8cfeda
4
- data.tar.gz: 90c8576e1fadb6b9a17d8e6c76f9c871e073fa0cab1e9178a26959b80e62b1fa
3
+ metadata.gz: 0f8259eb752347ee6abf3210ab4b0f0c44ee962d238e3034185735c4762a8063
4
+ data.tar.gz: 7649061472dff64eddb8704311ee17afbd0c29d07ac6d101982725fbf55fbd35
5
5
  SHA512:
6
- metadata.gz: 37e969657c3cd6f54fd0f4d9a77292b4740917463823b84af9325a87455b6b686af353d98769a09d6e36e2ddd503e62fc1d460f981c359326deb87232349d89c
7
- data.tar.gz: af06784a17f10737b24c85b3ee2b59dd34f0bd61da21e19234d1cca04e213a195ca5698ec8ddbb876dd3a8fdf5894814b2c39da65305747f78a907401fbf5ccb
6
+ metadata.gz: d9ab666ea3cca8ca7ade809cb1fc3881e534d5a9ffb1651f2de2d1ddc30266e6d44ac1a89947b1cba62d35ba59e292479ec33e0098fe50d1b6d7a1d1e77a0184
7
+ data.tar.gz: 709140300213ec4afef7c43665e56dd9ccfe673118284d2cb5efbe5a03c87ee9d42fed94e6c8277cc49ffec74d5232108d1b0555c53dcc7e23cc77f6cc70413d
@@ -0,0 +1,15 @@
1
+ version = 1
2
+
3
+ test_patterns = ["spec/**/*_spec.rb"]
4
+
5
+ [[analyzers]]
6
+ name = "test-coverage"
7
+ enabled = true
8
+
9
+ [[analyzers]]
10
+ name = "ruby"
11
+ enabled = true
12
+
13
+ [[transformers]]
14
+ name = "rubocop"
15
+ enabled = true
@@ -0,0 +1,33 @@
1
+ name: Test & Lint
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ env:
10
+ DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ continue-on-error: ${{ matrix.experimental }}
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: [ '2.6', '2.7', '3.0' ]
20
+ experimental: [ false ]
21
+ name: Ruby ${{ matrix.ruby }}
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ - run: curl https://deepsource.io/cli | sh
28
+ - run: gem install bundler:2.1.4
29
+ - run: bundle install
30
+ - run: bundle exec rubocop
31
+ - run: bundle exec rspec --format progress
32
+ - run: ./bin/deepsource report --analyzer test-coverage --key ruby --value-file ./coverage/.resultset.json
33
+ if: (github.event_name == 'push') || (github.event.pull_request.head.repo.full_name == github.repository) # don't run on forks which don't have access to DEEPSOURCE_DSN
data/.gitignore CHANGED
@@ -8,6 +8,8 @@
8
8
  /spec/examples.txt
9
9
  /tmp/
10
10
 
11
+ Gemfile.lock
12
+
11
13
  # rspec failure tracking
12
14
  .rspec_status
13
15
  *.gem
@@ -1,8 +1,12 @@
1
- require: rubocop-rspec
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
2
5
  inherit_from: .rubocop_todo.yml
3
6
 
4
7
  AllCops:
5
8
  TargetRubyVersion: 2.5.3
9
+ NewCops: enable
6
10
 
7
11
  Layout/LineLength:
8
12
  Max: 120
@@ -53,3 +57,21 @@ Style/HashTransformValues:
53
57
 
54
58
  Style/SlicingWithRange:
55
59
  Enabled: true
60
+
61
+ Lint/MixedRegexpCaptureTypes:
62
+ Enabled: true
63
+
64
+ Style/RedundantFetchBlock:
65
+ Enabled: true
66
+
67
+ Style/RedundantRegexpCharacterClass:
68
+ Enabled: true
69
+
70
+ Style/RedundantRegexpEscape:
71
+ Enabled: true
72
+
73
+ RSpec/MultipleMemoizedHelpers:
74
+ Max: 10
75
+
76
+ RSpec/NestedGroups:
77
+ Max: 4
@@ -17,6 +17,12 @@ Metrics/BlockLength:
17
17
  Metrics/ClassLength:
18
18
  Max: 117
19
19
 
20
+ # Offense count: 1
21
+ # Configuration parameters: IgnoredMethods.
22
+ Metrics/CyclomaticComplexity:
23
+ Exclude:
24
+ - 'lib/slack/block_kit/element/multi_static_select.rb'
25
+
20
26
  # Offense count: 5
21
27
  # Configuration parameters: Max.
22
28
  RSpec/ExampleLength:
@@ -24,6 +30,10 @@ RSpec/ExampleLength:
24
30
  - 'spec/lib/slack/block_kit/composition/confirmation_dialog_spec.rb'
25
31
  - 'spec/lib/slack/block_kit/composition/option_group_spec.rb'
26
32
  - 'spec/lib/slack/block_kit/composition/option_spec.rb'
33
+ - 'spec/lib/slack/block_kit/element/checkboxes_spec.rb'
34
+ - 'spec/lib/slack/block_kit/element/radio_buttons_spec.rb'
35
+ - 'spec/lib/slack/block_kit/composition/option_spec.rb'
36
+ - 'spec/lib/slack/block_kit/element/multi_static_select_spec.rb'
27
37
 
28
38
  # Offense count: 4
29
39
  Style/Documentation:
@@ -0,0 +1,93 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+ - N/A
11
+
12
+ ### Changed
13
+ - N/A
14
+
15
+ ### Deprecated
16
+ - N/A
17
+
18
+ ### Removed
19
+ - N/A
20
+
21
+ ### Fixed
22
+ - N/A
23
+
24
+ ### Security
25
+ - N/A
26
+
27
+
28
+ ---
29
+
30
+ ## [0.13.0] - 2020-12-29
31
+
32
+ ### Added
33
+ - Ruby3 Support
34
+ - `Slack::BlockKit::Element::Timepicker` (#72)
35
+ - Add `input` to `Slack::BlockKit::Blocks` and elements to `Slack::BlockKit::Layout::Input` (#73)
36
+
37
+ ### Changed
38
+ - Development dependencies now managed by bundler via Gemfile, rather than in gemspec
39
+
40
+
41
+ ---
42
+
43
+
44
+ ## [0.12.0] - 2020-10-06
45
+
46
+ ### Added
47
+ - `Slack::BlockKit::Layout::Header` (#57)
48
+
49
+ ### Removed
50
+ - `Slack::BlockKit::Element::Checkboxes#initial`, use the `initial:` keyword on `#option`
51
+ - `Slack::BlockKit::Element::MultiStaticSelect#initial`, use the `initial:` keyword on `#option`
52
+ - `Slack::BlockKit::Element::StaticSelect#initial`, use the `initial:` keyword on `#option`
53
+
54
+
55
+ ---
56
+
57
+
58
+ ## [0.11.0] - 2020-10-03
59
+
60
+ ### Added
61
+ - Add `Slack::BlockKit::Element::RadioButtons` (#52 by @caalberts)
62
+
63
+ ### Changed
64
+ - Internal refactoring of `#confirmation_dialog` methods into a shared `Confirmable` module. (#48)
65
+
66
+ ### Fixed
67
+ - Ruby2.7 kwarg deprecation warnings
68
+
69
+
70
+ ---
71
+
72
+
73
+ ## [0.10.0] - 2020-09-11
74
+
75
+ ### Added
76
+ - Add `Slack::BlockKit::Element::Checkboxes` (#44 by @caalberts)
77
+
78
+ ### Fixed
79
+ - Fixed initial options in multi select blocks (#46 by @caalberts)
80
+
81
+
82
+ ---
83
+
84
+ See [releases] for previous changes.
85
+
86
+
87
+ [Unreleased]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.13.0...HEAD
88
+ [0.13.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.12.0...v0.13.0
89
+ [0.12.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.11.0...v0.12.0
90
+ [0.11.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.10.0...v0.11.0
91
+ [0.10.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.9.0...v0.10.0
92
+
93
+ [releases]: https://github.com/CGA1123/slack-ruby-block-kit/releases
data/Gemfile CHANGED
@@ -2,5 +2,18 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in tenios-rb.gemspec
6
5
  gemspec
6
+
7
+ gem 'dotenv', '~> 2'
8
+ gem 'faraday', '~> 1'
9
+ gem 'pry', '~> 0.13'
10
+ gem 'rake', '~> 13'
11
+ gem 'rspec', '~> 3'
12
+ gem 'rspec_junit_formatter', '~> 0.4'
13
+
14
+ gem 'rubocop', '~> 1', require: false
15
+ gem 'rubocop-rake', '~> 0.5', require: false
16
+ gem 'rubocop-rspec', '~> 2', require: false
17
+
18
+ gem 'codecov', '~> 0.2', require: false
19
+ gem 'simplecov', '~> 0.20', require: false if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
- [![CircleCI](https://circleci.com/gh/CGA1123/slack-ruby-block-kit/tree/master.svg?style=svg)](https://circleci.com/gh/CGA1123/slack-ruby-block-kit/tree/master)
2
1
  [![Gem Version](https://badge.fury.io/rb/slack-ruby-block-kit.svg)](https://badge.fury.io/rb/slack-ruby-block-kit)
2
+ [![codecov](https://codecov.io/gh/CGA1123/slack-ruby-block-kit/branch/master/graph/badge.svg)](https://codecov.io/gh/CGA1123/slack-ruby-block-kit)
3
+ [![DeepSource](https://deepsource.io/gh/CGA1123/slack-ruby-block-kit.svg/?label=active+issues&show_trend=true)](https://deepsource.io/gh/CGA1123/slack-ruby-block-kit/?ref=repository-badge)
4
+ [![DeepSource](https://deepsource.io/gh/CGA1123/slack-ruby-block-kit.svg/?label=resolved+issues&show_trend=true)](https://deepsource.io/gh/CGA1123/slack-ruby-block-kit/?ref=repository-badge)
3
5
 
4
6
  # Slack::BlockKit
5
7
 
@@ -3,15 +3,16 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Composition; end
6
+
6
7
  module Element; end
7
- module Layout; end
8
8
 
9
- VERSION = '0.8.0'
9
+ module Layout; end
10
10
 
11
11
  Dir[File.join(__dir__, 'block_kit', 'composition', '*.rb')].sort.each { |file| require file }
12
12
  Dir[File.join(__dir__, 'block_kit', 'element', '*.rb')].sort.each { |file| require file }
13
13
  Dir[File.join(__dir__, 'block_kit', 'layout', '*.rb')].sort.each { |file| require file }
14
14
  Dir[File.join(__dir__, 'block_kit', '*.rb')].sort.each { |file| require file }
15
+ Dir[File.join(__dir__, 'surfaces', '*.rb')].sort.each { |file| require file }
15
16
 
16
17
  module_function
17
18
 
@@ -22,5 +23,48 @@ module Slack
22
23
 
23
24
  blocks
24
25
  end
26
+
27
+ def home(blocks: nil,
28
+ private_metadata: nil, callback_id: nil, external_id: nil)
29
+ home_surface = Slack::Surfaces::Home.new(blocks: blocks,
30
+ private_metadata: private_metadata,
31
+ callback_id: callback_id,
32
+ external_id: external_id)
33
+
34
+ yield(home_surface) if block_given?
35
+
36
+ home_surface
37
+ end
38
+
39
+ def modal(title: nil,
40
+ blocks: nil,
41
+ private_metadata: nil, callback_id: nil, external_id: nil,
42
+ clear_on_close: nil, notify_on_close: nil)
43
+ modal_surface = Slack::Surfaces::Modal.new(title: title,
44
+ blocks: blocks,
45
+ private_metadata: private_metadata,
46
+ callback_id: callback_id,
47
+ external_id: external_id,
48
+ clear_on_close: clear_on_close,
49
+ notify_on_close: notify_on_close)
50
+
51
+ yield(modal_surface) if block_given?
52
+
53
+ modal_surface
54
+ end
55
+
56
+ def message(blocks: nil, channel: nil, thread_ts: nil, as_user: nil, text: nil)
57
+ message_surface = Slack::Surfaces::Message.new(
58
+ blocks: blocks,
59
+ channel: channel,
60
+ thread_ts: thread_ts,
61
+ text: text,
62
+ as_user: as_user
63
+ )
64
+
65
+ yield(message_surface) if block_given?
66
+
67
+ message_surface
68
+ end
25
69
  end
26
70
  end
@@ -57,6 +57,18 @@ module Slack
57
57
  append(block)
58
58
  end
59
59
 
60
+ def input(label:, hint: nil, block_id: nil)
61
+ block = Layout::Input.new(
62
+ label: label,
63
+ hint: hint,
64
+ block_id: block_id
65
+ )
66
+
67
+ yield(block) if block_given?
68
+
69
+ append(block)
70
+ end
71
+
60
72
  def append(block)
61
73
  @blocks << block
62
74
 
@@ -9,6 +9,22 @@ module Slack
9
9
  #
10
10
  # https://api.slack.com/reference/messaging/composition-objects#confirm
11
11
  class ConfirmationDialog
12
+ # {Confirmable} contains the common behaviour for configuring a
13
+ # {ConfirmationDialog}
14
+ module Confirmable
15
+ def self.included(klass)
16
+ klass.attr_accessor :confirm
17
+ end
18
+
19
+ def confirmation_dialog
20
+ self.confirm = Composition::ConfirmationDialog.new
21
+
22
+ yield(confirm) if block_given?
23
+
24
+ self
25
+ end
26
+ end
27
+
12
28
  def initialize
13
29
  @title, @confirm, @text, @style = nil
14
30
  end
@@ -8,11 +8,16 @@ module Slack
8
8
  # https://api.slack.com/reference/messaging/composition-objects#option
9
9
  # https://api.slack.com/reference/messaging/block-elements#select
10
10
  class Option
11
- def initialize(value:, text:, emoji: nil, description: nil, url: nil)
11
+ def initialize(value:, text:, initial: false, emoji: nil, description: nil, url: nil)
12
12
  @text = PlainText.new(text: text, emoji: emoji)
13
13
  @value = value
14
14
  @description = description && PlainText.new(text: description, emoji: emoji)
15
15
  @url = url
16
+ @initial = initial
17
+ end
18
+
19
+ def initial?
20
+ !!@initial
16
21
  end
17
22
 
18
23
  def as_json(*)
@@ -17,8 +17,8 @@ module Slack
17
17
  yield(self) if block_given?
18
18
  end
19
19
 
20
- def option(text:, value:, emoji: nil)
21
- @options << Option.new(text: text, value: value, emoji: emoji)
20
+ def option(text:, value:, emoji: nil, initial: false)
21
+ @options << Option.new(text: text, value: value, emoji: emoji, initial: initial)
22
22
 
23
23
  self
24
24
  end
@@ -9,9 +9,9 @@ module Slack
9
9
  #
10
10
  # https://api.slack.com/reference/messaging/block-elements#button
11
11
  class Button
12
- TYPE = 'button'
12
+ include Composition::ConfirmationDialog::Confirmable
13
13
 
14
- attr_accessor :confirm
14
+ TYPE = 'button'
15
15
 
16
16
  def initialize(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
17
17
  @text = Composition::PlainText.new(text: text, emoji: emoji)
@@ -23,14 +23,6 @@ module Slack
23
23
  yield(self) if block_given?
24
24
  end
25
25
 
26
- def confirmation_dialog
27
- @confirm = Composition::ConfirmationDialog.new
28
-
29
- yield(@confirm) if block_given?
30
-
31
- @confirm
32
- end
33
-
34
26
  def as_json(*)
35
27
  {
36
28
  type: TYPE,
@@ -39,7 +31,7 @@ module Slack
39
31
  url: @url,
40
32
  value: @value,
41
33
  style: @style,
42
- confirm: @confirm&.as_json
34
+ confirm: confirm&.as_json
43
35
  }.compact
44
36
  end
45
37
  end
@@ -13,9 +13,9 @@ module Slack
13
13
  #
14
14
  # https://api.slack.com/reference/messaging/block-elements#channel-select
15
15
  class ChannelsSelect
16
- TYPE = 'channels_select'
16
+ include Composition::ConfirmationDialog::Confirmable
17
17
 
18
- attr_accessor :confirm
18
+ TYPE = 'channels_select'
19
19
 
20
20
  def initialize(placeholder:, action_id:, initial: nil, emoji: nil)
21
21
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
@@ -25,21 +25,13 @@ module Slack
25
25
  yield(self) if block_given?
26
26
  end
27
27
 
28
- def confirmation_dialog
29
- @confirm = Composition::ConfirmationDialog.new
30
-
31
- yield(@confirm) if block_given?
32
-
33
- self
34
- end
35
-
36
28
  def as_json(*)
37
29
  {
38
30
  type: TYPE,
39
31
  placeholder: @placeholder.as_json,
40
32
  action_id: @action_id,
41
33
  initial_channel: @initial_channel,
42
- confirm: @confirm&.as_json
34
+ confirm: confirm&.as_json
43
35
  }.compact
44
36
  end
45
37
  end