nextver 0.1.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c362a06dd22de7a07aa0828ce466ef992056a3d2805f3c55e64ef284f2a35262
4
- data.tar.gz: 18b753dbf747914d374a9ee031654d00a231f734289067899a9457dbddf543c9
3
+ metadata.gz: 5bb8461f23e755657657651af9c58f17e7bd01079495fa04b2aae42c4634d688
4
+ data.tar.gz: 69b372968a5a0d00bd4c70568e130485d723a6d0ee6839e52240ff4df1d1443a
5
5
  SHA512:
6
- metadata.gz: dacce37fd2e50624ae8cdadc34d86a3f20a3129746c58c4fae30c991f1846c789295384df591797664440d52bf817d6a1ddd1ad1f3a8043e6520d59dc5fcd6b5
7
- data.tar.gz: 3ce8545521596259f898c595c3d416df5be8c8b61d68fc34a9754cfbbaf9bebfe3450f703110d4731415acbb78511b32d7c60af79d1dc714e5b9372c51713303
6
+ metadata.gz: 482823e6a7272e67576d043f275b66ff525ef4a6d825f58d66ccb4ac494b8cc2d4e70f09df200e97afe901a66ee1f7f9ff64d2ac9707ec7c345be57ca06a67aa
7
+ data.tar.gz: 57b139973304c592122e90d4e0dae5bdee939f393171ba11d44826b2ef8749fa2f88bb6057c1e38e4b1bb3a5b2b6d58203c88c02923dc447d948c92ca08ef261
data/README.md CHANGED
@@ -11,13 +11,13 @@ gem "nextver", require: false, group: :development
11
11
 
12
12
  or `gem install nextver`.
13
13
 
14
- To get `bin/nextver` created on every `bundle install`, set this once in your app and commit `.bundle/config`:
14
+ In a Rails app, create `bin/nextver` once and commit it:
15
15
 
16
16
  ```
17
- bundle config set --local bin bin
17
+ bin/rails generate nextver:install
18
18
  ```
19
19
 
20
- Or run `bundle binstubs nextver` once and commit `bin/nextver`.
20
+ Outside Rails, `bundle binstubs nextver` does the same.
21
21
 
22
22
  ## Usage
23
23
 
@@ -26,6 +26,7 @@ bin/nextver [options...] [dir]
26
26
 
27
27
  -d Debug mode, print considering steps.
28
28
  -e Suppress trailing new line. Print only version out.
29
+ -f Force non-feat/fix commits to bump patch.
29
30
  -n Version is not prefixed by v, for example, 1.0.0.
30
31
  -t Show detected latest version.
31
32
  -v Show version of nextver.
data/bin/nextver CHANGED
@@ -6,6 +6,7 @@ opts = {}
6
6
  parser = OptionParser.new do |o|
7
7
  o.banner = "Usage of nextver:\n\n nextver [options...] [dir]\n\nOptions:"
8
8
  o.on("-d", "Debug mode, print considering steps.") { opts[:debug] = true }
9
+ o.on("-f", "Force non-feat/fix commits to bump patch.") { opts[:force] = true }
9
10
  o.on("-e", "Suppress trailing new line. Print only version out.") { opts[:no_newline] = true }
10
11
  o.on("-n", "Version is not prefixed by v, for example, 1.0.0.") { opts[:no_prefix] = true }
11
12
  o.on("-t", "Show detected latest version.") { opts[:latest] = true }
@@ -16,7 +17,7 @@ end
16
17
  begin
17
18
  parser.parse!
18
19
  log = ->(msg) { puts msg if opts[:debug] }
19
- repo = Nextver::Repo.new(ARGV[0] || ".", prefixed: !opts[:no_prefix], log: log)
20
+ repo = Nextver::Repo.new(ARGV[0] || ".", prefixed: !opts[:no_prefix], force: opts[:force], log: log)
20
21
  current = repo.current_version
21
22
 
22
23
  if opts[:latest]
@@ -0,0 +1,17 @@
1
+ require "rails/generators"
2
+
3
+ module Nextver
4
+ # rails generate nextver:install
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Creates bin/nextver binstub."
7
+
8
+ def create_binstub
9
+ create_file "bin/nextver", <<~RUBY
10
+ #!/usr/bin/env ruby
11
+ require "bundler/setup"
12
+ load Gem.bin_path("nextver", "nextver")
13
+ RUBY
14
+ chmod "bin/nextver", 0o755
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Nextver
2
- VERSION = "0.1.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/nextver.rb CHANGED
@@ -22,19 +22,20 @@ module Nextver
22
22
  parts[0, 3] + (parts[3] ? [0, parts[3]] : [1, ""])
23
23
  end
24
24
 
25
- # :major, :minor, :patch or nil for a single commit message.
26
- def bump(message)
25
+ # :major, :minor, :patch or nil for a single commit message. +force+ makes other conventional types :patch.
26
+ def bump(message, force: false)
27
27
  header = HEADER.match(message.strip) or return nil
28
28
  return :major if header[1] || message.lines.drop(1).any? { |l| l =~ BREAKING_FOOTER }
29
- { "feat" => :minor, "fix" => :patch }[message[/\A\w+/]]
29
+ { "feat" => :minor, "fix" => :patch }.fetch(message[/\A\w+/], force ? :patch : nil)
30
30
  end
31
31
 
32
32
  class Repo
33
- def initialize(dir = ".", prefixed: true, log: nil)
33
+ def initialize(dir = ".", prefixed: true, force: false, log: nil)
34
34
  raise Error, "target path is not git repo path" unless File.directory?(File.join(dir, ".git"))
35
35
  @dir = dir
36
36
  @prefix = prefixed ? "v" : ""
37
37
  @prefixed = prefixed
38
+ @force = force
38
39
  @log = log || ->(_) {}
39
40
  end
40
41
 
@@ -46,6 +47,7 @@ module Nextver
46
47
 
47
48
  def next_version(current = current_version)
48
49
  @log.call(@prefixed ? "Version is prefixed by v." : "Version is not prefixed by v.")
50
+ @log.call("Forcing non-feat/fix commits to bump patch.") if @force
49
51
  unless current
50
52
  @log.call("Current version is missing. Start a new one at v1.0.0.")
51
53
  return "#{@prefix}1.0.0"
@@ -56,7 +58,7 @@ module Nextver
56
58
  messages = git("log", "--format=%B%x00", "#{current}..HEAD").split("\0").map(&:strip).reject(&:empty?)
57
59
  @log.call("#{messages.size} commit(s) since latest tag")
58
60
 
59
- counts = messages.map { |m| Nextver.bump(m) }.compact.group_by(&:itself).transform_values(&:size)
61
+ counts = messages.map { |m| Nextver.bump(m, force: @force) }.compact.group_by(&:itself).transform_values(&:size)
60
62
  @log.call("============\nCommit stats\n------------")
61
63
  @log.call("Major change(s) = #{counts.fetch(:major, 0)}")
62
64
  @log.call("Minor change(s) = #{counts.fetch(:minor, 0)}")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nextver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chonlasith Jucksriporn
@@ -19,6 +19,7 @@ files:
19
19
  - LICENSE.txt
20
20
  - README.md
21
21
  - bin/nextver
22
+ - lib/generators/nextver/install_generator.rb
22
23
  - lib/nextver.rb
23
24
  - lib/nextver/version.rb
24
25
  homepage: https://github.com/chonla/nextver-gem