smart_todo 1.0.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 +7 -0
- data/.gitignore +8 -0
- data/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml +1027 -0
- data/.rubocop.yml +5 -0
- data/.shopify-build/VERSION +1 -0
- data/.shopify-build/smart-todo.yml +37 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/rubocop +29 -0
- data/bin/setup +8 -0
- data/dev.yml +11 -0
- data/exe/smart_todo +14 -0
- data/lib/smart_todo/cli.rb +74 -0
- data/lib/smart_todo/dispatcher.rb +99 -0
- data/lib/smart_todo/events/date.rb +26 -0
- data/lib/smart_todo/events/gem_release.rb +69 -0
- data/lib/smart_todo/events/pull_request_close.rb +86 -0
- data/lib/smart_todo/events.rb +52 -0
- data/lib/smart_todo/parser/comment_parser.rb +71 -0
- data/lib/smart_todo/parser/metadata_parser.rb +116 -0
- data/lib/smart_todo/parser/todo_node.rb +43 -0
- data/lib/smart_todo/slack_client.rb +113 -0
- data/lib/smart_todo/version.rb +5 -0
- data/lib/smart_todo.rb +22 -0
- data/lib/smart_todo_cop.rb +37 -0
- data/shipit.rubygems.yml +1 -0
- data/smart_todo.gemspec +38 -0
- metadata +152 -0
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v1
|
@@ -0,0 +1,37 @@
|
|
1
|
+
containers:
|
2
|
+
ruby-2.3:
|
3
|
+
docker: circleci/ruby:2.3
|
4
|
+
ruby-2.4:
|
5
|
+
docker: circleci/ruby:2.4
|
6
|
+
ruby-2.5:
|
7
|
+
docker: circleci/ruby:2.5
|
8
|
+
ruby-2.6:
|
9
|
+
docker: circleci/ruby:2.6
|
10
|
+
|
11
|
+
shared:
|
12
|
+
defaults: &defaults
|
13
|
+
timeout: 5m
|
14
|
+
dependencies:
|
15
|
+
- bundler
|
16
|
+
run:
|
17
|
+
- bundle exec rake test
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- label: ":cop: Ruby style check"
|
21
|
+
timeout: 5m
|
22
|
+
container: ruby-2.5
|
23
|
+
dependencies:
|
24
|
+
- bundler
|
25
|
+
run: bin/rubocop
|
26
|
+
- label: ":ruby: Ruby 2.3"
|
27
|
+
container: ruby-2.3
|
28
|
+
<<: *defaults
|
29
|
+
- label: ":ruby: Ruby 2.4"
|
30
|
+
container: ruby-2.4
|
31
|
+
<<: *defaults
|
32
|
+
- label: ":ruby: Ruby 2.5"
|
33
|
+
container: ruby-2.5
|
34
|
+
<<: *defaults
|
35
|
+
- label: ":ruby: Ruby 2.6"
|
36
|
+
container: ruby-2.6
|
37
|
+
<<: *defaults
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at edouard.chin@shopify.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
smart_todo (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.6.0)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
ast (2.4.0)
|
12
|
+
crack (0.4.3)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
hashdiff (0.4.0)
|
15
|
+
jaro_winkler (1.5.3)
|
16
|
+
minitest (5.11.3)
|
17
|
+
parallel (1.17.0)
|
18
|
+
parser (2.6.3.0)
|
19
|
+
ast (~> 2.4.0)
|
20
|
+
public_suffix (3.1.1)
|
21
|
+
rainbow (3.0.0)
|
22
|
+
rake (10.5.0)
|
23
|
+
rubocop (0.71.0)
|
24
|
+
jaro_winkler (~> 1.5.1)
|
25
|
+
parallel (~> 1.10)
|
26
|
+
parser (>= 2.6)
|
27
|
+
rainbow (>= 2.2.2, < 4.0)
|
28
|
+
ruby-progressbar (~> 1.7)
|
29
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
30
|
+
ruby-progressbar (1.10.1)
|
31
|
+
safe_yaml (1.0.5)
|
32
|
+
unicode-display_width (1.6.0)
|
33
|
+
webmock (3.6.0)
|
34
|
+
addressable (>= 2.3.6)
|
35
|
+
crack (>= 0.3.2)
|
36
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bundler (~> 1.17)
|
43
|
+
minitest (~> 5.0)
|
44
|
+
rake (~> 10.0)
|
45
|
+
rubocop (~> 0.71)
|
46
|
+
smart_todo!
|
47
|
+
webmock
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Shopify
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
<h3 align="center">
|
2
|
+
<img src="https://user-images.githubusercontent.com/8122246/61341925-b936d180-a848-11e9-95c1-0d2f398c51b1.png?raw=true" width="200">
|
3
|
+
</h3>
|
4
|
+
|
5
|
+
[](https://buildkite.com/shopify/smart-todo?branch=master)
|
6
|
+
|
7
|
+
_SmartTodo_ is a library designed to assign users on TODO comments written in your codebase and help assignees be reminded when it's time to commit to their TODO.
|
8
|
+
|
9
|
+
Installation
|
10
|
+
-----------
|
11
|
+
1) Add the gem in your Gemfile.
|
12
|
+
```ruby
|
13
|
+
group :development do
|
14
|
+
gem 'smart_todo', require: false # No need to require it
|
15
|
+
end
|
16
|
+
```
|
17
|
+
2) Run `bundle install`
|
18
|
+
|
19
|
+
|
20
|
+
Summary
|
21
|
+
---------
|
22
|
+
SmartTodo allows to write TODO comments alongside your code and assign a user to it.
|
23
|
+
When the TODO's event is met (i.e. a certain date is reached), the TODO's assignee will get pinged on Slack.
|
24
|
+
|
25
|
+
**Without SmartTodo**
|
26
|
+
```ruby
|
27
|
+
# TODO: Warning! We need to change the API endpoint on July 1st because the provider
|
28
|
+
# is modifying its API.
|
29
|
+
def api_call
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
-------------------
|
34
|
+
|
35
|
+
**With SmartTodo**
|
36
|
+
```ruby
|
37
|
+
# TODO(on: date('2019-07-01'), to: 'john@example.com')
|
38
|
+
# The API provider is modifying its endpoint, we need to modify our code.
|
39
|
+
def api_call
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Documentation
|
44
|
+
----------------
|
45
|
+
Please check out the GitHub [wiki](https://github.com/Shopify/smart_todo/wiki) for documentation and example on how to setup SmartTodo in your project.
|
46
|
+
|
47
|
+
License
|
48
|
+
--------
|
49
|
+
This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE.txt) file.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "smart_todo"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/rubocop
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load(Gem.bin_path("rubocop", "rubocop"))
|
data/bin/setup
ADDED
data/dev.yml
ADDED
data/exe/smart_todo
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift("#{__dir__}/../lib")
|
5
|
+
|
6
|
+
require 'smart_todo'
|
7
|
+
|
8
|
+
unless ENV['ENABLE_SMART_TODO']
|
9
|
+
puts 'Not running SmartTodo since the ENABLE_SMART_TODO ENV is not set'
|
10
|
+
|
11
|
+
exit(0)
|
12
|
+
end
|
13
|
+
|
14
|
+
SmartTodo::CLI.new.run
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optionparser"
|
4
|
+
|
5
|
+
module SmartTodo
|
6
|
+
# This class is the entrypoint of the SmartTodo library and is responsible
|
7
|
+
# to retrieve the command line options as well as iterating over each files/directories
|
8
|
+
# to run the +CommentParser+ on.
|
9
|
+
class CLI
|
10
|
+
def initialize
|
11
|
+
@options = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param args [Array<String>]
|
15
|
+
def run(args = ARGV)
|
16
|
+
paths = define_options.parse!(args)
|
17
|
+
validate_options!
|
18
|
+
paths << '.' if paths.empty?
|
19
|
+
|
20
|
+
paths.each do |path|
|
21
|
+
normalize_path(path).each do |file|
|
22
|
+
parse_file(file)
|
23
|
+
|
24
|
+
STDOUT.print('.')
|
25
|
+
STDOUT.flush
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @raise [ArgumentError] if the +slack_token+ or the +fallback_channel+
|
31
|
+
# options are not passed to the command line
|
32
|
+
# @return [void]
|
33
|
+
def validate_options!
|
34
|
+
@options[:slack_token] ||= ENV.fetch('SMART_TODO_SLACK_TOKEN') { raise(ArgumentError, 'Missing :slack_token') }
|
35
|
+
|
36
|
+
@options.fetch(:fallback_channel) { raise(ArgumentError, 'Missing :fallback_channel') }
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [OptionParser] an instance of OptionParser
|
40
|
+
def define_options
|
41
|
+
OptionParser.new do |opts|
|
42
|
+
opts.banner = "Usage: smart_todo [options] file_or_path1 file_or_path2 ..."
|
43
|
+
opts.on('--slack_token TOKEN') do |token|
|
44
|
+
@options[:slack_token] = token
|
45
|
+
end
|
46
|
+
opts.on('--fallback_channel CHANNEL') do |channel|
|
47
|
+
@options[:fallback_channel] = channel
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# @param path [String] a path to a file or directory
|
53
|
+
# @return [Array<String>] all the directories the parser should run on
|
54
|
+
def normalize_path(path)
|
55
|
+
if File.file?(path)
|
56
|
+
[path]
|
57
|
+
else
|
58
|
+
Dir["#{path}/**/*.rb"]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param file [String] a path to a file
|
63
|
+
def parse_file(file)
|
64
|
+
Parser::CommentParser.new(File.read(file, encoding: 'UTF-8')).parse.each do |todo_node|
|
65
|
+
event_message = nil
|
66
|
+
event_met = todo_node.metadata.events.find do |event|
|
67
|
+
event_message = Events.public_send(event.method_name, *event.arguments)
|
68
|
+
end
|
69
|
+
|
70
|
+
Dispatcher.new(event_message, todo_node, file, @options).dispatch if event_met
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,99 @@
|
|
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
|