Class: Lazylead::Task::Svn::Grep

Inherits:
Object
  • Object
show all
Defined in:
lib/lazylead/task/svn/grep.rb

Overview

Detect particular text in diff commit.

Instance Method Summary collapse

Constructor Details

#initialize(log = Log.new) ⇒ Grep

Returns a new instance of Grep.



40
41
42
# File 'lib/lazylead/task/svn/grep.rb', line 40

def initialize(log = Log.new)
  @log = log
end

Instance Method Details

#from(opts) ⇒ Object

The start date & time for search range



61
62
63
# File 'lib/lazylead/task/svn/grep.rb', line 61

def from(opts)
  (now(opts).to_time - opts["period"].to_i).to_datetime
end

#now(opts) ⇒ Object

The current date & time for search range



66
67
68
69
70
71
72
# File 'lib/lazylead/task/svn/grep.rb', line 66

def now(opts)
  if opts.key? "now"
    DateTime.parse(opts["now"])
  else
    DateTime.now
  end
end

#run(_, postman, opts) ⇒ Object



44
45
46
47
48
# File 'lib/lazylead/task/svn/grep.rb', line 44

def run(_, postman, opts)
  text = opts.slice("text", ",")
  commits = svn_log(opts).select { |c| c.includes? text }
  postman.send(opts.merge(entries: commits)) unless commits.empty?
end

#svn_log(opts) ⇒ Object

Return all svn commits for particular date range in repo



51
52
53
54
55
56
57
58
# File 'lib/lazylead/task/svn/grep.rb', line 51

def svn_log(opts)
  stdout = OS.new.run "svn log --diff --no-auth-cache",
                      "--username #{opts.decrypt('svn_user', 'svn_salt')}",
                      "--password #{opts.decrypt('svn_password', 'svn_salt')}",
                      "-r {#{from(opts)}}:{#{now(opts)}} #{opts['svn_url']}"
  return [] if stdout.blank?
  Lazylead::Svn::Commits.new(stdout)
end