git_bumper 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/bin/git-bump +3 -0
- data/git_bumper.gemspec +1 -2
- data/lib/git_bumper/build_tag.rb +5 -0
- data/lib/git_bumper/cli.rb +40 -0
- data/lib/git_bumper/cli_parser.rb +42 -0
- data/lib/git_bumper/git.rb +12 -2
- data/lib/git_bumper/tag.rb +12 -0
- data/lib/git_bumper/version.rb +1 -1
- data/lib/git_bumper.rb +9 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dbebb5b4068fbb7d06f8f8f6e5833ff6b7e7571
|
4
|
+
data.tar.gz: ef4b3519f87bda65e8818ec17186b8631dbd4bfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70507cc3b729a0ed77834e7d3daf26de9d3b8a2689265821a5a05319aed87243daa63afdf5477326b111e828a2908dbf7912635272276b0d076ecad0b152f4a8
|
7
|
+
data.tar.gz: 362e024de5c17480b783678554f5fb67740d121e92b9170083a81076721f4fe6f7d101f9cfec07d4a805f8e8ae69a319ae8d600483ba24e0a77d97d9ee798b8e
|
data/Gemfile
CHANGED
data/bin/git-bump
ADDED
data/git_bumper.gemspec
CHANGED
@@ -15,8 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.executables = ['git-bump']
|
20
19
|
spec.require_paths = ['lib']
|
21
20
|
|
22
21
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
data/lib/git_bumper/build_tag.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module GitBumper
|
2
|
+
# This class receives a Hash of options parsed by CLIParser and executes the
|
3
|
+
# requested action.
|
4
|
+
class CLI
|
5
|
+
# @param [Hash]
|
6
|
+
def initialize(options)
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
Git.fetch_tags
|
12
|
+
|
13
|
+
old_tag = greatest_tag
|
14
|
+
abort 'No tags found.' unless old_tag
|
15
|
+
|
16
|
+
new_tag = old_tag.clone
|
17
|
+
new_tag.increment(@options.fetch(:increment))
|
18
|
+
|
19
|
+
puts "The old tag is #{old_tag}"
|
20
|
+
puts "The new tag will be #{new_tag}"
|
21
|
+
puts 'Push to origin? (y/N)'
|
22
|
+
|
23
|
+
abort 'Aborted.' unless prompt_yes
|
24
|
+
|
25
|
+
Git.create_tag(new_tag)
|
26
|
+
Git.push_tag(new_tag)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def prompt_yes
|
32
|
+
STDIN.gets.chomp.to_s =~ /y(es)?/i
|
33
|
+
end
|
34
|
+
|
35
|
+
def greatest_tag
|
36
|
+
Git.greatest_tag(klass: @options.fetch(:klass),
|
37
|
+
prefix: @options.fetch(:prefix))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module GitBumper
|
5
|
+
# This is the parser for CLI arguments.
|
6
|
+
class CLIParser
|
7
|
+
attr_reader :options
|
8
|
+
|
9
|
+
# @param argv [Array<String>]
|
10
|
+
def initialize(argv)
|
11
|
+
@argv = argv
|
12
|
+
@parser = OptionParser.new
|
13
|
+
@options = { klass: GitBumper::Tag,
|
14
|
+
prefix: 'v',
|
15
|
+
increment: :patch }
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse
|
19
|
+
@parser.banner = 'Usage: git bump [options]'
|
20
|
+
|
21
|
+
@parser
|
22
|
+
.on('-b', '--build', 'Use build tags') do
|
23
|
+
options[:klass] = GitBumper::BuildTag
|
24
|
+
end
|
25
|
+
.on('-p', '--prefix [PREFIX]', 'Set a prefix') do |prefix|
|
26
|
+
options[:prefix] = prefix
|
27
|
+
end
|
28
|
+
.on('--major', 'Increments the major version') do
|
29
|
+
options[:increment] = :major
|
30
|
+
end
|
31
|
+
.on('--minor', 'Increments the minor version') do
|
32
|
+
options[:increment] = :minor
|
33
|
+
end
|
34
|
+
.on('-h', '--help', 'Prints this help') do
|
35
|
+
puts @parser
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
|
39
|
+
@parser.parse!(@argv)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/git_bumper/git.rb
CHANGED
@@ -16,16 +16,26 @@ module GitBumper
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# Returns the greatest tag.
|
19
|
-
def greatest_tag(prefix: 'v',
|
19
|
+
def greatest_tag(prefix: 'v', klass: Tag)
|
20
20
|
output = `git tag --list --sort=-v:refname "#{prefix}[0-9]*" 2> /dev/null`
|
21
21
|
|
22
22
|
tags = output.split.collect do |tag|
|
23
|
-
|
23
|
+
klass.parse(tag)
|
24
24
|
end
|
25
25
|
|
26
26
|
tags.find do |tag|
|
27
27
|
tag
|
28
28
|
end || false
|
29
29
|
end
|
30
|
+
|
31
|
+
# Create a new git tag.
|
32
|
+
def create_tag(tag)
|
33
|
+
`git tag #{tag}`
|
34
|
+
end
|
35
|
+
|
36
|
+
# Pushes a tag to origin.
|
37
|
+
def push_tag(tag)
|
38
|
+
`git push origin #{tag}`
|
39
|
+
end
|
30
40
|
end
|
31
41
|
end
|
data/lib/git_bumper/tag.rb
CHANGED
@@ -38,5 +38,17 @@ module GitBumper
|
|
38
38
|
def to_s
|
39
39
|
"#{prefix}#{major}.#{minor}.#{patch}"
|
40
40
|
end
|
41
|
+
|
42
|
+
# Increments a part of the version.
|
43
|
+
def increment(part)
|
44
|
+
case part
|
45
|
+
when :major
|
46
|
+
@major += 1
|
47
|
+
when :minor
|
48
|
+
@minor += 1
|
49
|
+
when :patch
|
50
|
+
@patch += 1
|
51
|
+
end
|
52
|
+
end
|
41
53
|
end
|
42
54
|
end
|
data/lib/git_bumper/version.rb
CHANGED
data/lib/git_bumper.rb
CHANGED
@@ -2,6 +2,15 @@ require 'git_bumper/version'
|
|
2
2
|
require 'git_bumper/tag'
|
3
3
|
require 'git_bumper/build_tag'
|
4
4
|
require 'git_bumper/git'
|
5
|
+
require 'git_bumper/cli_parser'
|
6
|
+
require 'git_bumper/cli'
|
5
7
|
|
6
8
|
module GitBumper
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def run
|
12
|
+
parser = CLIParser.new(ARGV)
|
13
|
+
parser.parse
|
14
|
+
CLI.new(parser.options).run
|
15
|
+
end
|
7
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_bumper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lenon Marcel
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,7 +55,8 @@ dependencies:
|
|
55
55
|
description: A CLI utility to bump git tags.
|
56
56
|
email:
|
57
57
|
- lenon.marcel@gmail.com
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- git-bump
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
@@ -69,10 +70,13 @@ files:
|
|
69
70
|
- README.md
|
70
71
|
- Rakefile
|
71
72
|
- bin/console
|
73
|
+
- bin/git-bump
|
72
74
|
- bin/setup
|
73
75
|
- git_bumper.gemspec
|
74
76
|
- lib/git_bumper.rb
|
75
77
|
- lib/git_bumper/build_tag.rb
|
78
|
+
- lib/git_bumper/cli.rb
|
79
|
+
- lib/git_bumper/cli_parser.rb
|
76
80
|
- lib/git_bumper/git.rb
|
77
81
|
- lib/git_bumper/tag.rb
|
78
82
|
- lib/git_bumper/version.rb
|