Skip to content
Browse files

Organizing revisions under Snitch::Revisions.

  • Loading branch information...
1 parent fd5eac2 commit 00d3f2e3b3765ad4920ad70ea5a88431be98cdca @jqr jqr committed Aug 29, 2008
Showing with 66 additions and 73 deletions.
  1. +2 −2 lib/snitch/base.rb
  2. +34 −32 lib/snitch/gitcommit.rb
  3. +30 −39 lib/snitch/svnlook.rb
View
4 lib/snitch/base.rb
@@ -8,9 +8,9 @@ def initialize(repository, revision, options)
@revision =
case options[:scm]
when :git
- GitCommit.new(repository, revision)
+ Revisions::Git.new(repository, revision)
when :subversion
- SvnLook.new(repository, revision, @config[:svnlook])
+ Revisions::Subversion.new(repository, revision, @config[:svnlook])
else
raise "Unrecognized scm: #{options[:scm].inspect}"
end
View
66 lib/snitch/gitcommit.rb
@@ -1,43 +1,45 @@
class Snitch
- # A simple interface class for snitch's services to use. Requires the mojombo-grit gem
- #
- # gitcommit = Snitch::GitCommit.new('/var/www/apps/yourapp.git/', 'a9s8d76f9as8d76f9sa...'
- # puts gitcommit.author, gitcommit.project # etc, etc, etc.
- #
- class GitCommit
- include Message
- require 'mojombo-grit'
+ module Revisions
+ # A simple interface class for snitch's services to use. Requires the mojombo-grit gem
+ #
+ # gitcommit = Snitch::GitCommit.new('/var/www/apps/yourapp.git/', 'a9s8d76f9as8d76f9sa...'
+ # puts gitcommit.author, gitcommit.project # etc, etc, etc.
+ #
+ class Git
+ include Message
+ require 'mojombo-grit'
- attr_reader :repository
+ attr_reader :repository
- def initialize(repository, revision = nil)
- @repository, @revision = Grit::Repo.new(repository), revision
- @commit = revision ? @repository.commit( revision ) : @repository.commits.first
- end
+ def initialize(repository, revision = nil)
+ @repository, @revision = Grit::Repo.new(repository), revision
+ @commit = revision ? @repository.commit( revision ) : @repository.commits.first
+ end
- # Only show the first 7 digits of the yucky SHA hash
- def revision
- @commit.id_abbrev
- end
+ # Only show the first 7 digits of the yucky SHA hash
+ def revision
+ @commit.id_abbrev
+ end
- def author
- @commit.author.to_s
- end
+ def author
+ @commit.author.to_s
+ end
- def project
- @repository.description
- end
+ def project
+ @repository.description
+ end
- def message
- " - #{@commit.message}"
- end
+ def message
+ " - #{@commit.message}"
+ end
- def diffs
- @diffs ||= @commit.diffs.map(&:diff).join("\n\n")
- end
+ def diffs
+ @diffs ||= @commit.diffs.map(&:diff).join("\n\n")
+ end
- def affected
- @affected ||= ' - ' + @commit.diffs.map(&:b_path).join("\n - ")
+ def affected
+ @affected ||= ' - ' + @commit.diffs.map(&:b_path).join("\n - ")
+ end
end
end
-end
+end
View
69 lib/snitch/svnlook.rb
@@ -1,53 +1,44 @@
class Snitch
- # 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')
- class SvnLook
- include Message
- LOG_PREPEND = '\n-{2}'
+ module Revisions
+ class Subversion
+ include Message
+ LOG_PREPEND = '\n-{2}'
- attr_reader :repository, :revision
+ attr_reader :repository, :revision
- def initialize(repository, revision, svn_look_path=nil)
- @repository, @revision, @svnlook = repository, revision, svn_look_path
- @svnlook = svn_look_path || '/usr/bin/svnlook'
- end
+ def initialize(repository, revision, svn_look_path=nil)
+ @repository, @revision, @svnlook = repository, revision, svn_look_path
+ @svnlook = svn_look_path || '/usr/bin/svnlook'
+ end
- # Creates a few helper methods for looking at the subversion commit
- %w[changed date diff log].each { |m| define_method(m) { look m } }
+ # Creates a few helper methods for looking at the subversion commit
+ %w[changed date diff log].each { |m| define_method(m) { look m } }
- # 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.
- def author
- look(:author).chop
- end
+ def author
+ look(:author).chop
+ end
- # 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".
- def project
- # @project ||= repository.split('/')[-2]
- @project ||= repository.split('/')[-2, 2].detect { |a| a != 'repos' }
- end
+ # 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".
+ def project
+ # @project ||= repository.split('/')[-2]
+ @project ||= repository.split('/')[-2, 2].detect { |a| a != 'repos' }
+ end
- # Returns the message entered with the committed revision
- def message
- @message ||= log.split(%r{#{LOG_PREPEND}}).inject('') { |str, log_item| str << " - #{log_item.gsub(/-/, '').capitalize}"; str }
- end
+ def message
+ @message ||= log.split(%r{#{LOG_PREPEND}}).inject('') { |str, log_item| str << " - #{log_item.gsub(/-/, '').capitalize}"; str }
+ end
- # Returns the affected files of the committed revision
- def affected
- @affected ||= changed.inject('') { |str, line| str << " - #{line}"; str }
- end
+ def affected
+ @affected ||= changed.inject('') { |str, line| str << " - #{line}"; str }
+ end
- private
- # runs an svn look command
+ private
+
def look(method)
`#{@svnlook} #{method.to_s} #{repository} -r #{revision}`
end
+ end
end
end

0 comments on commit 00d3f2e

Please sign in to comment.
Something went wrong with that request. Please try again.