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.



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

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

Instance Method Details

#run(_, postman, opts) ⇒ Object



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

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 postman, opts.merge(stdout: stdout) unless stdout.blank?
end

#send_email(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.


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

def send_email(postman, opts)
  Dir.mktmpdir do |dir|
    name = "svn-log-#{Date.today.strftime('%d-%b-%Y')}.html"
    f = File.open(File.join(dir, name), "w")
    begin
      f.write opts.msg_body("template-attachment")
      f.close
      postman.send opts.merge(attachments: [f.path])
    ensure
      File.delete(f)
    end
  rescue StandardError => e
    @log.error "ll-010: Can't send an email for #{opts} due to " \
               "#{Backtrace.new(e)}'"
  end
end