smart_todo 1.0.2 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +27 -0
- data/.github/workflows/rubocop.yml +22 -0
- data/.rubocop.yml +3 -3
- data/Gemfile +2 -2
- data/Gemfile.lock +33 -26
- data/README.md +1 -1
- data/dev.yml +5 -1
- data/exe/smart_todo +3 -5
- data/lib/smart_todo/cli.rb +17 -11
- data/lib/smart_todo/dispatchers/base.rb +94 -0
- data/lib/smart_todo/dispatchers/output.rb +15 -0
- data/lib/smart_todo/dispatchers/slack.rb +67 -0
- data/lib/smart_todo/events/date.rb +1 -1
- data/lib/smart_todo/events/gem_bump.rb +57 -0
- data/lib/smart_todo/events/gem_release.rb +5 -5
- data/lib/smart_todo/events/issue_close.rb +7 -7
- data/lib/smart_todo/events.rb +11 -2
- data/lib/smart_todo/parser/comment_parser.rb +1 -1
- data/lib/smart_todo/parser/metadata_parser.rb +10 -7
- data/lib/smart_todo/parser/todo_node.rb +3 -3
- data/lib/smart_todo/slack_client.rb +20 -19
- data/lib/smart_todo/version.rb +1 -1
- data/lib/smart_todo.rb +15 -9
- data/lib/smart_todo_cop.rb +6 -4
- data/service.yml +1 -0
- data/smart_todo.gemspec +7 -6
- metadata +27 -23
- data/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
- data/.travis.yml +0 -15
- data/CHANGELOG.md +0 -24
- data/lib/smart_todo/dispatcher.rb +0 -99
data/.travis.yml
DELETED
data/CHANGELOG.md
DELETED
@@ -1,24 +0,0 @@
|
|
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
|
-
## [1.0.2] - 2019-08-09
|
10
|
-
### Fixed
|
11
|
-
- Fixed the SmartTodo cop to add an offense in case a SmartTodo has no assignee.
|
12
|
-
```ruby
|
13
|
-
# Bad
|
14
|
-
#
|
15
|
-
# TODO(on: date('2019-08-08'))
|
16
|
-
```
|
17
|
-
|
18
|
-
## [1.0.1] - 2019-08-06
|
19
|
-
### Fixed
|
20
|
-
- Fixed `issue_close` event making a call to the `pulls/` GH endpoint instead of the `issues/` one
|
21
|
-
|
22
|
-
## [1.0.0] - 2019-07-19
|
23
|
-
### Added
|
24
|
-
- Initial Release
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SmartTodo
|
4
|
-
# The Dispatcher handles the logic to send the Slack message
|
5
|
-
# to the assignee once its TODO came to expiration.
|
6
|
-
class Dispatcher
|
7
|
-
# @param event_message [String] the success message associated
|
8
|
-
# a specific event
|
9
|
-
# @param todo_node [SmartTodo::Parser::TodoNode]
|
10
|
-
# @param file [String] the file containing the TODO
|
11
|
-
# @param options [Hash]
|
12
|
-
def initialize(event_message, todo_node, file, options)
|
13
|
-
@event_message = event_message
|
14
|
-
@todo_node = todo_node
|
15
|
-
@options = options
|
16
|
-
@file = file
|
17
|
-
@assignee = @todo_node.metadata.assignee
|
18
|
-
end
|
19
|
-
|
20
|
-
# Make a Slack API call to dispatch the message to the user or channel
|
21
|
-
#
|
22
|
-
# @return [Hash] the Slack response
|
23
|
-
def dispatch
|
24
|
-
user = if email?
|
25
|
-
retrieve_slack_user
|
26
|
-
else
|
27
|
-
{ 'user' => { 'id' => @assignee, 'profile' => { 'first_name' => 'Team' } } }
|
28
|
-
end
|
29
|
-
|
30
|
-
client.post_message(user.dig('user', 'id'), slack_message(user))
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
# Retrieve the unique identifier of a Slack user with his email address
|
36
|
-
#
|
37
|
-
# @return [Hash] the Slack response containing the user ID
|
38
|
-
# @raise [SlackClient::Error] in case the Slack API returns an error
|
39
|
-
# other than `users_not_found`
|
40
|
-
def retrieve_slack_user
|
41
|
-
client.lookup_user_by_email(@assignee)
|
42
|
-
rescue SlackClient::Error => error
|
43
|
-
if error.error_code == 'users_not_found'
|
44
|
-
{ 'user' => { 'id' => @options[:fallback_channel] }, 'fallback' => true }
|
45
|
-
else
|
46
|
-
raise(error)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Prepare the content of the message to send to the TODO assignee
|
51
|
-
#
|
52
|
-
# @param user [Hash] contain information about a user
|
53
|
-
# @return [String]
|
54
|
-
def slack_message(user)
|
55
|
-
header = if user.key?('fallback')
|
56
|
-
unexisting_user
|
57
|
-
else
|
58
|
-
existing_user(user)
|
59
|
-
end
|
60
|
-
|
61
|
-
<<~EOM
|
62
|
-
#{header}
|
63
|
-
|
64
|
-
You have an assigned TODO in the `#{@file}` file.
|
65
|
-
#{@event_message}
|
66
|
-
|
67
|
-
Here is the associated comment on your TODO:
|
68
|
-
|
69
|
-
```
|
70
|
-
#{@todo_node.comment.strip}
|
71
|
-
```
|
72
|
-
EOM
|
73
|
-
end
|
74
|
-
|
75
|
-
# Message in case a TODO's assignee doesn't exist in the Slack organization
|
76
|
-
#
|
77
|
-
# @return [String]
|
78
|
-
def unexisting_user
|
79
|
-
"Hello :wave:,\n\n`#{@assignee}` had an assigned TODO but this user doesn't exist on Slack anymore."
|
80
|
-
end
|
81
|
-
|
82
|
-
# @param user [Hash]
|
83
|
-
def existing_user(user)
|
84
|
-
"Hello #{user.dig('user', 'profile', 'first_name')} :wave:,"
|
85
|
-
end
|
86
|
-
|
87
|
-
# @return [SlackClient] an instance of SlackClient
|
88
|
-
def client
|
89
|
-
@client ||= SlackClient.new(@options[:slack_token])
|
90
|
-
end
|
91
|
-
|
92
|
-
# Check if the TODO's assignee is a specific user or a channel
|
93
|
-
#
|
94
|
-
# @return [true, false]
|
95
|
-
def email?
|
96
|
-
@assignee.include?("@")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|