Permalink
Browse files

Abstracting Revision.

  • Loading branch information...
1 parent 24d490a commit 265ef52aa36facb90081f43b88d985a08015bdde @jqr jqr committed Aug 29, 2008
Showing with 34 additions and 21 deletions.
  1. +1 −0 Manifest.txt
  2. +2 −9 lib/snitch.rb
  3. +21 −0 lib/snitch/revision.rb
  4. +4 −5 lib/snitch/revisions/git.rb
  5. +6 −7 lib/snitch/revisions/subversion.rb
View
@@ -12,6 +12,7 @@ lib/snitch/services/echo.rb
lib/snitch/services/campfire.rb
lib/snitch/services/email.rb
lib/snitch/services/twitter.rb
+lib/snitch/revision.rb
lib/snitch/revisions/subversion.rb
lib/snitch/revisions/git.rb
lib/snitch/version.rb
View
@@ -9,6 +9,7 @@
require 'snitch/services/email'
require 'snitch/services/twitter'
require 'snitch/message'
+require 'snitch/revision'
require 'snitch/revisions/subversion'
require 'snitch/revisions/git'
require 'snitch/version'
@@ -22,15 +23,7 @@ def initialize(repository, revision, options)
config_file = options[:config_file]
Config.config_file_path = config_file unless config_file.nil?
@config = Config::load
- @revision =
- case options[:scm]
- when :git
- Revisions::Git.new(repository, revision)
- when :subversion
- Revisions::Subversion.new(repository, revision)
- else
- raise "Unrecognized scm: #{options[:scm].inspect}"
- end
+ @revision = Revision.new_from_name(options[:scm], repository, revision)
@services = []
@config[:services].each { |s, attrs| use(s, attrs) }
View
@@ -0,0 +1,21 @@
+class Snitch
+ class Revision
+ attr_accessor :repository_path, :revision
+
+ def initialize(repository_path, revision)
+ self.repository_path, self.revision = repository_path, revision
+ end
+
+ def self.new_from_name(name, repository_path, revision)
+ case name
+ when :git
+ Revisions::Git.new(repository_path, revision)
+ when :subversion
+ Revisions::Subversion.new(repository_path, revision)
+ else
+ raise "Unrecognized scm: #{name}"
+ end
+ end
+
+ end
+end
@@ -1,14 +1,13 @@
class Snitch
module Revisions
- class Git
+ class Git < Revision
include Message
gem 'mojombo-grit'
require 'mojombo-grit'
- attr_reader :repository
-
- def initialize(repository, revision = nil)
- @repository, @revision = Grit::Repo.new(repository), revision
+ def initialize(repository_path, revision = nil)
+ super
+ @repository = Grit::Repo.new(repository_path)
@commit = revision ? @repository.commit( revision ) : @repository.commits.first
end
@@ -1,13 +1,12 @@
class Snitch
module Revisions
- class Subversion
+ class Subversion < Revision
include Message
LOG_PREPEND = '\n-{2}'
- attr_reader :repository, :revision
- def initialize(repository, revision)
- @repository, @revision, @svnlook = repository, revision
+ def initialize(repository_path, revision)
+ super
@svnlook = `which svnlook`
end
@@ -22,8 +21,8 @@ def author
# /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' }
+ # @project ||= repository_path.split('/')[-2]
+ @project ||= repository_path.split('/')[-2, 2].detect { |a| a != 'repos' }
end
def message
@@ -37,7 +36,7 @@ def affected
private
def look(method)
- `#{@svnlook} #{method.to_s} #{repository} -r #{revision}`
+ `#{@svnlook} #{method.to_s} #{repository_path} -r #{revision}`
end
end
end

0 comments on commit 265ef52

Please sign in to comment.