Class: Snitch::SvnLook

Inherits:
Object
  • Object
show all
Defined in:
lib/snitch/svnlook.rb

Overview

This is a wrapper around the svnlook command line utility. I saw someone else using it so I did. I haven’t looked around for other options but I will as I’m not a fan of relying on command line stuff.

svnlook = Snitch::SvnLook.new('/var/www/apps/yourapp/repos/', 101)
puts svnlook.author, svnlook.project # etc, etc, etc.

The svnlook bin file defaults to /usr/bin/svnlook. To override the location of svnlook, just pass in a third parameter to the new method like so:

svnlook = Snitch::SvnLook.new('/var/www/apps/yourapp/repos/', 101, '/usr/local/bin/svnlook')

Constant Summary collapse

LOG_PREPEND =
'\n-{2}'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, revision, svn_look_path = nil) ⇒ SvnLook

Returns a new instance of SvnLook.



16
17
18
19
# File 'lib/snitch/svnlook.rb', line 16

def initialize(repository, revision, svn_look_path=nil)
  @repository, @revision, @svnlook = repository, revision, svn_look_path
  @svnlook = svn_look_path || '/usr/bin/svnlook'
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



14
15
16
# File 'lib/snitch/svnlook.rb', line 14

def repository
  @repository
end

#revisionObject (readonly)

Returns the value of attribute revision.



14
15
16
# File 'lib/snitch/svnlook.rb', line 14

def revision
  @revision
end

Instance Method Details

#affectedObject

Returns the affected files of the committed revision



43
44
45
# File 'lib/snitch/svnlook.rb', line 43

def affected
  @affected ||= changed.inject('') { |str, line| str << " - #{line}"; str }
end

#authorObject

Does an svn look for the author of the commit. Can’t be in the fancy meta programming above because it needs to get a newline chopped off.



25
26
27
# File 'lib/snitch/svnlook.rb', line 25

def author
  look(:author).chop
end

#messageObject

Returns the message entered with the committed revision



38
39
40
# File 'lib/snitch/svnlook.rb', line 38

def message
  @message ||= log.split(%r{#{LOG_PREPEND}}).inject('') { |str, log_item| str << " - #{log_item.gsub(/-/, '').capitalize}"; str }
end

#projectObject

Returns a best guess of the projects name. Assumes that most will be /some/path/to/cabin/repos/ or /some/path/to/cabin. Will grab the last two folders in the path and remove any that are equal to “repos”.



32
33
34
35
# File 'lib/snitch/svnlook.rb', line 32

def project
  # @project ||= repository.split('/')[-2]
  @project ||= repository.split('/')[-2, 2].detect { |a| a != 'repos' }
end

#to_s(which = :long) ⇒ Object

Outputs the SvnLook in a pretty format for pasting into campfire



48
49
50
51
52
53
54
55
56
57
# File 'lib/snitch/svnlook.rb', line 48

def to_s(which=:long)
  case which.to_s
  when 'long'
    "[#{project}] Revision #{revision} Committed by #{author}:\n#{message}\nChanged Files:\n#{affected}"
  when 'short'
    str = "[#{project}] Revision #{revision} Committed by #{author}:"        
    str += message.size > 137 ? message[0, (140 - str.size)] + '...' : message
    str.gsub("\n", ' ')
  end
end