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.



38
39
40
# File 'lib/lazylead/task/svn/grep.rb', line 38

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



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

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



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

def svn_log(opts)
  cmd = [
    "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']}"
  ]
  stdout = `#{cmd.join(" ")}`
  stdout.split("-" * 72).reject(&:blank?).reverse.map { |e| Entry.new(e) }
end