git_bumper 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b8ae281cbee5393215f4851fbe2eca2baea9ab6
4
- data.tar.gz: 4a183aad58abe42fd06ed5388a198c18d0e4c3ff
3
+ metadata.gz: 9dbebb5b4068fbb7d06f8f8f6e5833ff6b7e7571
4
+ data.tar.gz: ef4b3519f87bda65e8818ec17186b8631dbd4bfd
5
5
  SHA512:
6
- metadata.gz: 0bcb8968736411476cfccbebc2ef0d4b2691216777b76f40cf5dd6180c12713618fdc8bed010c2cd46469d1fb1567d695a3dfab72e724ddc006bb73f1827abb4
7
- data.tar.gz: 78fa201911ebc984f39d4407bd33ed0a6bcdc9875fa0cc203ca11c40c193abda2417cdbac1600737fc246d6f98cc0e809a226cb2cc61bc336b621370f62d6b38
6
+ metadata.gz: 70507cc3b729a0ed77834e7d3daf26de9d3b8a2689265821a5a05319aed87243daa63afdf5477326b111e828a2908dbf7912635272276b0d076ecad0b152f4a8
7
+ data.tar.gz: 362e024de5c17480b783678554f5fb67740d121e92b9170083a81076721f4fe6f7d101f9cfec07d4a805f8e8ae69a319ae8d600483ba24e0a77d97d9ee798b8e
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in git_bumper.gemspec
4
4
  gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
data/bin/git-bump ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'git_bumper'
3
+ GitBumper.run
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.bindir = 'exe'
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'
@@ -32,5 +32,10 @@ module GitBumper
32
32
  def to_s
33
33
  "#{prefix}#{build}"
34
34
  end
35
+
36
+ # Increments the build number.
37
+ def increment(*)
38
+ @build += 1
39
+ end
35
40
  end
36
41
  end
@@ -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
@@ -16,16 +16,26 @@ module GitBumper
16
16
  end
17
17
 
18
18
  # Returns the greatest tag.
19
- def greatest_tag(prefix: 'v', tag_class: Tag)
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
- tag_class.parse(tag)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module GitBumper
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lenon Marcel
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-11 00:00:00.000000000 Z
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