commit_hookr 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Michael Bumann, Sebastian Kippe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = commit_hookr
2
+
3
+ Configurable Git commit hooks for your team. Currently comes only with a Codebase commit menu.
4
+
5
+ == Usage
6
+
7
+ 1. Install the gem
8
+
9
+ gem install commit_hookr
10
+
11
+ 2. In your Git project's root:
12
+
13
+ hookr codebase
14
+
15
+ 3. Edit .hookr to your liking. If you want to use Codebase ticket listing, you need to configure the codebase project name.
16
+
17
+ 4. Never forget to put ticket ids and time in your commit messages again. ;)
18
+
19
+ == Note on Patches/Pull Requests
20
+
21
+ * Fork the project.
22
+ * Make your feature addition or bug fix.
23
+ * Add tests for it. This is important so I don't break it in a
24
+ future version unintentionally.
25
+ * Commit, do not mess with rakefile, version, or history.
26
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
27
+ * Send me a pull request. Bonus points for topic branches.
28
+
29
+ == Copyright
30
+
31
+ Copyright (c) 2010 Michael Bumann, Sebastian Kippe. See LICENSE for details.
data/bin/hookr ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV.size == 0
4
+ puts File.read("../README.rdoc")
5
+ exit 1
6
+ end
7
+
8
+ require "fileutils"
9
+
10
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/templates/commit-msg.rb", "#{FileUtils.pwd}/.git/hooks/commit-msg")
11
+ FileUtils.chmod 0755, "#{FileUtils.pwd}/.git/hooks/commit-msg"
12
+ FileUtils.cp("#{File.dirname(__FILE__)}/../lib/templates/#{ARGV[0]}.rb", "#{FileUtils.pwd}/.hookr")
13
+
14
+ puts "Yo dawg I herd u like commit hooks, so I put some files in ur directories."
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
File without changes
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'commit_hookr'
3
+
4
+ require 'test/unit/assertions'
5
+
6
+ World(Test::Unit::Assertions)
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require "highline"
4
+ HighLine.track_eof = false
5
+
6
+ class CommitHookr
7
+ def self.call(&block)
8
+ @@hook = block
9
+ end
10
+
11
+ attr_accessor :message, :message_file
12
+
13
+ def initialize(message_file)
14
+ self.message_file = message_file
15
+ self.message = ""
16
+ end
17
+
18
+ def original_message
19
+ File.read(message_file)
20
+ end
21
+
22
+ def run
23
+ STDIN.reopen '/dev/tty' unless STDIN.tty?
24
+ instance_eval &@@hook
25
+ exit 0
26
+ end
27
+
28
+ def ui
29
+ @highline ||= HighLine.new
30
+ end
31
+
32
+ def abort!
33
+ exit 1
34
+ end
35
+
36
+ def commit!
37
+ exit 0
38
+ end
39
+
40
+ def write(message)
41
+ File.open(message_file, "w+") do |f|
42
+ f.write message
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,60 @@
1
+ CommitHookr.call do
2
+
3
+ # Your codebase project slug
4
+ CODEBASE_PROJECT = "my_awesome_project"
5
+
6
+ def choose_ticket_number
7
+ case @ticket_number = ui.ask("Codebase ticket number ([number], [n] none, [l] list): ") { |q| q.validate = // }.strip #TODO validatestrip .input
8
+ when "n"
9
+ commit!
10
+ when "l"
11
+ list_tickets
12
+ choose_ticket_number
13
+ else
14
+ self.message << " [touch:#{@ticket_number}]" if @ticket_number && @ticket_number != ""
15
+ end
16
+ end
17
+
18
+ def list_tickets
19
+ user = `git config codebase.username`.strip
20
+ api_key = `git config codebase.apikey`.strip
21
+ domain = `git config codebase.domain`.strip
22
+
23
+ tickets = Tickets.new(:user => user, :api_key => api_key, :domain => domain, :project => CODEBASE_PROJECT).all["tickets"]
24
+ puts "---"
25
+ tickets.each do |ticket|
26
+ puts "#{ticket["ticket_id"]}: #{ticket["summary"]}"
27
+ end
28
+ puts ""
29
+ end
30
+
31
+ def enter_time
32
+ @time = ui.ask("Time spent (in minutes): ")
33
+ self.message << " {t:#{@time}}" if @time && @time != ""
34
+ end
35
+
36
+ self.message = "#{original_message.strip}\n"
37
+ choose_ticket_number unless self.message.match(/\[touch:.+\]/)
38
+ enter_time unless self.message.match(/\{t:.+\}/)
39
+
40
+ write self.message
41
+ end
42
+
43
+ require "httparty"
44
+
45
+ class Tickets
46
+ include HTTParty
47
+ headers 'Accept' => 'application/xml'
48
+ headers 'Content-type' => 'application/xml'
49
+ format :xml
50
+
51
+ def initialize(args)
52
+ @auth = {:username => args.delete(:user), :password => args.delete(:api_key)}
53
+ @host = args.delete(:domain)
54
+ @project = args.delete(:project)
55
+ end
56
+
57
+ def all(query="")
58
+ self.class.get("http://#{@host}/#{@project}/tickets", :basic_auth => @auth, :query => {:query => query})
59
+ end
60
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "commit_hookr"
5
+ load ".hookr"
6
+
7
+ CommitHookr.new(ARGV[0]).run
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'commit_hookr'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,5 @@
1
+ require 'helper'
2
+
3
+ class TestCommitHookr < Test::Unit::TestCase
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commit_hookr
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Michael Bumann
13
+ - Sebastian Kippe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-03-17 00:00:00 +01:00
19
+ default_executable: hookr
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: highline
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: cucumber
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :development
44
+ version_requirements: *id002
45
+ description: ""
46
+ email: info@sebastiankippe.de
47
+ executables:
48
+ - hookr
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - bin/hookr
56
+ - features/commit_hookr.feature
57
+ - features/step_definitions/commit_hookr_steps.rb
58
+ - features/support/env.rb
59
+ - lib/commit_hookr.rb
60
+ - lib/templates/codebase.rb
61
+ - lib/templates/commit-msg.rb
62
+ - test/helper.rb
63
+ - test/test_commit_hookr.rb
64
+ - LICENSE
65
+ - README.rdoc
66
+ has_rdoc: true
67
+ homepage: http://github.com/skddc/commit_hookr
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.6
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Configurable git commit hooks for your team
96
+ test_files:
97
+ - test/helper.rb
98
+ - test/test_commit_hookr.rb