snitch 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -0,0 +1,5 @@
1
+ 0.1.1 - 3/25/2007
2
+ * added documentation; the first release didn't have hardly any
3
+
4
+ 0.1.0 - 3/25/2007
5
+ * initial release of snitch
data/Rakefile CHANGED
@@ -52,3 +52,13 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
52
52
  p.extra_deps << %w[ twitter tinder activesupport ]
53
53
  #p.spec_extras - A hash of extra values to set in the gemspec.
54
54
  end
55
+
56
+ desc 'Publish HTML to RubyForge'
57
+ task :publish_html do
58
+ config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
59
+ host = "#{config["username"]}@rubyforge.org"
60
+ remote_dir = "/var/www/gforge-projects/snitch/"
61
+ local_dir = 'html'
62
+ sh %{rsync -av --delete #{local_dir}/ #{host}:#{remote_dir}}
63
+ `rake publish_docs`
64
+ end
data/lib/snitch.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # This file simply includes the gems and snitch files needed.
2
+
1
3
  %w[uri yaml rubygems active_support].each { |x| require x }
2
4
 
3
5
  require 'snitch/base'
data/lib/snitch/base.rb CHANGED
@@ -2,6 +2,13 @@ module Snitch
2
2
  class Base
3
3
  attr_reader :services, :config
4
4
 
5
+ # Creates a new instance of snitch from a repository path and a revision.
6
+ #
7
+ # Snitch::Base.new('/var/www/apps/myapp/repos', 102)
8
+ #
9
+ # 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
10
+ #
11
+ # Snitch::Base.new('/var/www/apps/myapp/repos', 102, '/some/other/path/to/config')
5
12
  def initialize(repository, revision, config_file='/home/deploy/.snitch')
6
13
  Config.config_file_path = config_file unless config_file.nil?
7
14
  @config = Config::load
@@ -10,14 +17,26 @@ module Snitch
10
17
  @config[:services].each { |s, attrs| use(s, attrs) }
11
18
  end
12
19
 
20
+ # Obtains the commit message from the svnlook class. Takes either <tt>:long</tt> or <tt>:short</tt> as optional parameter.
21
+ # * <tt>:long</tt> is the full commit message along with a list of all changed files.
22
+ # * <tt>:short</tt> is a truncated version of the commit message that is less than 140 characters for twitter.
13
23
  def commit_message(which=:long)
14
24
  @svnlook_bin.to_s(which)
15
25
  end
16
26
 
27
+ # Adds a service to the services array from a string or symbol of the service name and a hash of attributes.
28
+ #
29
+ # snitch = Snitch::Base.new('/var/www/apps/myapp/repos', 102)
30
+ # snitch.use(:twitter, {:login => 'jnunemaker', :password => 'secret'})
17
31
  def use(s, attrs)
18
32
  @services << Service.new_from_name(s, attrs)
19
33
  end
20
34
 
35
+ # Sends the commit message to all the added services. The following code would tattle the commit message to twitter.
36
+ #
37
+ # snitch = Snitch::Base.new('/var/www/apps/myapp/repos', 102)
38
+ # snitch.use(:twitter, {:login => 'jnunemaker', :password => 'secret'})
39
+ # snitch.tattle
21
40
  def tattle
22
41
  long = commit_message(:long)
23
42
  short = commit_message(:short)
data/lib/snitch/config.rb CHANGED
@@ -3,14 +3,17 @@ module Snitch
3
3
  @@snitch_config_path = '/home/deploy/.snitch'
4
4
 
5
5
  class << self
6
+ # Returns the path to the config file.
6
7
  def config_file_path
7
8
  @@snitch_config_path
8
9
  end
9
10
 
11
+ # Allows you to change the config file path.
10
12
  def config_file_path=(new_path)
11
13
  @@snitch_config_path = new_path
12
14
  end
13
15
 
16
+ # Loads the config file. If the file does not exist, it creates it and fills in a blank template that only needs settings.
14
17
  def load
15
18
  begin
16
19
  config = YAML::load(open(@@snitch_config_path)).symbolize_keys!
@@ -20,6 +23,7 @@ module Snitch
20
23
  end
21
24
  end
22
25
 
26
+ # Creates a config file based on a template.
23
27
  def create
24
28
  snitch_config_tpl = <<EOF
25
29
  # what is the location of svnlook (you can find this on *nix boxes by typing `which svnlook`)
@@ -1,4 +1,5 @@
1
1
  module Snitch
2
+ # Service is the base class for all services. All services should inherit from this class.
2
3
  class Service
3
4
  attr_reader :base, :attributes
4
5
 
@@ -10,7 +11,10 @@ module Snitch
10
11
  # Don't allow changing the commit message from outside the class
11
12
  protected :message_length=
12
13
 
13
- # Handy for creating a new instance of a service from the config file
14
+ # Handy for creating a new instance of a service from the config file. Simply pass in the service name and the attributes for the service and you get a new instance of the service.
15
+ #
16
+ # Snitch::Service.new_from_name(:twitter, {:login => 'jnunemaker', :password => 'secret'})
17
+ # # => #<Snitch::Services::Twitter:0x15a6508 @attributes={:login=>"jnunemaker", :password=>"secret"}>
14
18
  def new_from_name(s, attributes)
15
19
  service = "Snitch::Services::#{s.to_s.camelize}".constantize
16
20
  service.new(attributes)
@@ -21,6 +25,14 @@ module Snitch
21
25
  @attributes = attributes
22
26
  end
23
27
 
28
+ # Uses method missing to return the value of a key in the attributes hash.
29
+ # Allows for doing this...
30
+ #
31
+ # service.login
32
+ #
33
+ # instead of this...
34
+ #
35
+ # service.attributes[:login]
24
36
  def method_missing(method, *args, &block)
25
37
  if method.to_s =~ /=$/
26
38
  @attributes[method.to_s.chop] = args[0]
@@ -1,10 +1,13 @@
1
1
  require 'tinder'
2
2
  module Snitch
3
3
  module Services
4
+ # Allows for using tinder the unnofficial campfire api to paste a commit message into a campfire chatroom.
4
5
  class Campfire < Service
5
6
 
7
+ # Sets the prefferred commit message length to <tt>:long</tt>
6
8
  self.message_length = :long
7
9
 
10
+ # Logs into campfire and enters the room in the config file.
8
11
  def connection(force=false)
9
12
  if @campfire.nil? || force
10
13
  connection = ::Tinder::Campfire.new(subdomain)
@@ -15,6 +18,7 @@ module Snitch
15
18
  @campfire
16
19
  end
17
20
 
21
+ # Pastes a given message into a campfire room using the connection method.
18
22
  def tattle(message)
19
23
  connection.paste(message)
20
24
  end
@@ -1,15 +1,19 @@
1
1
  require 'twitter'
2
2
  module Snitch
3
3
  module Services
4
+ # Allows for using the twitter api to post a commit message update.
4
5
  class Twitter < Service
5
6
 
7
+ # Sets the prefferred commit message length to <tt>:short</tt>
6
8
  self.message_length = :short
7
9
 
10
+ # Logs into twitter.
8
11
  def connection(force=false)
9
12
  @twitter = ::Twitter::Base.new(login, password) if @twitter.nil? || force
10
13
  @twitter
11
14
  end
12
15
 
16
+ # Posts a given message to twitter using the connection method.
13
17
  def tattle(message)
14
18
  connection.update(message)
15
19
  end
@@ -1,16 +1,12 @@
1
1
  module Snitch
2
- # This is a wrapper around the svnlook command line utility. I saw someone
3
- # else using it so I did. I haven't looked around for other options but I will
4
- # as I'm not a fan of relying on command line stuff.
2
+ # 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.
5
3
  #
6
4
  # svnlook = Snitch::SvnLook.new('/var/www/apps/yourapp/repos/', 101)
7
5
  # puts svnlook.author, svnlook.project # etc, etc, etc.
8
6
  #
9
- # The svnlook bin file defaults to /usr/bin/svnlook. To override the location
10
- # of svnlook, just pass in a third parameter to the new method like so:
7
+ # 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:
11
8
  #
12
9
  # svnlook = Snitch::SvnLook.new('/var/www/apps/yourapp/repos/', 101, '/usr/local/bin/svnlook')
13
- #
14
10
  class SvnLook
15
11
 
16
12
  LOG_PREPEND = '\n-{2}'
@@ -25,17 +21,13 @@ module Snitch
25
21
  # Creates a few helper methods for looking at the subversion commit
26
22
  %w[changed date diff log].each { |m| define_method(m) { look m } }
27
23
 
28
- # Does an svn look for the author of the commit.
29
- # Can't be in the fancy meta programming above because
30
- # it needs to get a newline chopped off
24
+ # 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.
31
25
  def author
32
26
  look(:author).chop
33
27
  end
34
28
 
35
- # Returns a best guess of the projects name.
36
- # Assumes that most will be /some/path/to/cabin/repos/.
37
- # Using the aforementioned path, this would return cabin
38
- # as the project name.
29
+ # Returns a best guess of the projects name. Assumes that most will be /some/path/to/cabin/repos/.
30
+ # Using the aforementioned path, this would return cabin as the project name.
39
31
  def project
40
32
  @project ||= repository.split('/')[-2]
41
33
  end
@@ -2,7 +2,7 @@ module Snitch #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: snitch
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
6
+ version: 0.1.1
7
7
  date: 2007-03-25 00:00:00 -04:00
8
8
  summary: Makes tattling on your svn commits to other services simple
9
9
  require_paths: