smart_todo 1.0.2 → 1.3.1

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.
data/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- sudo: false
2
- cache: bundler
3
- language: ruby
4
- before_install:
5
- - gem update bundler
6
- rvm:
7
- - 2.3
8
- - 2.4
9
- - 2.5
10
- - 2.6
11
- script:
12
- - bundle exec rubocop --config .rubocop.yml
13
- - bundle exec rake test
14
- notifications:
15
- email: false
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