-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
541 additions
and
573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ gemspec | |
group :rubocop do | ||
gem "rubocop-shopify", require: false | ||
end | ||
|
||
gem "prism", github: "ruby/prism" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "smart_todo" | ||
|
||
class NullDispatcher < SmartTodo::Dispatchers::Base | ||
class << self | ||
def validate_options!(_); end | ||
end | ||
def dispatch | ||
end | ||
end | ||
exit SmartTodo::CLI.new(NullDispatcher).run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module SmartTodo | ||
class CommentParser | ||
attr_reader :todos | ||
|
||
def initialize | ||
@todos = [] | ||
end | ||
|
||
def parse(source, filepath = "-e") | ||
parse_comments(Prism.parse_inline_comments(source, filepath), filepath) | ||
end | ||
|
||
def parse_file(filepath) | ||
parse_comments(Prism.parse_file_inline_comments(filepath), filepath) | ||
end | ||
|
||
class << self | ||
def parse(source) | ||
parser = new | ||
parser.parse(source) | ||
parser.todos | ||
end | ||
end | ||
|
||
private | ||
|
||
def parse_comments(comments, filepath) | ||
current_todo = nil | ||
|
||
comments.each do |comment| | ||
source = comment.location.slice | ||
|
||
if source.match?(/^#\sTODO\(/) | ||
todos << current_todo if current_todo | ||
current_todo = Todo.new(source, filepath) | ||
elsif current_todo && (indent = source[/^#(\s*)/, 1].length) && (indent - current_todo.indent == 2) | ||
current_todo << "#{source[(indent + 1)..]}\n" | ||
else | ||
todos << current_todo if current_todo | ||
current_todo = nil | ||
end | ||
end | ||
|
||
todos << current_todo if current_todo | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
gem("bundler") | ||
require "bundler" | ||
require "net/http" | ||
require "time" | ||
require "json" | ||
|
||
module SmartTodo | ||
# This module contains all the methods accessible for SmartTodo comments. | ||
# It is meant to be reopened by the host application in order to define | ||
|
@@ -10,23 +16,29 @@ module SmartTodo | |
# | ||
# @example Adding a custom event | ||
# module SmartTodo | ||
# module Events | ||
# class Events | ||
# def trello_card_close(card) | ||
# ... | ||
# end | ||
# end | ||
# end | ||
# | ||
# TODO(on: trello_card_close(381), to: '[email protected]') | ||
module Events | ||
extend self | ||
class Events | ||
def initialize | ||
@now = nil | ||
@spec_set = nil | ||
@rubygems_client = nil | ||
@github_client = nil | ||
@installed_ruby_version = nil | ||
end | ||
|
||
# Check if the +date+ is in the past | ||
# | ||
# @param date [String] a correctly formatted date | ||
# @return [false, String] | ||
def date(date) | ||
Date.met?(date) | ||
Date.met?(date, now) | ||
end | ||
|
||
# Check if a new version of +gem_name+ was released with the +requirements+ expected | ||
|
@@ -35,7 +47,7 @@ def date(date) | |
# @param requirements [Array<String>] a list of version specifiers | ||
# @return [false, String] | ||
def gem_release(gem_name, *requirements) | ||
GemRelease.new(gem_name, requirements).met? | ||
GemRelease.new(gem_name, requirements, rubygems_client).met? | ||
end | ||
|
||
# Check if +gem_name+ was bumped to the +requirements+ expected | ||
|
@@ -44,7 +56,7 @@ def gem_release(gem_name, *requirements) | |
# @param requirements [Array<String>] a list of version specifiers | ||
# @return [false, String] | ||
def gem_bump(gem_name, *requirements) | ||
GemBump.new(gem_name, requirements).met? | ||
GemBump.new(gem_name, requirements, spec_set).met? | ||
end | ||
|
||
# Check if the issue +issue_number+ is closed | ||
|
@@ -54,7 +66,7 @@ def gem_bump(gem_name, *requirements) | |
# @param issue_number [String, Integer] | ||
# @return [false, String] | ||
def issue_close(organization, repo, issue_number) | ||
IssueClose.new(organization, repo, issue_number, type: "issues").met? | ||
IssueClose.new(organization, repo, issue_number, github_client, type: "issues").met? | ||
end | ||
|
||
# Check if the pull request +pr_number+ is closed | ||
|
@@ -64,15 +76,41 @@ def issue_close(organization, repo, issue_number) | |
# @param pr_number [String, Integer] | ||
# @return [false, String] | ||
def pull_request_close(organization, repo, pr_number) | ||
IssueClose.new(organization, repo, pr_number, type: "pulls").met? | ||
IssueClose.new(organization, repo, pr_number, github_client, type: "pulls").met? | ||
end | ||
|
||
# Check if the installed ruby version meets requirements. | ||
# | ||
# @param requirements [Array<String>] a list of version specifiers | ||
# @return [false, String] | ||
def ruby_version(*requirements) | ||
RubyVersion.new(requirements).met? | ||
RubyVersion.new(requirements, installed_ruby_version).met? | ||
end | ||
|
||
private | ||
|
||
def now | ||
@now ||= Time.now | ||
end | ||
|
||
def spec_set | ||
@spec_set ||= Bundler.load.specs | ||
end | ||
|
||
def rubygems_client | ||
@rubygems_client ||= Net::HTTP.new("rubygems.org", Net::HTTP.https_default_port).tap do |client| | ||
client.use_ssl = true | ||
end | ||
end | ||
|
||
def github_client | ||
@github_client ||= Net::HTTP.new("api.github.com", Net::HTTP.https_default_port).tap do |client| | ||
client.use_ssl = true | ||
end | ||
end | ||
|
||
def installed_ruby_version | ||
@installed_ruby_version ||= Gem::Version.new(RUBY_VERSION) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.