git_breeze 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f411ec6aefe6c704aa75132ab0e2ef37aaeaa2d8
4
+ data.tar.gz: ad02bcd7f002478120db86af40f0a0cd28db8524
5
+ SHA512:
6
+ metadata.gz: 250c6fa6a18c9eae0c171b13446dc53d25ce36ffbcceedd5ec022d64db6b49e50123114262176be632dd59b7f1b45a9a0834aa21ccac9ff521995de46b75b9a0
7
+ data.tar.gz: 15d761b82e63553d6c33c16ad22a975db67fb2b7f55c1a907f17e20dceac318976d7c7198bfe05493b9779e4b9045c5a5fe2cf5a256377eec444e8edfec94fb2
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ .bundle
3
+ .ruby-version
4
+ Gemfile.lock
5
+ coverage
6
+ bin/autospec
7
+ bin/rspec
8
+ bin/rake
9
+ doc/
10
+ lib/bundler/man
11
+ /git-breeze
12
+ pkg
13
+ rdoc
14
+ tmp
15
+ tags
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ -I spec/support
3
+ -r pry
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.6
8
+ - 2.2.2
9
+ addons:
10
+ code_climate:
11
+ repo_token: d08131691091072810c086f65d42c36ba7ea3241629c643caa363cbc966bbb23
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ### 0.1.0 / 2015-09-09
2
+ changed references from tracker to brreeze and altered the code to remove unnecessary stuff
3
+
4
+ ### 0.0.1 / 2015-09-09
5
+ [full changelog](https://github.com/stevenharman/git_tracker/compare/v0.0.1...v1.0.0)
6
+
7
+ Forked from git_tracker
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git_breeze.gemspec
4
+ gemspec
5
+
6
+ gem 'codeclimate-test-reporter', :group => :test, :require => nil
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 MobileIgniter
2
+
3
+ MIT License
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,139 @@
1
+ # GitBreeze
2
+
3
+ *GitBreeze*, or *git-breeze*, is a Git hook that will scan your current
4
+ branch name looking for something it recognizes as a [Breeze][b]
5
+ story number. If it finds one, it will automagically add it, in the [special
6
+ format][pt-format], to your commit message.
7
+
8
+ ## Installation
9
+
10
+ ### 1) Install the `git-breeze` binary
11
+
12
+ You need to get the `git-breeze` binary onto your system.
13
+
14
+ - via [Homebrew][homebrew] :beers: (preferred)
15
+
16
+ ```bash
17
+ $ brew install git-breeze
18
+ ```
19
+
20
+ - via [RubyGems][rubygems] :pensive: (if you must)
21
+
22
+ ```bash
23
+ $ gem install git_breeze
24
+ ```
25
+
26
+ ### 2) Initialize the hook
27
+
28
+ Then you need to initialize the *git hook* into each local Git repository where
29
+ you want to use it.
30
+
31
+ ```bash
32
+ # from inside a local Git repository
33
+ # for example: /path/to/repo/
34
+ $ git breeze init
35
+ ```
36
+
37
+ This will put the `prepare-commit-msg` hook in the `/path/to/repo/.git/hooks`
38
+ directory and make it executable.
39
+
40
+ **NOTE:** The hook needs to be initialized just once for each repository in
41
+ which you will use it.
42
+
43
+ ## Usage
44
+
45
+ With the hook initialized in a repository, create branches being sure to include
46
+ the Breeze story number in the branch name.
47
+
48
+ ```bash
49
+ $ git checkout -b a_useful_and_helpful_name_8675309
50
+ ```
51
+
52
+ When you commit, Git will fire the hook which will find the story number in the
53
+ branch name and prepare your commit message so that it includes the story number
54
+ in the [special Breeze syntax][b-format].
55
+
56
+ ```bash
57
+ # on branch named `best_feature_ever-8675309`
58
+ $ git commit
59
+ ```
60
+
61
+ Will result in a commit message something like: *(notice the two empty lines at
62
+ the top)*
63
+
64
+ ```diff
65
+
66
+
67
+ #8675309
68
+ # Please enter the commit message for your changes. Lines starting
69
+ # with '#' will be ignored, and an empty message aborts the commit.
70
+ # On branch best_feature_ever-8675309
71
+ # Changes to be committed:
72
+ # (use "git reset HEAD <file>..." to unstage)
73
+ #
74
+ # new file: feature.rb
75
+ #
76
+
77
+ ```
78
+
79
+ You should then add a [useful and responsible commit message][tpope]. :heart:
80
+
81
+ ### Passing commit messages via command line
82
+
83
+ If you pass a commit message on the command line the hook will still add the
84
+ story number, preceded by an empty line, to the end of your message.
85
+
86
+ ```bash
87
+ # on branch named `best_feature_ever-8675309`
88
+ $ git commit -m'Look at this rad code, yo!'
89
+ ```
90
+
91
+ Results in this commit message:
92
+
93
+ ```
94
+ Look at this rad code, yo!
95
+
96
+ #8675309
97
+ ```
98
+
99
+ However, if you include the story number in the Breeze format within
100
+ your commit message, the hook will do nothing.
101
+
102
+ ```bash
103
+ # on branch named `best_feature_ever-8675309`
104
+ $ git commit -m'#8675309 Look at this rad code, yo!'
105
+ ```
106
+
107
+ Results in this commit message:
108
+
109
+
110
+ ```
111
+ #8675309 Look at this rad code, yo!
112
+ ```
113
+
114
+ ### Valid branch names
115
+
116
+ *GitBreeze* allows you to include the story number any where in the branch
117
+ name, optionally prefixing it with a hash (`#`). Examples:
118
+
119
+ - `best_feature_ever_#8675309`
120
+ - `best-feature-ever-8675309`
121
+ - `8675309_best_feature_ever`
122
+ - `#8675309-best-feature-ever`
123
+ - `your_name/8675309_best_feature_ever`
124
+ - `your_name/#8675309_best_feature_ever`
125
+
126
+ ## Contributing :octocat:
127
+
128
+ 1. Fork it
129
+ 2. Create your feature branch (`git checkout -b my_new_feature`)
130
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
131
+ 4. Push to the branch (`git push origin my_new_feature`)
132
+ 5. Create new Pull Request
133
+
134
+
135
+ [b]: https://www.breeze.pm/
136
+ [b-format]: http://www.breeze.pm/help/projects/bitbucket-integration
137
+ [tpope]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
138
+ [homebrew]: http://mxcl.github.com/homebrew
139
+ [rubygems]: http://rubygems.org/gems/git_breeze
data/Rakefile ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env rake
2
+ require File.expand_path('../lib/git_breeze/version', __FILE__)
3
+
4
+ # Skip these tasks when being installed by Homebrew
5
+ unless ENV['HOMEBREW_BREW_FILE']
6
+
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ task :default => :spec
10
+
11
+ # Rubygems tasks
12
+ namespace :gem do
13
+ require 'bundler/gem_tasks'
14
+ end
15
+
16
+ desc "Create tag v#{GitBreeze::VERSION}, build, and push to GitHub, Rubygems, and Homebrew"
17
+ task :release => ['gem:release', 'standalone:homebrew']
18
+
19
+ end
20
+
21
+ # standalone and Homebrew
22
+ file 'git-breezer' => FileList.new('lib/git_breeze.rb', 'lib/git_breeze/*.rb') do |task|
23
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
24
+ require 'git_breeze/standalone'
25
+ GitBreeze::Standalone.save(task.name)
26
+ end
27
+
28
+ namespace :standalone do
29
+
30
+ desc 'Build standalone script'
31
+ task :build => 'git-breezer'
32
+
33
+ desc 'Build and install standalone script'
34
+ task :install => 'standalone:build' do
35
+ prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
36
+
37
+ FileUtils.mkdir_p "#{prefix}/bin"
38
+ FileUtils.cp 'git-breezer', "#{prefix}/bin", :preserve => true
39
+ end
40
+
41
+ task :homebrew do
42
+ brew_dir = Bundler.with_clean_env { `brew --prefix` }.chomp
43
+ Dir.chdir brew_dir do
44
+ sh 'git checkout -q master'
45
+ sh 'git pull -q origin master'
46
+
47
+ formula_file = 'Library/Formula/git-breezer.rb'
48
+ sha = `curl -#L https://github.com/stevenharman/git_breeze/archive/v#{GitBreeze::VERSION}.tar.gz | shasum`.split(/\s+/).first
49
+ abort unless $?.success? and sha.length == 40
50
+
51
+ formula = File.read formula_file
52
+ formula.sub! /\bv\d+(\.\d+)*/, "v#{GitBreeze::VERSION}"
53
+ formula.sub! /\b[0-9a-f]{40}\b/, sha
54
+ File.open(formula_file, 'w') {|f| f << formula }
55
+
56
+ branch = "git_breeze-v#{GitBreeze::VERSION}"
57
+ sh "git checkout -q -B #{branch}"
58
+ sh "git commit -m 'git-breezer #{GitBreeze::VERSION}' -- #{formula_file}"
59
+ sh "git push -u stevenharman #{branch}"
60
+ sh "hub pull-request -m 'git-breezer #{GitBreeze::VERSION}'"
61
+
62
+ sh 'git checkout -q master'
63
+ end
64
+ end
65
+ end
66
+
data/bin/git-breeze ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'git_breeze'
4
+ GitBreeze::Runner.execute(*ARGV)
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/git_breeze/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'git_breeze'
6
+ gem.version = GitBreeze::VERSION
7
+ gem.authors = ['Timothy Nott']
8
+ gem.email = ['tim@mobileigniter.com']
9
+ gem.homepage = 'https://bitbucket.org/mobileigniter/git_breeze'
10
+ gem.summary = %q{Teaching Git about Breeze.}
11
+ gem.description = <<-EOF
12
+ Some simple tricks that make working with Breeze.pm easier
13
+ EOF
14
+
15
+ gem.add_development_dependency 'rspec', '~> 3.2.0'
16
+ gem.add_development_dependency 'activesupport', '~> 3.2'
17
+ # Use i18n < 0.7 until we drop Ruby 1.8.7 and 1.9.2 support
18
+ gem.add_development_dependency 'i18n', '~> 0.6.11'
19
+ gem.add_development_dependency 'pry', '~> 0.10.1'
20
+ # Use Rake < 10.2 (requires Ruby 1.9+) until we drop Ruby 1.8.7 support
21
+ gem.add_development_dependency 'rake', '~> 10.1.1'
22
+
23
+ gem.files = `git ls-files`.split("\n")
24
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ gem.executables = %w(git-breeze)
26
+ gem.require_paths = ['lib']
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'English'
2
+ require 'git_breeze/repository'
3
+
4
+ module GitBreeze
5
+ module Branch
6
+ def self.story_number
7
+ current[/#?(\d{6,10})/, 1]
8
+ end
9
+
10
+ def self.current
11
+ branch_path = `git symbolic-ref HEAD`
12
+
13
+ Repository.ensure_exists unless exit_successful?
14
+
15
+ branch_path[%r{refs/heads/(.+)}, 1] || ''
16
+ end
17
+
18
+ private
19
+
20
+ def self.exit_successful?
21
+ $CHILD_STATUS.exitstatus == 0
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ module GitBreeze
2
+ class CommitMessage
3
+
4
+ def initialize(file)
5
+ @file = file
6
+ @message = File.read(@file)
7
+ end
8
+
9
+ def mentions_story?(number)
10
+ @message =~ /^(?!#).*\[(\w+\s)?(#\d+\s)*##{number}(\s#\d+)*(\s\w+)?\]/io
11
+ end
12
+
13
+ # def keyword
14
+ # @message =~ /\[(fix|fixes|fixed|complete|completes|completed|finish|finishes|finished|deliver|delivers|delivered)\]/io
15
+ # $1
16
+ # end
17
+
18
+ def append(text)
19
+ body, postscript = parse(@message)
20
+ new_message = format_message(body, text, postscript)
21
+ File.open(@file, 'w') do |f|
22
+ f.write(new_message)
23
+ end
24
+ new_message
25
+ end
26
+
27
+ private
28
+
29
+ def parse(message)
30
+ lines = message.split($/)
31
+ body = lines.take_while { |line| !line.start_with?('#') }
32
+ postscript = "# testing to see if I can add instructions here\n#\{story number\} should be put in automatically. use @\{username\} to call someone out. use m:\{ListName\} to move an item to a new list\n" + lines.slice(body.length..-1)
33
+ [body.join("\n"), postscript.join("\n")]
34
+ end
35
+
36
+ def format_message(preamble, text, postscript)
37
+ return <<-MESSAGE
38
+ #{preamble.strip}
39
+
40
+ #{text}
41
+ #{postscript}
42
+ MESSAGE
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,38 @@
1
+ require 'git_breeze/repository'
2
+
3
+ module GitBreeze
4
+ class Hook
5
+ attr_reader :hook_file
6
+
7
+ def self.init
8
+ init_at(Repository.root)
9
+ end
10
+
11
+ def self.init_at(root)
12
+ new(root).write
13
+ end
14
+
15
+ def initialize(root)
16
+ @hook_file = File.join(root, '.git', 'hooks', 'prepare-commit-msg')
17
+ end
18
+
19
+ def write
20
+ File.open(hook_file, 'w') do |f|
21
+ f.write(hook_body)
22
+ f.chmod(0755)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def hook_body
29
+ return <<-HOOK
30
+ #!/usr/bin/env bash
31
+
32
+ git_breeze prepare-commit-msg "$@"
33
+
34
+ HOOK
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ require 'git_breeze/branch'
2
+ require 'git_breeze/commit_message'
3
+
4
+ module GitBreeze
5
+ class PrepareCommitMessage
6
+ attr_reader :file, :source, :commit_sha
7
+
8
+ def self.run(file, source=nil, commit_sha=nil)
9
+ new(file, source, commit_sha).run
10
+ end
11
+
12
+ def initialize(file, source=nil, commit_sha=nil)
13
+ @file = file
14
+ @source = source
15
+ @commit_sha = commit_sha
16
+ end
17
+
18
+ def run
19
+ exit_when_commit_exists
20
+
21
+ story = story_number_from_branch
22
+ message = CommitMessage.new(file)
23
+ exit if message.mentions_story?(story)
24
+ keyword = message.keyword
25
+
26
+ message_addition = [keyword, "##{story}"].compact.join(' ')
27
+ message.append("[#{message_addition}]")
28
+ end
29
+
30
+ private
31
+
32
+ def exit_when_commit_exists
33
+ exit if source == 'commit'
34
+ end
35
+
36
+ def story_number_from_branch
37
+ story = Branch.story_number
38
+ exit unless story
39
+ story
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ require 'English'
2
+
3
+ module GitBreeze
4
+ module Repository
5
+
6
+ def self.root
7
+ path = `git rev-parse --show-toplevel`.chomp
8
+ abort unless $CHILD_STATUS.exitstatus == 0
9
+ path
10
+ end
11
+
12
+ def self.ensure_exists
13
+ root
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,39 @@
1
+ require 'git_breeze/prepare_commit_message'
2
+ require 'git_breeze/hook'
3
+ require 'git_breeze/version'
4
+
5
+ module GitBreeze
6
+ module Runner
7
+
8
+ def self.execute(cmd_arg = 'help', *args)
9
+ command = cmd_arg.gsub(/-/, '_')
10
+ abort("[git_breeze] command: '#{cmd_arg}' does not exist.") unless respond_to?(command)
11
+ send(command, *args)
12
+ end
13
+
14
+ def self.prepare_commit_msg(*args)
15
+ PrepareCommitMessage.run(*args)
16
+ end
17
+
18
+ def self.init
19
+ Hook.init
20
+ end
21
+
22
+ def self.install
23
+ puts '`git-breeze install` is deprecated. Please use `git-breeze init`'
24
+ self.init
25
+ end
26
+
27
+ def self.help
28
+ puts <<-HELP
29
+ git-breeze #{VERSION} is installed.
30
+
31
+ Remember, git-breeze is a hook which Git interacts with during its normal
32
+ lifecycle of committing, rebasing, merging, etc. You need to initialize this
33
+ hook by running `git-breeze init` from each repository in which you wish to
34
+ use it. Cheers!
35
+ HELP
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,70 @@
1
+ module GitBreeze
2
+ module Standalone
3
+ extend self
4
+
5
+ GIT_BREEZE_ROOT = File.expand_path('../../..', __FILE__)
6
+ PREAMBLE = <<-preamble
7
+ #
8
+ # This file is generated code. DO NOT send patches for it.
9
+ #
10
+ # Original source files with comments are at:
11
+ # https://bitbucket.org/mobileigniter/git_breeze
12
+ #
13
+
14
+ preamble
15
+
16
+ def save(filename, path = '.')
17
+ dest = File.join(File.expand_path(path), filename)
18
+ File.open(dest, 'w') do |f|
19
+ build(f)
20
+ f.chmod(0755)
21
+ end
22
+ end
23
+
24
+ def build(io)
25
+ io.puts "#!#{ruby_executable}"
26
+ io << PREAMBLE
27
+
28
+ each_source_file do |filename|
29
+ File.open(filename, 'r') do |source|
30
+ inline_source(source, io)
31
+ end
32
+ end
33
+
34
+ io.puts 'GitBreeze::Runner.execute(*ARGV)'
35
+ io
36
+ end
37
+
38
+ def ruby_executable
39
+ if File.executable? '/usr/bin/ruby' then '/usr/bin/ruby'
40
+ else
41
+ require 'rbconfig'
42
+ File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def inline_source(code, io)
49
+ code.each_line do |line|
50
+ io << line unless require_own_file?(line)
51
+ end
52
+ io.puts ''
53
+ end
54
+
55
+ def require_own_file?(line)
56
+ line =~ /^\s*require\s+["']git_breeze\//
57
+ end
58
+
59
+ def each_source_file
60
+ File.open(File.join(GIT_BREEZE_ROOT, 'lib/git_breeze.rb'), 'r') do |main|
61
+ main.each_line do |req|
62
+ if req =~ /^require\s+["'](.+)["']/
63
+ yield File.join(GIT_BREEZE_ROOT, 'lib', "#{$1}.rb")
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module GitBreeze
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'git_breeze/version'
2
+ require 'git_breeze/hook'
3
+ require 'git_breeze/repository'
4
+ require 'git_breeze/prepare_commit_message'
5
+ require 'git_breeze/runner'
6
+ require 'git_breeze/branch'
7
+ require 'git_breeze/commit_message'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+
3
+ git-tracker prepare-commit-msg "$@"
4
+