Permalink
Browse files

Merge branch 'master' of git://github.com/jqr/snitch into jqr/master

Conflicts:

	Manifest.txt
	lib/snitch.rb
	lib/snitch/gitcommit.rb
	test/test_helper.rb
  • Loading branch information...
jnunemaker committed Oct 26, 2008
2 parents 4d62251 + 8cf43ba commit 4c2f01697ab344e7f0b42fa683385592681698d7
View
@@ -10,36 +10,37 @@ bin/snitch
config/hoe.rb
config/requirements.rb
lib/snitch.rb
-lib/snitch/base.rb
lib/snitch/config.rb
-lib/snitch/exceptions.rb
lib/snitch/gitcommit.rb
lib/snitch/message.rb
-lib/snitch/patches/hash.rb
-lib/snitch/patches/tinder.rb
+lib/snitch/revision.rb
+lib/snitch/revisions/git.rb
+lib/snitch/revisions/subversion.rb
lib/snitch/service.rb
lib/snitch/services/campfire.rb
+lib/snitch/services/echo.rb
lib/snitch/services/email.rb
lib/snitch/services/twitter.rb
-lib/snitch/svnlook.rb
lib/snitch/version.rb
script/console
script/destroy
script/generate
script/txt2html
setup.rb
+snitch.gemspec
tasks/deployment.rake
tasks/environment.rake
tasks/website.rake
test/snitch_config
test/test_helper.rb
-test/unit/base_test.rb
-test/unit/gitcommit_test.rb
+test/unit/revisions/git_test.rb
+test/unit/revisions/subversion_test.rb
test/unit/service_test.rb
test/unit/services/campfire_test.rb
+test/unit/services/echo_test.rb
test/unit/services/email_test.rb
test/unit/services/twitter_test.rb
-test/unit/svnlook_test.rb
+test/unit/snitch_test.rb
website/css/common.css
website/images/campfire.gif
website/images/twitter.gif
View
@@ -1,7 +1,7 @@
=Snitch
-Snitch is an subversion post-commit service integration helper. I just made that up. Subversion has a post-commit hook which is executed each time you commit a change to a repository. Snitch makes it really easy to hook into the post-commit and send the commit message along with the files changed to various services on the web.
+Snitch is an git/subversion post-commit service integration helper. SCMs typically have a post commit hook which is executed each time you commit a change to a repository. Snitch makes it really easy to hook into the post-commit and send the commit message along with the files changed to various services on the web.
-Currently, snitch works with campfire and twitter. I'll be adding in SMS, email, some day but feel free to do it yourself and send me a patch.
+Snitch currently works with campfire, twitter and email.
==Installation:
View
39 bin/snitch 100644 → 100755
@@ -1,3 +1,38 @@
#!/usr/bin/env ruby
-%w[rubygems snitch].each { |x| require x }
-Snitch::Base.new(ARGV[0], ARGV[1], ARGV[2]).tattle
+
+require 'optparse'
+
+options = {
+ :verbose => false,
+ :development => false,
+ :config_file => File.expand_path('~/.snitch'),
+ :scm => :subversion,
+ :dry_run => false
+}
+
+op = OptionParser.new
+op.banner = "Usage: #{File.basename(__FILE__)} [options] repository_path revision"
+op.on('-h', '--help', "Display this help") { puts op; exit }
+op.on('-v', '--verbose', "Verbose mode") { options.verbose = true }
+op.on('-c', '--config FILE', "Configuration file to use, defaults to ~/.snitch") { |value| options[:config_file] = value }
+op.on('-d', '--development', "Development mode, runs from a directory") { options[:development] = true }
+op.on('--scm TYPE', [:git, :subversion], "Specifies source code manager: git or subversion(default)") { |value| options[:scm] = value }
+op.on('--dry-run', "Do everything but actually posting data") { options[:dry_run] = true }
+
+op.parse!(ARGV)
+
+require 'rubygems'
+
+if options[:development]
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
+end
+require 'snitch'
+
+repository_path, revision = ARGV
+
+unless repository_path && revision
+ puts op
+ exit(1)
+end
+
+Snitch.new(repository_path, revision, options).tattle
View
@@ -1,17 +1,61 @@
-# This file simply includes the gems and snitch files needed.
-
%w[uri yaml rubygems active_support mojombo-grit].each { |x| require x }
-require 'snitch/base'
+$: << File.join(File.dirname(__FILE__))
+
require 'snitch/config'
-require 'snitch/exceptions'
-require 'snitch/patches/hash'
-require 'snitch/patches/tinder'
require 'snitch/service'
+require 'snitch/services/echo'
require 'snitch/services/campfire'
require 'snitch/services/email'
require 'snitch/services/twitter'
require 'snitch/message'
-require 'snitch/svnlook'
-require 'snitch/gitcommit'
+require 'snitch/revision'
+require 'snitch/revisions/subversion'
+require 'snitch/revisions/git'
require 'snitch/version'
+
+class Snitch
+ attr_reader :services, :config
+
+ class ConfigFileLoadError < StandardError; end
+
+ def initialize(repository, revision, options)
+ config_file = options[:config_file]
+ Config.config_file_path = config_file unless config_file.nil?
+ @config = Config::load
+ @revision = Revision.new_from_name(options[:scm], repository, revision)
+
+ @services = []
+ @config[:services].each { |s, attrs| use(s, attrs) }
+ if @services.empty?
+ use('echo', :message_length => :long)
+ end
+ end
+
+ def commit_message(which = :long)
+ @revision.to_s(which)
+ end
+
+ def use(s, attrs = {})
+ @services << Service.new_from_name(s, attrs)
+ end
+
+ def tattle
+ superlong = commit_message(:superlong)
+ long = commit_message(:long)
+ short = commit_message(:short)
+ @services.each do |s|
+ message =
+ case s.message_length.to_s
+ when 'superlong'
+ superlong
+ when 'long'
+ long
+ else
+ short
+ end
+
+ s.tattle(message)
+ end
+ end
+end
View
@@ -1,48 +0,0 @@
-module Snitch
- class Base
- attr_reader :services, :config
-
- # Creates a new instance of snitch from a repository path and a revision.
- #
- # Snitch::Base.new('/var/www/apps/myapp/repos', 102)
- #
- # You must have a config file in order for this to work. You can optionally pass in the path to the config file. The default config_file is /home/deploy/.snitch
- #
- # Snitch::Base.new('/var/www/apps/myapp/repos', 102, '/some/other/path/to/config')
- def initialize(repository, revision, config_file='/home/deploy/.snitch')
- Config.config_file_path = config_file unless config_file.nil?
- @config = Config::load
- @scm = @config.key?(:git) ? GitCommit.new(repository, revision) : SvnLook.new(repository, revision, @config[:svnlook])
- @services = []
- @config[:services].each { |s, attrs| use(s, attrs) }
- end
-
- # Obtains the commit message from the svnlook class. Takes either <tt>:long</tt> or <tt>:short</tt> as optional parameter.
- # * <tt>:long</tt> is the full commit message along with a list of all changed files.
- # * <tt>:short</tt> is a truncated version of the commit message that is less than 140 characters for twitter.
- def commit_message(which=:long)
- @scm.to_s(which)
- end
-
- # Adds a service to the services array from a string or symbol of the service name and a hash of attributes.
- #
- # snitch = Snitch::Base.new('/var/www/apps/myapp/repos', 102)
- # snitch.use(:twitter, {:login => 'jnunemaker', :password => 'secret'})
- def use(s, attrs)
- @services << Service.new_from_name(s, attrs)
- end
-
- # Sends the commit message to all the added services. The following code would tattle the commit message to twitter.
- #
- # snitch = Snitch::Base.new('/var/www/apps/myapp/repos', 102)
- # snitch.use(:twitter, {:login => 'jnunemaker', :password => 'secret'})
- # snitch.tattle
- def tattle
- long = commit_message(:long)
- short = commit_message(:short)
- @services.each do |s|
- s.tattle(s.class.message_length == :long ? long : short)
- end
- end
- end
-end
View
@@ -1,22 +1,20 @@
-module Snitch
+class Snitch
class Config
@@snitch_config_path = '/home/deploy/.snitch'
class << self
- # Returns the path to the config file.
def config_file_path
@@snitch_config_path
end
- # Allows you to change the config file path.
def config_file_path=(new_path)
@@snitch_config_path = new_path
end
# Loads the config file. If the file does not exist, it creates it and fills in a blank template that only needs settings.
def load
begin
- config = YAML::load(open(@@snitch_config_path)).symbolize_keys!
+ config = YAML::load(open(@@snitch_config_path)).symbolize_keys
rescue
create
raise ConfigFileLoadError, "The config file was missing or could not be loaded because of a parse error. It should be here: #{@@snitch_config_path}. Fill it out and try again."
@@ -26,12 +24,6 @@ def load
# Creates a config file based on a template.
def create
snitch_config_tpl = <<EOF
-# what is the location of svnlook (you can find this on *nix boxes by typing `which svnlook`)
-svnlook: /usr/bin/svnlook
-
-# If you want git support, comment out the line above and uncomment this one:
-# git: true
-
# what services would you like to send commit messages to?
services:
:campfire:
View
@@ -1,4 +0,0 @@
-module Snitch
- class ConfigFileLoadError < StandardError; end
- class ServiceLoginError < StandardError; end
-end
View
@@ -15,10 +15,24 @@ def initialize(repository, revision = nil)
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 project; @repository.description end
- def message; " - #{@commit.message}" end
- def affected; @affected ||= ' - ' + @commit.diffs.map(&:b_path).join("\n - ") end
+ def revision
+ @commit.id_abbrev
+ end
+
+ def author
+ @commit.author.to_s
+ end
+
+ def project
+ @repository.description
+ end
+
+ def message
+ " - #{@commit.message}"
+ end
+
+ def affected
+ @affected ||= ' - ' + @commit.diffs.map(&:b_path).join("\n - ")
+ end
end
end
View
@@ -1,16 +1,14 @@
-module Snitch
- # This is a module for outputting snitch messages
- # it is included in the SvnLook and GitCommit classes.
- # It requires the class to support the following methods:
- # project, revision, author, message, affected (a list of files affected)
+class Snitch
module Message
# Outputs a commit in a pretty format for snitch services
- def to_s(which=:long)
+ def to_s(which = :long)
case which.to_s
+ when 'superlong'
+ "[#{project}] Revision #{revision} Committed by #{author}:\n - #{message}\nChanges:\n#{diffs}"
when 'long'
- "[#{project}] Revision #{revision} Committed by #{author}:\n#{message}\nChanged Files:\n#{affected}"
+ "[#{project}] Revision #{revision} Committed by #{author}:\n - #{message}\nChanged Files:\n#{affected}"
when 'short'
- str = "[#{project}] Revision #{revision} Committed by #{author}:"
+ str = "[#{project}] Revision #{revision} Committed by #{author}: "
str += message.size > 137 ? message[0, (140 - str.size)] + '...' : message
str.gsub("\n", ' ')
end
View
@@ -1,11 +0,0 @@
-class Hash
- def symbolize_keys!
- keys.each do |key|
- unless key.is_a?(Symbol)
- self[key.to_sym] = self[key]
- delete(key)
- end
- end
- self
- end
-end
@@ -1,9 +0,0 @@
-module Tinder
- class Campfire
- def find_or_create_room_by_name(name)
- room = find_room_by_name(name)
- room = create_room(name) if room.nil?
- room
- end
- end
-end
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
Oops, something went wrong.

0 comments on commit 4c2f016

Please sign in to comment.