slkecho 2.0.1 → 2.1.0
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/CHANGELOG.md +7 -0
- data/README.md +8 -0
- data/exe/slkecho +1 -1
- data/lib/slkecho/blocks_builder.rb +23 -0
- data/lib/slkecho/cli.rb +13 -5
- data/lib/slkecho/option_parser.rb +4 -1
- data/lib/slkecho/options.rb +1 -1
- data/lib/slkecho/slack_client.rb +0 -12
- data/lib/slkecho/slack_request/post_message.rb +6 -14
- data/lib/slkecho/version.rb +1 -1
- data/lib/slkecho.rb +1 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aa38817dd7a85a9bb6a39924da65ad1d45173c29b058347481c1f98e62b37a0
|
4
|
+
data.tar.gz: 963364abf7315212c650aa05650634dc3662e3bd1728adaaa83e89f9f94d5ad7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1079f1a9c85669cb0ea19a6879b9d724a389f3bf7c23dfbd716fb9fc73dffda189c1d42a9dd8674a90d7decf42037a8adc4b9f32a6718230673b0c27f5c71acd
|
7
|
+
data.tar.gz: 33b784774eb1c33908807c0600af4e9113dfa28ffb957da395ed2742741db00360bb7741f80fdb94990daf08ddb768925eaf02efcd2f977b8435fe395b005ca7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [v2.1.0] - 2024-01-19
|
4
|
+
|
5
|
+
- feat: Add --message-as-blocks option
|
6
|
+
- fix: Require libraries
|
7
|
+
- style: Enable RuboCop new cops and fix offenses
|
8
|
+
- style: Add rubocop-performance and fix offenses
|
9
|
+
|
3
10
|
## [v2.0.1] - 2024-01-17
|
4
11
|
|
5
12
|
- feat: Add Dockerfile
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Slkecho
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/slkecho)
|
4
|
+
|
3
5
|
Slkecho is a CLI tool to post message to Slack like echo command.
|
4
6
|
|
5
7
|
## Installation
|
@@ -63,6 +65,12 @@ Set user image for message by emoji.
|
|
63
65
|
|
64
66
|
See below: https://api.slack.com/methods/chat.postMessage#arg_icon_emoji
|
65
67
|
|
68
|
+
### --message-as-blocks (optional)
|
69
|
+
|
70
|
+
Post message as blocks.
|
71
|
+
|
72
|
+
See below: https://api.slack.com/methods/chat.postMessage#arg_blocks
|
73
|
+
|
66
74
|
## Contributing
|
67
75
|
|
68
76
|
Bug reports and pull requests are welcome on GitHub at https://github.com/okonomi/slkecho.
|
data/exe/slkecho
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Slkecho
|
6
|
+
class BlocksBuilder
|
7
|
+
def build_from_message(message, user_id = nil)
|
8
|
+
[
|
9
|
+
{
|
10
|
+
"type" => "section",
|
11
|
+
"text" => {
|
12
|
+
"type" => "mrkdwn",
|
13
|
+
"text" => user_id.nil? ? message : "<@#{user_id}> #{message}"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_from_json(json, user_id = nil)
|
20
|
+
JSON.parse(json.gsub("<mention>", "<@#{user_id}>"))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/slkecho/cli.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "optparse"
|
4
|
-
|
5
3
|
module Slkecho
|
6
4
|
class CLI
|
7
|
-
def initialize(option_parser:, slack_client:)
|
5
|
+
def initialize(option_parser:, slack_client:, blocks_builder:)
|
8
6
|
@option_parser = option_parser
|
9
7
|
@slack_client = slack_client
|
8
|
+
@blocks_builder = blocks_builder
|
10
9
|
end
|
11
10
|
|
12
11
|
def run(argv)
|
@@ -27,17 +26,26 @@ module Slkecho
|
|
27
26
|
def post_message_params_from(options, user_id)
|
28
27
|
Slkecho::SlackClient::PostMessageParams.new(
|
29
28
|
channel: options.channel,
|
30
|
-
|
29
|
+
blocks: blocks_from(options.message, user_id, options.message_as_blocks),
|
31
30
|
username: options.username,
|
32
31
|
icon_url: options.icon_url,
|
33
32
|
icon_emoji: options.icon_emoji
|
34
33
|
)
|
35
34
|
end
|
36
35
|
|
36
|
+
def blocks_from(message, user_id, message_as_blocks)
|
37
|
+
if message_as_blocks
|
38
|
+
@blocks_builder.build_from_json(message, user_id)
|
39
|
+
else
|
40
|
+
@blocks_builder.build_from_message(message, user_id)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
37
44
|
def self.run(argv)
|
38
45
|
cli = new(
|
39
46
|
option_parser: Slkecho::OptionParser.new,
|
40
|
-
slack_client: Slkecho::SlackClient.new(slack_api_token: Slkecho.configuration.slack_api_token)
|
47
|
+
slack_client: Slkecho::SlackClient.new(slack_api_token: Slkecho.configuration.slack_api_token),
|
48
|
+
blocks_builder: Slkecho::BlocksBuilder.new
|
41
49
|
)
|
42
50
|
cli.run(argv)
|
43
51
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "optparse"
|
4
|
+
|
3
5
|
module Slkecho
|
4
6
|
class OptionParser
|
5
|
-
def option_parser # rubocop:disable Metrics/AbcSize
|
7
|
+
def option_parser # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
6
8
|
@option_parser ||= ::OptionParser.new do |o|
|
7
9
|
o.banner = "Usage: slkecho [options] message"
|
8
10
|
o.program_name = "slkecho"
|
@@ -12,6 +14,7 @@ module Slkecho
|
|
12
14
|
o.on("--username USERNAME", "Set user name for message.") { @options.username = _1 }
|
13
15
|
o.on("--icon-url ICON_URL", "Set user icon image for message by URL.") { @options.icon_url = _1 }
|
14
16
|
o.on("--icon-emoji ICON_EMOJI", "Set user image for message by emoji.") { @options.icon_emoji = _1 }
|
17
|
+
o.on("--message-as-blocks", "Post message as blocks.") { @options.message_as_blocks = true }
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
data/lib/slkecho/options.rb
CHANGED
data/lib/slkecho/slack_client.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "net/http"
|
4
|
-
require "uri"
|
5
|
-
require "json"
|
6
|
-
|
7
3
|
require_relative "slack_request/lookup_user_by_email"
|
8
4
|
require_relative "slack_request/post_message"
|
9
5
|
|
@@ -13,14 +9,6 @@ module Slkecho
|
|
13
9
|
|
14
10
|
def initialize(slack_api_token:)
|
15
11
|
@slack_api_token = slack_api_token
|
16
|
-
|
17
|
-
@uri = URI.parse("https://slack.com/api/chat.postMessage")
|
18
|
-
@http = Net::HTTP.new(@uri.host, @uri.port)
|
19
|
-
@http.use_ssl = true
|
20
|
-
@headers = {
|
21
|
-
"Content-Type" => "application/json; charset=utf-8",
|
22
|
-
"Authorization" => "Bearer #{slack_api_token}"
|
23
|
-
}
|
24
12
|
end
|
25
13
|
|
26
14
|
def lookup_user_by_email(email:)
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
require "json"
|
6
|
+
|
3
7
|
module Slkecho
|
4
8
|
module SlackRequest
|
5
9
|
class PostMessage
|
6
|
-
Params = Struct.new(:channel, :
|
10
|
+
Params = Struct.new(:channel, :blocks, :username, :icon_url, :icon_emoji, keyword_init: true)
|
7
11
|
|
8
12
|
def initialize(slack_api_token:)
|
9
13
|
@slack_api_token = slack_api_token
|
@@ -34,24 +38,12 @@ module Slkecho
|
|
34
38
|
def request_body(params)
|
35
39
|
{
|
36
40
|
"channel" => params.channel,
|
37
|
-
"blocks" =>
|
41
|
+
"blocks" => params.blocks,
|
38
42
|
"username" => params.username,
|
39
43
|
"icon_url" => params.icon_url,
|
40
44
|
"icon_emoji" => params.icon_emoji
|
41
45
|
}
|
42
46
|
end
|
43
|
-
|
44
|
-
def blocks_from(message)
|
45
|
-
[
|
46
|
-
{
|
47
|
-
"type" => "section",
|
48
|
-
"text" => {
|
49
|
-
"type" => "mrkdwn",
|
50
|
-
"text" => message
|
51
|
-
}
|
52
|
-
}
|
53
|
-
]
|
54
|
-
end
|
55
47
|
end
|
56
48
|
end
|
57
49
|
end
|
data/lib/slkecho/version.rb
CHANGED
data/lib/slkecho.rb
CHANGED
@@ -6,6 +6,7 @@ require_relative "slkecho/cli"
|
|
6
6
|
require_relative "slkecho/options"
|
7
7
|
require_relative "slkecho/option_parser"
|
8
8
|
require_relative "slkecho/slack_client"
|
9
|
+
require_relative "slkecho/blocks_builder"
|
9
10
|
|
10
11
|
module Slkecho
|
11
12
|
class InvalidConfigurationError < StandardError
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slkecho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okonomi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Post message to Slack like echo command.
|
14
14
|
email:
|
@@ -23,6 +23,7 @@ files:
|
|
23
23
|
- README.md
|
24
24
|
- exe/slkecho
|
25
25
|
- lib/slkecho.rb
|
26
|
+
- lib/slkecho/blocks_builder.rb
|
26
27
|
- lib/slkecho/cli.rb
|
27
28
|
- lib/slkecho/configuration.rb
|
28
29
|
- lib/slkecho/option_parser.rb
|
@@ -40,7 +41,8 @@ metadata:
|
|
40
41
|
source_code_uri: https://github.com/okonomi/slkecho
|
41
42
|
changelog_uri: https://github.com/okonomi/slkecho/blob/main/CHANGELOG.md
|
42
43
|
github_repo: https://github.com/okonomi/slkecho
|
43
|
-
|
44
|
+
rubygems_mfa_required: 'true'
|
45
|
+
post_install_message:
|
44
46
|
rdoc_options: []
|
45
47
|
require_paths:
|
46
48
|
- lib
|
@@ -56,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
58
|
version: '0'
|
57
59
|
requirements: []
|
58
60
|
rubygems_version: 3.5.3
|
59
|
-
signing_key:
|
61
|
+
signing_key:
|
60
62
|
specification_version: 4
|
61
63
|
summary: Post message to Slack like echo command.
|
62
64
|
test_files: []
|