babar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,14 @@
1
+ Contributions of any kind are welcome and encouraged, be they:
2
+
3
+ - Pull requests
4
+ - Bug reports
5
+ - Feature requests
6
+ - Words of encouragement
7
+ - :beer:
8
+
9
+ If you are interested in a particular feature, feel free to open an issue or
10
+ send me an email.
11
+
12
+ If you've got a pull request, keeping coding style consistent would be cool -
13
+ modulo a few parentheses, I tend to stick to the
14
+ [GitHub Ruby style guide](https://github.com/styleguide/ruby).
data/Hookfile ADDED
@@ -0,0 +1,3 @@
1
+ action 'Gemfile' => 'bundle'
2
+ action 'Hookfile' => 'babar install', :auto => true
3
+ action 'db/schema.rb' => 'rake db:migrate'
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Babar is licensed under the MIT License:
2
+
3
+ > Copyright (c) 2013: James Dabbs.
4
+ >
5
+ > Permission is hereby granted, free of charge, to any person obtaining
6
+ > a copy of this software and associated documentation files (the
7
+ > "Software"), to deal in the Software without restriction, including
8
+ > without limitation the rights to use, copy, modify, merge, publish,
9
+ > distribute, sublicense, and/or sell copies of the Software, and to
10
+ > permit persons to whom the Software is furnished to do so, subject to
11
+ > the following conditions:
12
+ >
13
+ > The above copyright notice and this permission notice shall be
14
+ > included in all copies or substantial portions of the Software.
15
+ >
16
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ > EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ > MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ > NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ > LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ > OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ > WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ ## Babar
2
+
3
+ Babar is a simple gem to help remember post-merge actions and manage git hooks
4
+ on a per-project basis. It alerts you to changes to specific files, and can
5
+ automatically take actions when those files are changed.
6
+
7
+ By default, Babar will remind you to `rake db:migrate` and `bundle` whenever you
8
+ merge in changes to `db/schema.rb` or `Gemfile` respectively.
9
+
10
+ Just want a simple git hook? See [this gist](https://gist.github.com/jamesdabbs/5017797)
11
+ for the genesis of this project.
12
+
13
+ ### Usage
14
+
15
+ gem install babar # Or add to Gemfile and bundle
16
+ babar install # To configure your .git/hooks/
17
+
18
+ Once installed, you will be notified whenever you merge (or pull) in changes
19
+ to a watched file.
20
+
21
+ ### Customizing
22
+
23
+ Babar looks for a Hookfile in your root directory. The default Hookfile is:
24
+
25
+ action 'Gemfile' => 'bundle', :auto => false
26
+ action 'db/schema.rb' => 'rake db:migrate', :auto => false
27
+
28
+ Adding `:auto => true` will cause an action to be automatically executed whenever
29
+ a matching file changes.
30
+
31
+ #### TODO
32
+
33
+ * Add generator to create default Hookfile in project
data/babar.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'babar'
3
+ spec.version = '0.0.1'
4
+ spec.date = '2013-02-25'
5
+ spec.description = 'Project-oriented management of git merge hooks'
6
+ spec.summary = spec.description
7
+ spec.authors = ['James Dabbs']
8
+ spec.email = 'jdabbs@emcien.com'
9
+ spec.files = %w(babar.gemspec Hookfile)
10
+ spec.files += Dir.glob('*.md') + Dir.glob('lib/**/*.rb') + Dir.glob('bin/*')
11
+ spec.bindir = 'bin'
12
+ spec.executables = 'babar'
13
+ spec.require_paths = ['lib']
14
+
15
+ spec.add_dependency 'rake'
16
+
17
+ spec.post_install_message = "\e[33mPlease run `babar install` to set up git hooks\e[0m"
18
+ end
data/bin/babar ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require 'babar'
3
+
4
+ case ARGV.first
5
+ when 'install'
6
+ raise 'Could not find .git/hooks directory' unless Dir.exists? '.git/hooks'
7
+ `touch .git/hooks/post-merge`
8
+ `sed -i '.tmp' '/babar/d' '.git/hooks/post-merge'` # Keep it idempotent
9
+ `echo babar >> .git/hooks/post-merge`
10
+ `chmod +x .git/hooks/post-merge`
11
+ puts 'Installed .git/hooks/post-merge'
12
+
13
+ when 'uninstall'
14
+ `sed -i '.tmp' '/babar/d' '.git/hooks/post-merge'`
15
+
16
+ when nil
17
+ Babar.run
18
+
19
+ else
20
+ puts "Unexpected option: #{ARGV.first}"
21
+ puts 'Usage: babar [un[install]]'
22
+ end
@@ -0,0 +1,25 @@
1
+ module Babar
2
+ class Action
3
+ def initialize target, action, opts={}
4
+ @target = Regexp.new target
5
+ @action = action
6
+ @auto = opts[:auto]
7
+ end
8
+
9
+ def auto?
10
+ @auto
11
+ end
12
+
13
+ def applies? file
14
+ file =~ @target
15
+ end
16
+
17
+ def perform
18
+ puts `#{@action}`
19
+ end
20
+
21
+ def notify
22
+ puts "\e[0m* \e[1;33m#{@action}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,43 @@
1
+ module Babar
2
+ class Manifest
3
+ def initialize files
4
+ @files = files
5
+ @actions = []
6
+ instance_eval File.read Babar.hookfile
7
+ end
8
+
9
+ def perform
10
+ applicable.select { |a| a.auto? }.map &:perform
11
+ end
12
+
13
+ def notify
14
+ return unless applicable.any?
15
+ puts "\n\e[0;33mThis merge altered your environment!"
16
+
17
+ taken, pending = applicable.partition &:auto?
18
+
19
+ if taken.any?
20
+ puts "\e[0;33mThe following actions were automatically taken:"
21
+ taken.each &:notify
22
+ end
23
+
24
+ if pending.any?
25
+ puts "\e[0;33mYou should probably:"
26
+ pending.each &:notify
27
+ end
28
+
29
+ puts "\e[0m"
30
+ end
31
+
32
+ private # ----------
33
+
34
+ def action opts
35
+ target, action = opts.shift
36
+ @actions << Action.new(target, action, opts)
37
+ end
38
+
39
+ def applicable
40
+ @applicable ||= @actions.select { |a| @files.any? { |f| a.applies?(f) } }
41
+ end
42
+ end
43
+ end
data/lib/babar.rb ADDED
@@ -0,0 +1,23 @@
1
+ load 'tasks/babar.rake' if defined? Rake
2
+
3
+ require 'babar/action'
4
+ require 'babar/manifest'
5
+
6
+ module Babar
7
+ def self.run
8
+ manifest = Manifest.new changed
9
+ manifest.perform
10
+ manifest.notify
11
+ end
12
+
13
+ def self.changed offset=0
14
+ commits = `git reflog -n #{offset + 2}`.lines.map { |l| l.split.first }
15
+ changed = `git diff --name-only #{commits.first} #{commits.last}`.lines.map &:strip
16
+ end
17
+
18
+ def self.hookfile
19
+ ['Hookfile', File.expand_path('../../Hookfile', __FILE__)].find do |path|
20
+ File.exists? path
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: babar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Dabbs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Project-oriented management of git merge hooks
31
+ email: jdabbs@emcien.com
32
+ executables:
33
+ - babar
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - babar.gemspec
38
+ - Hookfile
39
+ - CONTRIBUTING.md
40
+ - LICENSE.md
41
+ - README.md
42
+ - lib/babar/action.rb
43
+ - lib/babar/manifest.rb
44
+ - lib/babar.rb
45
+ - bin/babar
46
+ homepage:
47
+ licenses: []
48
+ post_install_message: ! "\e[33mPlease run `babar install` to set up git hooks\e[0m"
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ segments:
59
+ - 0
60
+ hash: -1652465465846067857
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: -1652465465846067857
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.24
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Project-oriented management of git merge hooks
76
+ test_files: []