nextver 0.2.0 → 0.4.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: 2e6894a5f36486ee9b1edf138db8db97a9e8e2b5ee500332fe6665aa059bc719
4
- data.tar.gz: 5c66d173cb29b4ffead6695080a655f44d63332d2555a982dd2849cd7da791e7
3
+ metadata.gz: 33c4498c88b85d30319159d4d87d712dcd308e55eadc3eebc76843999a88756e
4
+ data.tar.gz: 9f3d97eda985aa440780513806134fdd02d7aeb41b2eac106114eb0a90703d0b
5
5
  SHA512:
6
- metadata.gz: 7d2f9f763ba8048e3408fe66993ad18a5f5a63a048bb9ecc4c2919b9e0694dc4e93418858a8877c398459333695228d6c997c3171e0d88a6565fd55017deb000
7
- data.tar.gz: fd44002a1827f6d5beb0b898b11615db6ae1a942148c3a11278b214c0bbd2606cefbc68c07df11e652f581f58b38874a68aad3693cec5ef45fc3795ad5503490
6
+ metadata.gz: e7531c23b2c3f360206502a9f1b890917f3e3367dd65e4516dd6a2c39f189aecff91d7c94b8eaad171dae98861e51bd99d71935c48a07c101b14ca7c11c801de
7
+ data.tar.gz: e6a0cc48b82a1bdfa4e8971f51565fc29395616a57e4a8638382a6662622d03605039475e75f1280b17cfc7eaa50b713ae88431d30437e60bf49056ead7289ad
data/README.md CHANGED
@@ -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 other commit types 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 other commit types 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]
@@ -1,3 +1,3 @@
1
1
  module Nextver
2
- VERSION = "0.2.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/nextver.rb CHANGED
@@ -8,6 +8,7 @@ module Nextver
8
8
  SEMVER = /\Av(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?)?)?\z/
9
9
  HEADER = /\A\w+(?:\([\w-]+\))?(!)?: .+/
10
10
  BREAKING_FOOTER = /^BREAKING[ -]CHANGE(?:: | #)/
11
+ BUMPS = { "feat" => :minor }.merge(%w[fix chore doc docs style styles refactor].to_h { |t| [t, :patch] }).freeze
11
12
 
12
13
  module_function
13
14
 
@@ -22,19 +23,20 @@ module Nextver
22
23
  parts[0, 3] + (parts[3] ? [0, parts[3]] : [1, ""])
23
24
  end
24
25
 
25
- # :major, :minor, :patch or nil for a single commit message.
26
- def bump(message)
26
+ # :major, :minor, :patch or nil for a single commit message. +force+ makes types outside BUMPS :patch.
27
+ def bump(message, force: false)
27
28
  header = HEADER.match(message.strip) or return nil
28
29
  return :major if header[1] || message.lines.drop(1).any? { |l| l =~ BREAKING_FOOTER }
29
- { "feat" => :minor, "fix" => :patch }[message[/\A\w+/]]
30
+ BUMPS.fetch(message[/\A\w+/], force ? :patch : nil)
30
31
  end
31
32
 
32
33
  class Repo
33
- def initialize(dir = ".", prefixed: true, log: nil)
34
+ def initialize(dir = ".", prefixed: true, force: false, log: nil)
34
35
  raise Error, "target path is not git repo path" unless File.directory?(File.join(dir, ".git"))
35
36
  @dir = dir
36
37
  @prefix = prefixed ? "v" : ""
37
38
  @prefixed = prefixed
39
+ @force = force
38
40
  @log = log || ->(_) {}
39
41
  end
40
42
 
@@ -46,6 +48,7 @@ module Nextver
46
48
 
47
49
  def next_version(current = current_version)
48
50
  @log.call(@prefixed ? "Version is prefixed by v." : "Version is not prefixed by v.")
51
+ @log.call("Forcing all other commit types to bump patch.") if @force
49
52
  unless current
50
53
  @log.call("Current version is missing. Start a new one at v1.0.0.")
51
54
  return "#{@prefix}1.0.0"
@@ -56,7 +59,7 @@ module Nextver
56
59
  messages = git("log", "--format=%B%x00", "#{current}..HEAD").split("\0").map(&:strip).reject(&:empty?)
57
60
  @log.call("#{messages.size} commit(s) since latest tag")
58
61
 
59
- counts = messages.map { |m| Nextver.bump(m) }.compact.group_by(&:itself).transform_values(&:size)
62
+ counts = messages.map { |m| Nextver.bump(m, force: @force) }.compact.group_by(&:itself).transform_values(&:size)
60
63
  @log.call("============\nCommit stats\n------------")
61
64
  @log.call("Major change(s) = #{counts.fetch(:major, 0)}")
62
65
  @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.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chonlasith Jucksriporn