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

#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
59
60
61
62
63
64
65
# File 'lib/lazylead/task/svn/grep.rb', line 49

def svn_log(opts)
  now = if opts.key? "now"
          DateTime.parse(opts["now"])
        else
          DateTime.now
        end
  start = (now.to_time - opts["period"].to_i).to_datetime
  cmd = [
    "svn log --diff --no-auth-cache",
    "--username #{opts.decrypt('svn_user', 'svn_salt')}",
    "--password #{opts.decrypt('svn_password', 'svn_salt')}",
    "-r {#{start}}:{#{now}} #{opts['svn_url']}"
  ]
  stdout = `#{cmd.join(" ")}`
  stdout.split("-" * 72).reject(&:blank?).reverse
        .map { |e| Entry.new(e) }
end