git-comitter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-05-29
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,23 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/git-comitter
6
+ lib/git-comitter.rb
7
+ lib/git-comitter/branch.rb
8
+ lib/git-comitter/commit.rb
9
+ lib/git-comitter/cruise.rb
10
+ lib/git-comitter/globals.rb
11
+ lib/git-comitter/primitives.rb
12
+ lib/git-comitter/selector.rb
13
+ script/console
14
+ script/destroy
15
+ script/generate
16
+ spec/branch_spec.rb
17
+ spec/commit_spec.rb
18
+ spec/globals_spec.rb
19
+ spec/primitives_spec.rb
20
+ spec/selector_spec.rb
21
+ spec/spec.opts
22
+ spec/spec_helper.rb
23
+ tasks/rspec.rake
@@ -0,0 +1,51 @@
1
+ = git-committer
2
+
3
+ * http://github.com/gja/git-comitter
4
+
5
+ == DESCRIPTION:
6
+
7
+ * A gem that helps define rules to write git update hooks
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Still quite basic
12
+
13
+ == SYNOPSIS:
14
+
15
+ The following script will allow if the commit's author matches tejasd or srshti
16
+
17
+ allow_if all_authors_match /tejasd/, /srshti/
18
+ deny
19
+
20
+ == REQUIREMENTS:
21
+
22
+ * git
23
+
24
+ == INSTALL:
25
+
26
+ * sudo gem install git-committer
27
+
28
+ == LICENSE:
29
+
30
+ (The MIT License)
31
+
32
+ Copyright (c) 2010 Tejas Dinkar
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ 'Software'), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/git-comitter'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'git-comitter' do
14
+ self.developer 'Tejas Dinkar', 'tejas@gja.in'
15
+ self.rubyforge_name = self.name # TODO this is default value
16
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
17
+
18
+ end
19
+
20
+ require 'newgem/tasks'
21
+ Dir['tasks/**/*.rake'].each { |t| load t }
22
+
23
+ # TODO - want other tests/tasks run by default? Add them to the list
24
+ # remove_task :default
25
+ # task :default => [:spec, :features]
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'git-comitter'
5
+
6
+ module GitComitter
7
+ def _accept
8
+ exit 0
9
+ end
10
+
11
+ def _deny
12
+ exit 1
13
+ end
14
+ end
15
+
16
+ include GitComitter
17
+
18
+ setup_globals(Git.bare(Dir.pwd), ARGV[1], ARGV[2], ARGV[3])
19
+
20
+ load ARGV[0]
@@ -0,0 +1,14 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module GitCommitter
5
+ VERSION = '0.0.1'
6
+ end
7
+
8
+ require 'git'
9
+ require 'git-comitter/globals.rb'
10
+ require 'git-comitter/primitives.rb'
11
+ require 'git-comitter/commit.rb'
12
+ require 'git-comitter/selector.rb'
13
+ require 'git-comitter/branch.rb'
14
+ require 'git-comitter/cruise.rb'
@@ -0,0 +1,6 @@
1
+ module GitComitter
2
+ def branch_is_in(*branches)
3
+ short_branch = branch.split("/").last
4
+ branches.include? short_branch
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ module GitComitter
2
+ class PatternMatcher
3
+ def initialize(patterns, &block)
4
+ @patterns = patterns
5
+ @commit_property = block
6
+ end
7
+
8
+ def match(commits)
9
+ messages = commits.map{|c| @commit_property.call c}
10
+ return messages.all? {|message| @patterns.any?{ |pattern| message =~ pattern } }
11
+ end
12
+ end
13
+
14
+ def matches_email(*patterns)
15
+ PatternMatcher.new(patterns) {|c| c.author.email}
16
+ end
17
+
18
+ def matches_message(*patterns)
19
+ PatternMatcher.new(patterns) {|c| c.message}
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'ftools'
5
+
6
+ class Array
7
+ def second
8
+ self[1]
9
+ end
10
+ end
11
+
12
+ module GitComitter
13
+ def cruise_is_red(args = {})
14
+ cruise_url = args[:cruise_url]
15
+ pipelines = args[:pipelines]
16
+ pipelines.each_pair do |pipeline_name, stage_name|
17
+ stage = Stage.new(cruise_url, pipeline_name, stage_name)
18
+ return true if stage.should_not_checkin?
19
+ end
20
+ false
21
+ end
22
+
23
+ class Pipeline
24
+ def initialize(cruise_url, pipeline)
25
+ @pipe = pipeline
26
+ @cruise_url = cruise_url
27
+ end
28
+
29
+ def status(stage)
30
+ url = "#{@cruise_url}?pipelineName=#{@pipe}&stageName=#{stage}&perPage=2"
31
+ urlObj = URI.parse(url)
32
+ req = Net::HTTP::Get.new(urlObj.path + '?' + urlObj.query)
33
+ res = Net::HTTP.start(urlObj.host, urlObj.port) {|http| http.request(req)}
34
+
35
+ history = JSON.parse(res.body)["history"]
36
+
37
+ status = history.first["current_status"]
38
+ status = history.second["current_status"] if status == 'building'
39
+ status
40
+ end
41
+ end
42
+
43
+ class Stage
44
+ def initialize(cruise_url, pipeline_name, stage_name)
45
+ @cruise = Pipeline.new(cruise_url, pipeline_name)
46
+ @stage_name = stage_name
47
+ end
48
+
49
+ def should_not_checkin?
50
+ stage_status != 'passed'
51
+ end
52
+
53
+ :private
54
+ def stage_status
55
+ @stage_status=@cruise.status @stage_name if @stage_status == nil
56
+ @stage_status
57
+ end
58
+ end
59
+ end
60
+
@@ -0,0 +1,18 @@
1
+ module GitComitter
2
+ attr_reader :full_branch, :old_sha, :new_sha
3
+
4
+ def setup_globals(git, full_branch, old_sha, new_sha)
5
+ @git = git
6
+ @full_branch = full_branch
7
+ @old_sha = old_sha
8
+ @new_sha = new_sha
9
+ end
10
+
11
+ def branch
12
+ full_branch.split("/").last
13
+ end
14
+
15
+ def commits
16
+ @git.log.between(old_sha, new_sha).to_a
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module GitComitter
2
+ class Always
3
+ def evaluate_match
4
+ true
5
+ end
6
+ end
7
+
8
+ def accept(args = {})
9
+ print(args[:message]) if args[:message]
10
+ _accept
11
+ end
12
+
13
+ def deny(args = {})
14
+ print(args[:message]) if args[:message]
15
+ _deny
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module GitComitter
2
+ def all_commits(matcher)
3
+ matcher.match(commits)
4
+ end
5
+
6
+ def latest_commit(matcher)
7
+ matcher.match([commits.first])
8
+ end
9
+
10
+ def first_commit(matcher)
11
+ matcher.match([commits.last])
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/git-comitter.rb'}"
9
+ puts "Loading git-comitter gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe GitComitter do
4
+ before(:each) do
5
+ clear_flags
6
+ end
7
+
8
+ it "Should be able to determine if a branch is in a particular list" do
9
+ self.stub!(:full_branch).and_return("refs/heads/master")
10
+ branch_is_in("master", "foo").should == true
11
+ branch_is_in("foo", "bar").should == false
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe GitComitter do
4
+ before(:each) do
5
+ clear_flags
6
+ end
7
+
8
+ def mock_commit(email)
9
+ mock(:author => mock(:email => email))
10
+ end
11
+
12
+ it "should be able to match author of a single commit" do
13
+ self.stub!(:commits).and_return([mock_commit("tejas@gja.in")])
14
+ all_commits(matches_email(/tejas/)).should == true
15
+ all_commits(matches_email(/somethingelse/)).should == false
16
+ end
17
+
18
+ it "should not match unless all authors match pattern" do
19
+ self.stub!(:commits).and_return([mock_commit("tejas@gja.in"), mock_commit("spam@gja.in")])
20
+ all_commits(matches_email(/tejas/)).should == false
21
+ end
22
+
23
+ it "should be able to take a list of patterns" do
24
+ self.stub!(:commits).and_return([mock_commit("tejas@gja.in"), mock_commit("spam@gja.in")])
25
+ all_commits(matches_email(/tejas/, /spam/)).should == true
26
+ end
27
+
28
+ it "should be able to match message of last commit" do
29
+ self.stub!(:commits).and_return([mock(:message => "Fixing Build"), mock(:message => "Some config")])
30
+ latest_commit(matches_message(/fixing build/i)).should == true
31
+ latest_commit(matches_message(/foobar/i)).should == false
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # These tests are run against the current git repository
4
+
5
+ describe GitComitter do
6
+ before(:each) do
7
+ setup_globals Git.open("."), 'refs/heads/master', '32d1f0b9ed4abe7fd51a2678b7c8dd709fe6f34d', '291dcd04238998b9a901188689e20ba42be83672'
8
+ end
9
+
10
+ it "should have set up branch and sha as global constants" do
11
+ full_branch.should == 'refs/heads/master'
12
+ old_sha.should == '32d1f0b9ed4abe7fd51a2678b7c8dd709fe6f34d'
13
+ new_sha.should == '291dcd04238998b9a901188689e20ba42be83672'
14
+ end
15
+
16
+ it "should get the short name of the branch" do
17
+ branch.should == 'master'
18
+ end
19
+
20
+ it "should get a list of commits" do
21
+ commits.should have(5).things
22
+ commits.map{|c| c.sha}.should == ["291dcd04238998b9a901188689e20ba42be83672", "c57f9601dac033bda72e20d39d31670785ebc472", "dc905cb24791a16c940b4b685be4e459f63177f4", "552192da1cb0e951dfc3f88c2da15c7e457be4cc", "6f68bef6dd15c560042e6eda4722868b0ed99550"]
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe GitComitter do
4
+ before(:each) do
5
+ clear_flags
6
+ end
7
+
8
+ it "Should be able to accept a push" do
9
+ accept
10
+ state.should == :accepted
11
+ end
12
+
13
+ it "Should print out a message when accepting" do
14
+ accept :message => "Dude, you can commit"
15
+ message.should == "Dude, you can commit"
16
+ end
17
+
18
+ it "Should be able to deny a commit" do
19
+ deny
20
+ state.should == :denied
21
+ end
22
+
23
+ it "Should print out a message when denying" do
24
+ deny :message => "Dude, you can't commit"
25
+ message.should == "Dude, you can't commit"
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ class MockMatcher
4
+ def match(commits)
5
+ @commits = commits
6
+ end
7
+
8
+ attr_reader :commits
9
+ end
10
+
11
+ describe GitComitter do
12
+ before(:each) do
13
+ @commit1 = mock("commit1")
14
+ @commit2 = mock("commit2")
15
+ @commit3 = mock("commit3")
16
+
17
+ self.stub!(:commits).and_return([@commit1, @commit2, @commit3])
18
+ @matcher = MockMatcher.new
19
+ end
20
+
21
+ it "should be able to match against all commits" do
22
+ all_commits @matcher
23
+ @matcher.commits.should == commits
24
+ end
25
+
26
+ it "should be able to match the latest commit" do
27
+ latest_commit @matcher
28
+ @matcher.commits.should == [@commit1]
29
+ end
30
+
31
+ it "should be able to match the first commit" do
32
+ first_commit @matcher
33
+ @matcher.commits.should == [@commit3]
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'git-comitter'
11
+
12
+ include GitComitter
13
+
14
+ module GitComitter
15
+ attr_accessor :state, :message
16
+
17
+ def clear_flags
18
+ @state = :neutral
19
+ end
20
+
21
+ def _accept
22
+ @state = :accepted
23
+ end
24
+
25
+ def _deny
26
+ @state = :denied
27
+ end
28
+
29
+ def print(message)
30
+ @message = message
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-comitter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Tejas Dinkar
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-18 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rubyforge
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 4
34
+ version: 2.0.4
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: hoe
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 2
48
+ - 6
49
+ - 0
50
+ version: 2.6.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ description: "* A gem that helps define rules to write git update hooks"
54
+ email:
55
+ - tejas@gja.in
56
+ executables:
57
+ - git-comitter
58
+ extensions: []
59
+
60
+ extra_rdoc_files:
61
+ - History.txt
62
+ - Manifest.txt
63
+ files:
64
+ - History.txt
65
+ - Manifest.txt
66
+ - README.rdoc
67
+ - Rakefile
68
+ - bin/git-comitter
69
+ - lib/git-comitter.rb
70
+ - lib/git-comitter/branch.rb
71
+ - lib/git-comitter/commit.rb
72
+ - lib/git-comitter/cruise.rb
73
+ - lib/git-comitter/globals.rb
74
+ - lib/git-comitter/primitives.rb
75
+ - lib/git-comitter/selector.rb
76
+ - script/console
77
+ - script/destroy
78
+ - script/generate
79
+ - spec/branch_spec.rb
80
+ - spec/commit_spec.rb
81
+ - spec/globals_spec.rb
82
+ - spec/primitives_spec.rb
83
+ - spec/selector_spec.rb
84
+ - spec/spec.opts
85
+ - spec/spec_helper.rb
86
+ - tasks/rspec.rake
87
+ has_rdoc: true
88
+ homepage: http://github.com/gja/git-comitter
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --main
94
+ - README.rdoc
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project: git-comitter
118
+ rubygems_version: 1.3.7
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: "* A gem that helps define rules to write git update hooks"
122
+ test_files: []
123
+