reissue 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -5
- data/README.md +3 -3
- data/lib/reissue/markdown.rb +115 -0
- data/lib/reissue/parser.rb +2 -85
- data/lib/reissue/printer.rb +2 -2
- data/lib/reissue/rake.rb +2 -1
- data/lib/reissue/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b29a6f2ef60fb2fcd7c8a87473a6331b7761c6396f1274128821540f562ec06c
|
4
|
+
data.tar.gz: fd813df98ea7a642b4b65895db0155a5ba34100f65358fbd0fb65863fcb992d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed99a9041e9ab54640c75d5eb5ff6dc86688a120069d8b5d9c866f0299c15c883bc4e7aecb7cd511c43e44dc4667d4f029e7cbab794ad84a4d45b9c43a7b8da7
|
7
|
+
data.tar.gz: f693b77d20a53cd92619efc3d3c984d93788b98caaac3d88a853bed175b8c7f589f8d4837196769dd8f9f6f7650a5c23dab1a956140c4bf774f5001df6b953d1
|
data/CHANGELOG.md
CHANGED
@@ -5,18 +5,28 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
-
## [0.
|
8
|
+
## [0.2.0] - 2024-07-02
|
9
9
|
|
10
10
|
### Added
|
11
11
|
|
12
|
-
-
|
12
|
+
- Reissue::Markdown class to implement the Reissue::Parser.parse behavior
|
13
|
+
|
14
|
+
### Removed
|
15
|
+
|
16
|
+
- Reissue::Parser implementation
|
13
17
|
|
14
18
|
### Fixed
|
15
19
|
|
16
|
-
-
|
20
|
+
- Handle multiline changes
|
21
|
+
|
22
|
+
## [0.1.8] - Unreleased
|
23
|
+
|
24
|
+
### Changed
|
25
|
+
|
26
|
+
- Update the README.md to specify the default values for some configuration.
|
17
27
|
|
18
|
-
## [0.1.
|
28
|
+
## [0.1.7] - 2024-06-10
|
19
29
|
|
20
30
|
### Fixed
|
21
31
|
|
22
|
-
-
|
32
|
+
- Pass the version_redo_proc to the Reissue.call in the reissue task.
|
data/README.md
CHANGED
@@ -89,15 +89,15 @@ Reissue::Task.create :your_name_and_namespace do |task|
|
|
89
89
|
# Required: The file to update with the new version number.
|
90
90
|
task.version_file = "path/to/version.rb"
|
91
91
|
|
92
|
-
# Optional: The number of versions to maintain in the changelog.
|
92
|
+
# Optional: The number of versions to maintain in the changelog. Defaults to 2.
|
93
93
|
task.version_limit = 5
|
94
94
|
|
95
95
|
# Optional: A Proc to format the version number. Receives a Gem::Version object, and segment.
|
96
|
-
task.
|
96
|
+
task.version_redo_proc = ->(version, segment) do
|
97
97
|
# your special versioning logic
|
98
98
|
end
|
99
99
|
|
100
|
-
# Optional: The file to update with the new version number.
|
100
|
+
# Optional: The file to update with the new version number. Defaults to "CHANGELOG.md".
|
101
101
|
task.changelog_file = "path/to/CHANGELOG.md"
|
102
102
|
|
103
103
|
# Optional: Whether to commit the changes automatically. Defaults to true.
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module Reissue
|
2
|
+
class Markdown
|
3
|
+
def self.parse(changelog)
|
4
|
+
new(changelog).to_h
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(changelog)
|
8
|
+
@changelog = changelog
|
9
|
+
@versions = {}
|
10
|
+
@header = nil
|
11
|
+
@parts = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse
|
15
|
+
return unless @header.nil? && @versions.empty?
|
16
|
+
|
17
|
+
header, *chunks = @changelog.split(/^## /)
|
18
|
+
|
19
|
+
@header = Header.new(header)
|
20
|
+
@versions = Array(chunks).map { |part| Version.new(part) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_h
|
24
|
+
parse
|
25
|
+
@header.to_h.merge("versions" => @versions.map(&:to_h))
|
26
|
+
end
|
27
|
+
|
28
|
+
class Header
|
29
|
+
def initialize(chunk)
|
30
|
+
@chunk = chunk.to_s
|
31
|
+
@title = nil
|
32
|
+
@preamble = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse
|
36
|
+
return unless @title.nil? && @preamble.nil?
|
37
|
+
|
38
|
+
scanner = StringScanner.new(@chunk.dup << "\n")
|
39
|
+
scanner.scan(/# ([\w\s]+)$/)
|
40
|
+
@title = scanner[1].to_s.strip
|
41
|
+
# the rest of the text is the preamble
|
42
|
+
@preamble = scanner.rest.strip
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_h
|
46
|
+
parse
|
47
|
+
{
|
48
|
+
"title" => @title,
|
49
|
+
"preamble" => @preamble
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Version
|
55
|
+
def initialize(chunk)
|
56
|
+
@chunk = chunk
|
57
|
+
@version = nil
|
58
|
+
@date = nil
|
59
|
+
@changes = []
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse
|
63
|
+
return unless @version.nil? && @date.nil? && @changes.empty?
|
64
|
+
# the first line contains the version and date
|
65
|
+
scanner = StringScanner.new(@chunk) << "\n"
|
66
|
+
scanner.scan(/\[?(.[^\]]+)\]? - (.+)$/)
|
67
|
+
@version = scanner[1].to_s.strip
|
68
|
+
@date = scanner[2].to_s.strip || "Unreleased"
|
69
|
+
|
70
|
+
# the rest of the text is the changes
|
71
|
+
@changes = scanner.rest.strip.split("### ").reject(&:empty?).map { |change| Change.new(change) }
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_h
|
75
|
+
parse
|
76
|
+
{
|
77
|
+
"version" => @version,
|
78
|
+
"date" => @date,
|
79
|
+
"changes" => @changes.inject({}) { |h, change| h.merge(change.to_h) }
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Change
|
85
|
+
def initialize(chunk)
|
86
|
+
@chunk = chunk
|
87
|
+
@type = nil
|
88
|
+
@changes = []
|
89
|
+
end
|
90
|
+
|
91
|
+
def parse
|
92
|
+
return unless @type.nil? && @changes.empty?
|
93
|
+
scanner = StringScanner.new(@chunk) << "\n"
|
94
|
+
scanner.scan(/([\w\s]+)$/)
|
95
|
+
|
96
|
+
@type = scanner[1].to_s.strip
|
97
|
+
|
98
|
+
# the rest of the text are the changes
|
99
|
+
@changes = scanner
|
100
|
+
.rest
|
101
|
+
.strip
|
102
|
+
.split(/^-/m)
|
103
|
+
.map { |change| change.strip.gsub(/^- /m, "") }
|
104
|
+
.reject(&:empty?)
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_h
|
108
|
+
parse
|
109
|
+
{
|
110
|
+
@type => @changes.map { |change| change.split("\n").map(&:strip).join("\n ") }
|
111
|
+
}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/lib/reissue/parser.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "strscan"
|
2
|
+
require_relative "markdown"
|
2
3
|
|
3
4
|
module Reissue
|
4
5
|
class Parser
|
@@ -8,94 +9,10 @@ module Reissue
|
|
8
9
|
|
9
10
|
def initialize(changelog)
|
10
11
|
@changelog = changelog
|
11
|
-
@versions = {}
|
12
|
-
@parts = []
|
13
12
|
end
|
14
13
|
|
15
14
|
def parse
|
16
|
-
|
17
|
-
@parts << parse_title(scanner)
|
18
|
-
@parts << parse_preamble(scanner)
|
19
|
-
@parts << parse_versions(scanner)
|
20
|
-
@parts.compact.reduce(&:merge)
|
21
|
-
end
|
22
|
-
|
23
|
-
VERSION_BREAK = "## "
|
24
|
-
CHANGE_BREAK = "### "
|
25
|
-
VERSION_MATCH = /^#{VERSION_BREAK}/
|
26
|
-
VERSION_OR_CHANGE_MATCH = Regexp.union(CHANGE_BREAK, VERSION_BREAK)
|
27
|
-
VERSION_OR_CHANGE_OR_NEWLINE_MATCH = Regexp.union(/\n/, CHANGE_BREAK, VERSION_BREAK)
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def parse_title(scanner)
|
32
|
-
scanner.scan(/# ([\w\s]+)$/)
|
33
|
-
title = scanner[1].to_s.strip
|
34
|
-
{"title" => title}
|
35
|
-
end
|
36
|
-
|
37
|
-
def parse_preamble(scanner)
|
38
|
-
preamble = scanner.scan_until(VERSION_MATCH)
|
39
|
-
preamble = preamble.to_s.gsub(VERSION_BREAK, "").strip
|
40
|
-
scanner.unscan unless preamble.empty?
|
41
|
-
{"preamble" => preamble.strip}
|
42
|
-
end
|
43
|
-
|
44
|
-
def parse_versions(scanner)
|
45
|
-
until scanner.eos?
|
46
|
-
scanner.skip(/\s+/)
|
47
|
-
next_line = scanner.scan_until(VERSION_OR_CHANGE_OR_NEWLINE_MATCH)
|
48
|
-
break if next_line.nil? || next_line.strip.empty?
|
49
|
-
unless next_line.match?(VERSION_OR_CHANGE_MATCH)
|
50
|
-
parse_versions(scanner)
|
51
|
-
end
|
52
|
-
if next_line.match?(VERSION_MATCH)
|
53
|
-
scanner.scan_until(/(.+)\n/)
|
54
|
-
version, date = scanner[1].split(" - ")
|
55
|
-
date ||= "Unreleased"
|
56
|
-
version = version.gsub(VERSION_BREAK, "").strip.tr("[]", "")
|
57
|
-
changes = parse_changes(scanner)
|
58
|
-
@versions[version] = {"version" => version, "date" => date, "changes" => changes}
|
59
|
-
parse_versions(scanner)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
{"versions" => @versions.values}
|
63
|
-
end
|
64
|
-
|
65
|
-
def parse_changes(scanner, changes: {})
|
66
|
-
return changes if scanner.eos?
|
67
|
-
scanner.skip(/\s+/)
|
68
|
-
|
69
|
-
next_line = scanner.scan_until(/\n/)
|
70
|
-
if next_line.nil? || next_line.strip.empty?
|
71
|
-
return changes
|
72
|
-
elsif next_line.match?(VERSION_MATCH)
|
73
|
-
scanner.unscan
|
74
|
-
return changes
|
75
|
-
end
|
76
|
-
|
77
|
-
if next_line.match?(CHANGE_BREAK)
|
78
|
-
change_type = next_line.gsub(CHANGE_BREAK, "").strip
|
79
|
-
changes[change_type] = parse_change_list(scanner)
|
80
|
-
end
|
81
|
-
parse_changes(scanner, changes: changes)
|
82
|
-
end
|
83
|
-
|
84
|
-
def parse_change_list(scanner, collection: [])
|
85
|
-
return collection if scanner.eos?
|
86
|
-
scanner.skip(/\s+/)
|
87
|
-
change = scanner.scan_until(/\n/)
|
88
|
-
if change.nil? || change.strip.empty?
|
89
|
-
return collection
|
90
|
-
elsif change.match?(VERSION_OR_CHANGE_MATCH)
|
91
|
-
scanner.unscan
|
92
|
-
return collection
|
93
|
-
else
|
94
|
-
item = change.sub(/^\s?-\s?/, "").strip
|
95
|
-
collection << item
|
96
|
-
parse_change_list(scanner, collection:)
|
97
|
-
end
|
98
|
-
collection.reject(&:empty?).compact
|
15
|
+
Markdown.parse(@changelog).to_h
|
99
16
|
end
|
100
17
|
end
|
101
18
|
end
|
data/lib/reissue/printer.rb
CHANGED
@@ -25,8 +25,8 @@ module Reissue
|
|
25
25
|
{}
|
26
26
|
end
|
27
27
|
version_string = "## [#{version}] - #{date}"
|
28
|
-
changes_string = changes.map do |section,
|
29
|
-
format_section(section,
|
28
|
+
changes_string = changes.map do |section, section_changes|
|
29
|
+
format_section(section, section_changes)
|
30
30
|
end.join("\n\n")
|
31
31
|
[version_string, changes_string].filter_map { |str| str unless str.empty? }.join("\n\n")
|
32
32
|
end.then do |data|
|
data/lib/reissue/rake.rb
CHANGED
@@ -49,13 +49,14 @@ module Reissue
|
|
49
49
|
@commit = true
|
50
50
|
@commit_finalize = true
|
51
51
|
@version_limit = 2
|
52
|
+
@version_redo_proc = nil
|
52
53
|
end
|
53
54
|
|
54
55
|
def define
|
55
56
|
desc description
|
56
57
|
task name, [:segment] do |task, args|
|
57
58
|
segment = args[:segment] || "patch"
|
58
|
-
new_version = Reissue.call(segment:, version_file:, version_limit:)
|
59
|
+
new_version = Reissue.call(segment:, version_file:, version_limit:, version_redo_proc:)
|
59
60
|
if defined?(Bundler)
|
60
61
|
Bundler.with_unbundled_env do
|
61
62
|
system("bundle install")
|
data/lib/reissue/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reissue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Gay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/reissue.rb
|
39
39
|
- lib/reissue/changelog_updater.rb
|
40
40
|
- lib/reissue/gem.rb
|
41
|
+
- lib/reissue/markdown.rb
|
41
42
|
- lib/reissue/parser.rb
|
42
43
|
- lib/reissue/printer.rb
|
43
44
|
- lib/reissue/rake.rb
|