smart_todo 1.3.0 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e7fe4f3876be333b1df4dcd44d965e57a0725e65900f96a518bd6a49d608165
4
- data.tar.gz: 02b5370dfc45cc2337d973db79a3a6bddccb8ae295d2ec529eebbb166247873b
3
+ metadata.gz: b21d53a3957ea19430b3726fd82fefeceef262330ead8eb9ef1ef087acd29bb4
4
+ data.tar.gz: 3927e36c7c059e90613ceec82e8d00efc8c7e6ceceb6183d05a5cd59c466086c
5
5
  SHA512:
6
- metadata.gz: b1bcacca903ebeb350b7abbb8af580de31904bae313c08aac9ffd53351ea8d13897bda85d6ede9e12971dcf5fa3f5a68b2ebb1f71bcbfddd443c34e6ee6c65fc
7
- data.tar.gz: 970874dccc0323c3b009ec22a083c5096172390fe7c34bb698958cd9e89deb958f5be69dc26145c945a1aac7d740875656ea8a9eb0372dfecbd7ca04745a0a2a
6
+ metadata.gz: f92dd70f82426b84d8a651a9963dffbf6b66017c484b25371b68c16495bf2cdb28faba9fdb31a0ab56ffbb5f848f1a877375379c4c94ca946bb16d9630d7d075
7
+ data.tar.gz: 69aa57c5583a6adba8320783171eeaef3814e9e758c81b3c81bbd455c3d238d72d145be44c5fa6732764d7561beac2c19181f8344462f209346572bb23f6bf3d
@@ -2,9 +2,9 @@ name: CI
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
5
+ branches: [ main ]
6
6
  pull_request:
7
- branches: [ master ]
7
+ branches: [ main ]
8
8
 
9
9
  jobs:
10
10
  build:
@@ -0,0 +1,22 @@
1
+ name: Contributor License Agreement (CLA)
2
+
3
+ on:
4
+ pull_request_target:
5
+ types: [opened, synchronize]
6
+ issue_comment:
7
+ types: [created]
8
+
9
+ jobs:
10
+ cla:
11
+ runs-on: ubuntu-latest
12
+ if: |
13
+ (github.event.issue.pull_request
14
+ && !github.event.issue.pull_request.merged_at
15
+ && contains(github.event.comment.body, 'signed')
16
+ )
17
+ || (github.event.pull_request && !github.event.pull_request.merged)
18
+ steps:
19
+ - uses: Shopify/shopify-cla-action@v1
20
+ with:
21
+ github-token: ${{ secrets.GITHUB_TOKEN }}
22
+ cla-token: ${{ secrets.CLA_TOKEN }}
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_todo (1.3.0)
4
+ smart_todo (1.4.3)
5
5
  rexml
6
6
 
7
7
  GEM
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Shopify
3
+ Copyright (c) 2019-present Shopify
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/dev.yml CHANGED
@@ -4,8 +4,12 @@ type:
4
4
  - ruby
5
5
 
6
6
  up:
7
- - ruby: 2.7.4
7
+ - ruby: 3.0.2
8
8
  - bundler
9
9
 
10
+ console:
11
+ desc: 'start a console'
12
+ run: bin/console
13
+
10
14
  test:
11
15
  bundle exec rake test
@@ -8,7 +8,7 @@ module SmartTodo
8
8
 
9
9
  # @return void
10
10
  def dispatch
11
- puts slack_message({})
11
+ puts slack_message({}, nil)
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "cgi"
3
4
  require "net/http"
4
5
  require "json"
5
6
 
@@ -37,14 +38,14 @@ module SmartTodo
37
38
  # @param email [String]
38
39
  # @return [Hash]
39
40
  #
40
- # @raise [Net::HTTPError] in case the reques to Slack failed
41
- # @raise [SlackClient::Error] in case Slack returs a { ok: false } in the body
41
+ # @raise [Net::HTTPError] in case the request to Slack failed
42
+ # @raise [SlackClient::Error] in case Slack returns a { ok: false } in the body
42
43
  #
43
44
  # @see https://api.slack.com/methods/users.lookupByEmail
44
45
  def lookup_user_by_email(email)
45
46
  headers = { "Content-Type" => "application/x-www-form-urlencoded" }
46
47
 
47
- request(:get, "/api/users.lookupByEmail?email=#{email}", nil, headers)
48
+ request(:get, "/api/users.lookupByEmail?email=#{CGI.escape(email)}", nil, headers)
48
49
  end
49
50
 
50
51
  # Send a message to a Slack channel or to a user
@@ -53,8 +54,8 @@ module SmartTodo
53
54
  # @param text [String] The message to send
54
55
  # @return [Hash]
55
56
  #
56
- # @raise [Net::HTTPError] in case the reques to Slack failed
57
- # @raise [SlackClient::Error] in case Slack returs a { ok: false } in the body
57
+ # @raise [Net::HTTPError] in case the request to Slack failed
58
+ # @raise [SlackClient::Error] in case Slack returns a { ok: false } in the body
58
59
  #
