slkecho 2.1.6 → 2.2.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 +6 -0
- data/README.md +4 -0
- data/exe/slkecho +0 -4
- data/lib/slkecho/cli.rb +11 -9
- data/lib/slkecho/option_parser.rb +4 -1
- data/lib/slkecho/options.rb +5 -2
- data/lib/slkecho/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27a5c0b65463136318cabb237d686c66d5e116a957e54cad2a3e96b5bacd4b26
|
4
|
+
data.tar.gz: a83950809a7c4ef56219a732409a257c3d9c9e70255cca266b385c0917ac7334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74cb2097a07867294dce7e3563737a10c08c1138fc24a0d5a67b202849c71194a4e32473152e13c1e7115d6520b66e82b38cec7891ff10b3ea170ec215bd9dd8
|
7
|
+
data.tar.gz: c74fda6c554796a2ed28fa600d18f891d8b25ef6e2a3c94bd471b591fa8a2d073e5532e8dafec93199687250172de69dbad5f947c9409c4b16fea400d6d85069
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -71,6 +71,10 @@ Post message as blocks.
|
|
71
71
|
|
72
72
|
See below: https://api.slack.com/methods/chat.postMessage#arg_blocks
|
73
73
|
|
74
|
+
### --token <token> (optional)
|
75
|
+
|
76
|
+
Pass a token to authenticate with Slack.
|
77
|
+
|
74
78
|
## Contributing
|
75
79
|
|
76
80
|
Bug reports and pull requests are welcome on GitHub at https://github.com/okonomi/slkecho.
|
data/exe/slkecho
CHANGED
@@ -9,10 +9,6 @@ end
|
|
9
9
|
|
10
10
|
begin
|
11
11
|
Slkecho::CLI.run(ARGV)
|
12
|
-
puts "Message sent successfully."
|
13
|
-
rescue Slkecho::InvalidConfigurationError => e
|
14
|
-
abort "#{e.message} Please set SLACK_API_TOKEN environment variable." if e.item == :slack_api_token
|
15
|
-
abort e.message
|
16
12
|
rescue Slkecho::InvalidOptionError => e
|
17
13
|
abort e.message
|
18
14
|
rescue Slkecho::SlackApiHttpError => e
|
data/lib/slkecho/cli.rb
CHANGED
@@ -2,24 +2,27 @@
|
|
2
2
|
|
3
3
|
module Slkecho
|
4
4
|
class CLI
|
5
|
-
def initialize(option_parser:,
|
5
|
+
def initialize(option_parser:, blocks_builder:)
|
6
6
|
@option_parser = option_parser
|
7
|
-
@slack_client = slack_client
|
8
7
|
@blocks_builder = blocks_builder
|
9
8
|
end
|
10
9
|
|
11
10
|
def run(argv)
|
12
11
|
options = @option_parser.parse(argv)
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
if options.configure
|
14
|
+
puts "Slkecho configuration"
|
15
|
+
else
|
16
|
+
slack_client = Slkecho::SlackClient.new(slack_api_token: options.token)
|
17
|
+
user_id = options.mention_by_email.nil? ? nil : email_to_user_id(slack_client, options.mention_by_email)
|
18
|
+
slack_client.post_message(post_message_params_from(options, user_id))
|
17
19
|
|
18
|
-
|
20
|
+
puts "Message sent successfully."
|
21
|
+
end
|
19
22
|
end
|
20
23
|
|
21
|
-
def email_to_user_id(email)
|
22
|
-
user =
|
24
|
+
def email_to_user_id(slack_client, email)
|
25
|
+
user = slack_client.lookup_user_by_email(email: email)
|
23
26
|
user[:id]
|
24
27
|
end
|
25
28
|
|
@@ -44,7 +47,6 @@ module Slkecho
|
|
44
47
|
def self.run(argv)
|
45
48
|
cli = new(
|
46
49
|
option_parser: Slkecho::OptionParser.new,
|
47
|
-
slack_client: Slkecho::SlackClient.new(slack_api_token: Slkecho.configuration.slack_api_token),
|
48
50
|
blocks_builder: Slkecho::BlocksBuilder.new
|
49
51
|
)
|
50
52
|
cli.run(argv)
|
@@ -9,12 +9,14 @@ module Slkecho
|
|
9
9
|
o.banner = "Usage: slkecho [options] message"
|
10
10
|
o.program_name = "slkecho"
|
11
11
|
o.version = Slkecho::VERSION
|
12
|
+
o.on("--configure", "Configure Slack API token.")
|
12
13
|
o.on("-c", "--channel CHANNEL", "Slack channel to post message.")
|
13
14
|
o.on("-m", "--mention-by-email EMAIL", "Mention to user by email.")
|
14
15
|
o.on("--username USERNAME", "Set user name for message.")
|
15
16
|
o.on("--icon-url ICON_URL", "Set user icon image for message by URL.")
|
16
17
|
o.on("--icon-emoji ICON_EMOJI", "Set user image for message by emoji.")
|
17
18
|
o.on("--message-as-blocks", "Post message as blocks.")
|
19
|
+
o.on("--token TOKEN", "Slack API token.")
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
@@ -28,7 +30,8 @@ module Slkecho
|
|
28
30
|
def build_options(argv)
|
29
31
|
option_values = {}
|
30
32
|
argv = option_parser.parse(argv, into: option_values)
|
31
|
-
option_values = option_values.transform_keys { _1.to_s.tr("-", "_") }
|
33
|
+
option_values = option_values.transform_keys { _1.to_s.tr("-", "_").to_sym }
|
34
|
+
option_values[:token] ||= ENV.fetch("SLACK_API_TOKEN", nil)
|
32
35
|
|
33
36
|
Slkecho::Options.new(option_values).tap do |opt|
|
34
37
|
opt.message = fetch_message(argv)
|
data/lib/slkecho/options.rb
CHANGED
@@ -7,6 +7,7 @@ module Slkecho
|
|
7
7
|
include ActiveModel::Model
|
8
8
|
include ActiveModel::Attributes
|
9
9
|
|
10
|
+
attribute :configure, :boolean
|
10
11
|
attribute :channel, :string
|
11
12
|
attribute :mention_by_email, :string
|
12
13
|
attribute :message, :string
|
@@ -14,9 +15,11 @@ module Slkecho
|
|
14
15
|
attribute :icon_url, :string
|
15
16
|
attribute :icon_emoji, :string
|
16
17
|
attribute :message_as_blocks, :boolean
|
18
|
+
attribute :token, :string
|
17
19
|
|
18
|
-
validates :channel, presence: { message: "is required." }
|
19
|
-
validates :message, presence: { message: "is missing." },
|
20
|
+
validates :channel, presence: { message: "is required." }, unless: -> { configure }
|
21
|
+
validates :message, presence: { message: "is missing." }, unless: -> { configure || !message.nil? }
|
22
|
+
validates :token, presence: { message: "is required." }, unless: -> { configure }
|
20
23
|
|
21
24
|
def error_message
|
22
25
|
errors.full_messages.join(" ").downcase
|
data/lib/slkecho/version.rb
CHANGED
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.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okonomi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|