Class: Lazylead::Task::Svn::Diff

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

Overview

Send notification about modification of svn files since particular

revision.

Instance Method Summary collapse

Constructor Details

#initialize(log = Log.new) ⇒ Diff

Returns a new instance of Diff.



39
40
41
# File 'lib/lazylead/task/svn/diff.rb', line 39

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

Instance Method Details

#run(_, postman, opts) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/lazylead/task/svn/diff.rb', line 43

def run(_, postman, opts)
  cmd = [
    "svn log --diff --no-auth-cache",
    "--username #{opts.decrypt('svn_user', 'svn_salt')}",
    "--password #{opts.decrypt('svn_password', 'svn_salt')}",
    "-r#{opts['since_rev']}:HEAD #{opts['svn_url']}"
  ]
  stdout = `#{cmd.join(" ")}`
  send_email stdout, postman, opts unless stdout.blank?
end

#send_email(stdout, postman, opts) ⇒ Object

Send email with svn log as an attachment. The attachment won’t be stored locally and we’ll be removed once

mail sent.


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lazylead/task/svn/diff.rb', line 57

def send_email(stdout, postman, opts)
  Dir.mktmpdir do |dir|
    name = "svn-log-#{Date.today.strftime('%d-%b-%Y')}.html"
    f = File.open(File.join(dir, name), "w")
    f.write(
      Email.new(
        opts["template-attachment"],
        opts.merge(stdout: stdout, version: Lazylead::VERSION)
      ).render
    )
    postman.send opts.merge(stdout: stdout, attachments: [f.path])
  rescue StandardError => e
    @log.error "ll-010: Can't send an email for #{opts} based on "\
             "'#{stdout}'", e
  end
end