59
60
  # @see https://api.slack.com/methods/chat.postMessage
60
61
  def post_message(channel, text)
@@ -68,8 +69,8 @@ module SmartTodo
68
69
  # @param data [String] JSON encoded data when making a POST request
69
70
  # @param headers [Hash]
70
71
  #
71
- # @raise [Net::HTTPError] in case the reques to Slack failed
72
- # @raise [SlackClient::Error] in case Slack returs a { ok: false } in the body
72
+ # @raise [Net::HTTPError] in case the request to Slack failed
73
+ # @raise [SlackClient::Error] in case Slack returns a { ok: false } in the body
73
74
  def request(method, endpoint, data = nil, headers = {})
74
75
  response = case method
75
76
  when :post, :patch
@@ -87,8 +88,8 @@ module SmartTodo
87
88
  # (Net::HTTPOK, Net::HTTPNotFound ...)
88
89
  # @return [Hash]
89
90
  #
90
- # @raise [Net::HTTPError] in case the reques to Slack failed
91
- # @raise [SlackClient::Error] in case Slack returs a { ok: false } in the body
91
+ # @raise [Net::HTTPError] in case the request to Slack failed
92
+ # @raise [SlackClient::Error] in case Slack returns a { ok: false } in the body
92
93
  def slack_response!(response)
93
94
  raise(Net::HTTPError.new("Request to slack failed", response)) unless response.code_type < Net::HTTPSuccess
94
95
  body = JSON.parse(response.body)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SmartTodo
4
- VERSION = "1.3.0"
4
+ VERSION = "1.4.3"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "smart_todo/parser/metadata_parser"
3
+ require "smart_todo"
4
4
 
5
5
  module RuboCop
6
6
  module Cop
@@ -10,29 +10,44 @@ module RuboCop
10
10
  #
11
11
  # @see https://rubocop.readthedocs.io/en/latest/extensions/#loading-extensions
12
12
  class SmartTodoCop < Cop
13
- MSG = "Don't write regular TODO comments. Write SmartTodo compatible syntax comments." \
14
- "For more info please look at https://github.com/shopify/smart_todo"
13
+ HELP = "For more info please look at https://github.com/Shopify/smart_todo/wiki/Syntax"
14
+ MSG = "Don't write regular TODO comments. Write SmartTodo compatible syntax comments. #{HELP}"
15
15
 
16
16
  # @param processed_source [RuboCop::ProcessedSource]
17
17
  # @return [void]
18
18
  def investigate(processed_source)
19
19
  processed_source.comments.each do |comment|
20
20
  next unless /^#\sTODO/ =~ comment.text
21
- next if smart_todo?(comment.text)
22
-
23
- add_offense(comment)
21
+ metadata = metadata(comment.text)
22
+ if !smart_todo?(metadata)
23
+ add_offense(comment)
24
+ elsif (methods = invalid_event_methods(metadata.events)).any?
25
+ add_offense(comment, message: "Invalid event method(s): #{methods.join(", ")}. #{HELP}")
26
+ end
24
27
  end
25
28
  end
26
29
 
30
+ private
31
+
27
32
  # @param comment [String]
28
- # @return [true, false]
29
- def smart_todo?(comment)
30
- metadata = ::SmartTodo::Parser::MetadataParser.parse(comment.gsub(/^#/, ""))
33
+ # @return [SmartTodo::Parser::Visitor]
34
+ def metadata(comment)
35
+ ::SmartTodo::Parser::MetadataParser.parse(comment.gsub(/^#/, ""))
36
+ end
31
37
 
38
+ # @param metadata [SmartTodo::Parser::Visitor]
39
+ # @return [true, false]
40
+ def smart_todo?(metadata)
32
41
  metadata.events.any? &&
33
42
  metadata.events.all? { |event| event.is_a?(::SmartTodo::Parser::MethodNode) } &&
34
43
  metadata.assignees.any?
35
44
  end
45
+
46
+ # @param metadata [Array<SmartTodo::Parser::MethodNode>]
47
+ # @return [Array<String>]
48
+ def invalid_event_methods(events)
49
+ events.map(&:method_name).reject { |method| ::SmartTodo::Events.respond_to?(method) }
50
+ end
36
51
  end
37
52
  end
38
53
  end
data/service.yml CHANGED
@@ -1 +0,0 @@
1
- classification: library
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_todo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-22 00:00:00.000000000 Z
11
+ date: 2023-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rexml
@@ -92,6 +92,7 @@ extensions: []
92
92
  extra_rdoc_files: []
93
93
  files:
94
94
  - ".github/workflows/build.yml"
95
+ - ".github/workflows/cla.yml"
95
96
  - ".github/workflows/rubocop.yml"
96
97
  - ".gitignore"
97
98
  - ".rubocop.yml"
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  - !ruby/object:Gem::Version
149
150
  version: '0'
150
151
  requirements: []
151
- rubygems_version: 3.2.20
152
+ rubygems_version: 3.3.3
152
153
  signing_key:
153
154
  specification_version: 4
154
155
  summary: Enhance todo's comments in your codebase.