Class: Lazylead::Task::Svn::Touch
- Inherits:
-
Object
- Object
- Lazylead::Task::Svn::Touch
- Defined in:
- lib/lazylead/task/svn/touch.rb
Overview
Send notification about modification of critical files in svn repo.
Instance Method Summary collapse
-
#initialize(log = Log.new) ⇒ Touch
constructor
A new instance of Touch.
- #run(_, postman, opts) ⇒ Object
-
#svn_log(opts) ⇒ Object
Return all svn commits for particular date range in repo.
-
#to_entry(xml) ⇒ Object
Convert single revision(XML text) to entry object.
-
#to_struct(hsh) ⇒ Object
Make a simple ruby struct object from hash hierarchically, considering nested hash(es) (if applicable).
-
#touch(files, opts) ⇒ Object
Return all svn commits for a particular date range, which are touching somehow the critical files within the svn repo.
Constructor Details
Instance Method Details
#run(_, postman, opts) ⇒ Object
42 43 44 45 46 |
# File 'lib/lazylead/task/svn/touch.rb', line 42 def run(_, postman, opts) files = opts.slice("files", ",") commits = touch(files, opts) postman.send(opts.merge(entries: commits)) unless commits.empty? end |
#svn_log(opts) ⇒ Object
Return all svn commits for particular date range in repo
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/lazylead/task/svn/touch.rb', line 60 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 --no-auth-cache", "--username #{opts.decrypt('svn_user', 'svn_salt')}", "--password #{opts.decrypt('svn_password', 'svn_salt')}", "--xml -v -r {#{start}}:{#{now}} #{opts['svn_url']}" ] raw = `#{cmd.join(" ")}` Nokogiri.XML(raw, nil, "UTF-8") end |
#to_entry(xml) ⇒ Object
Convert single revision(XML text) to entry object. Entry object is a simple ruby struct object.
79 80 81 82 83 84 85 86 87 |
# File 'lib/lazylead/task/svn/touch.rb', line 79 def to_entry(xml) e = to_struct(Hash.from_xml(xml.to_s.strip)).logentry if e.paths.path.respond_to? :each e.paths.path.each(&:strip!) else e.paths.path.strip! end e end |
#to_struct(hsh) ⇒ Object
Make a simple ruby struct object from hash hierarchically,
considering nested hash(es) (if applicable)
91 92 93 94 95 |
# File 'lib/lazylead/task/svn/touch.rb', line 91 def to_struct(hsh) OpenStruct.new( hsh.transform_values { |v| v.is_a?(Hash) ? to_struct(v) : v } ) end |
#touch(files, opts) ⇒ Object
Return all svn commits for a particular date range, which are touching
somehow the critical files within the svn repo.
50 51 52 53 54 55 56 57 |
# File 'lib/lazylead/task/svn/touch.rb', line 50 def touch(files, opts) xpath = files.map { |f| "contains(text(),\"#{f}\")" }.join(" or ") svn_log(opts).xpath("//logentry[paths/path[#{xpath}]]") .map { |xml| to_entry(xml) } .each do |e| e.paths.path.delete_if { |p| files.none? { |f| p.include? f } } if e.paths.path.respond_to? :delete_if end end |