nextver 0.2.0 → 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: 2e6894a5f36486ee9b1edf138db8db97a9e8e2b5ee500332fe6665aa059bc719
4
- data.tar.gz: 5c66d173cb29b4ffead6695080a655f44d63332d2555a982dd2849cd7da791e7
3
+ metadata.gz: 5bb8461f23e755657657651af9c58f17e7bd01079495fa04b2aae42c4634d688
4
+ data.tar.gz: 69b372968a5a0d00bd4c70568e130485d723a6d0ee6839e52240ff4df1d1443a
5
5
  SHA512:
6
- metadata.gz: 7d2f9f763ba8048e3408fe66993ad18a5f5a63a048bb9ecc4c2919b9e0694dc4e93418858a8877c398459333695228d6c997c3171e0d88a6565fd55017deb000
7
- data.tar.gz: fd44002a1827f6d5beb0b898b11615db6ae1a942148c3a11278b214c0bbd2606cefbc68c07df11e652f581f58b38874a68aad3693cec5ef45fc3795ad5503490
6
+ metadata.gz: 482823e6a7272e67576d043f275b66ff525ef4a6d825f58d66ccb4ac494b8cc2d4e70f09df200e97afe901a66ee1f7f9ff64d2ac9707ec7c345be57ca06a67aa
7
+ data.tar.gz: 57b139973304c592122e90d4e0dae5bdee939f393171ba11d44826b2ef8749fa2f88bb6057c1e38e4b1bb3a5b2b6d58203c88c02923dc447d948c92ca08ef261
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 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]
@@ -1,3 +1,3 @@
1
1
  module Nextver
2
- VERSION = "0.2.0"
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chonlasith Jucksriporn