class Danger::DangerWCC::Todos
Constants
- LINK_REGEX
- TODO_REGEX
Public Class Methods
new(plugin, options = {})
click to toggle source
# File lib/wcc/todos.rb, line 12 def initialize(plugin, options = {}) @plugin = plugin @options = options end
Public Instance Methods
perform()
click to toggle source
# File lib/wcc/todos.rb, line 17 def perform find_new_todos.each do |result| issue_message(result) end end
Private Instance Methods
find_link_in_context(file, line)
click to toggle source
# File lib/wcc/todos.rb, line 61 def find_link_in_context(file, line) context = grab_context_lines(file, line.line_number.right) context.each_with_index do |l, i| if m = l.match(LINK_REGEX) # line at index 0 in the context array is (line.line_number.right - 1) return [line.line_number.right - 1 + i, m.captures[0]] end end nil end
find_new_todos()
click to toggle source
# File lib/wcc/todos.rb, line 37 def find_new_todos find_in_diff(TODO_REGEX) do |_m, line, _hunk, file, _diff| make_violation(file, line) end end
grab_context_lines(file, line_number)
click to toggle source
# File lib/wcc/todos.rb, line 55 def grab_context_lines(file, line_number) contents = File.read(file.b_path) # grab the line and the lines immediately before and after it contents.lines[max(line_number - 2, 0)..line_number] end
issue_message(result)
click to toggle source
# File lib/wcc/todos.rb, line 25 def issue_message(result) if result[:link] plugin.message "TODO added in #{result[:file_link]} "\ "referencing [#{result[:link]}](#{result[:link]})", file: result[:file], line: result[:line] else plugin.warn "TODO added in #{result[:file_link]} - "\ 'is there a card associated with that?', file: result[:file], line: result[:line] end end
make_violation(file, todo_line)
click to toggle source
# File lib/wcc/todos.rb, line 43 def make_violation(file, todo_line) link_line_number, link = find_link_in_context(file, todo_line) { link: link, file: file.b_path, file_link: @plugin.github.html_link(file.b_path), line: max(link_line_number, todo_line.line_number.right), warn: link.nil? } end
max(a, b)
click to toggle source
# File lib/wcc/todos.rb, line 72 def max(a, b) return a if b.nil? return b if a.nil? a > b ? a : b end