reissue 0.3.0 → 0.3.2

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: b279a283d58ba13af326acf3eec52c805deffd80bfc0cd6e4e9a7d320cc9dd0f
4
- data.tar.gz: 4394e68a43bb33c0068fcb9869dac6bfa4f1a27bdd890afe2e65d3cdd2fe1cd6
3
+ metadata.gz: 4cc74e34e41fc5b950be6012c3b517235f0a6537f30c09ae17c6f8d66240407a
4
+ data.tar.gz: 19f8f5b5bb7cdce525e26d3def6c18139462def2b9ac5c936659a7f4608bf213
5
5
  SHA512:
6
- metadata.gz: 7d1d3335bf01a5563b93cf3dd4ba030f2e851a5a5cbbbfd23d38e9fdcda21634fa4cd0fb6cfe3fd9ba0b56bf55f3ab744116d77b38dadbda98844676dccd9a88
7
- data.tar.gz: 3ece0d9ecfe89e38c0dfef00304acaf1502760a7e9c3759f380d18b9698e2f1233e8cc2716d0c1184a00a11f5c7c457e4d386adf63dbabcd70ec0fb43f001eb4
6
+ metadata.gz: 84e988380692e405e2e173e2e87cb9e6088328e120640c4a482b3e737985961abe40f1ecadffd674113489f635101d0f75777d56635a3636b054f27c275c1be7
7
+ data.tar.gz: 02f0db508076455faf195b7f1b0ecd8d8ab3b1e772e61f335935b48f2bde96aee76aa6a89c9a8e39c44d358fe3d2d70d1fe41c2d4bd2ccdb445c0b103ed4b853
data/CHANGELOG.md CHANGED
@@ -5,14 +5,20 @@ 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.3.0] - 2024-09-06
8
+ ## [0.3.2] - 2025-01-16
9
+
10
+ ### Fixed
11
+
12
+ - Parser will handle nil changes
13
+
14
+ ## [0.3.1] - 2025-01-16
9
15
 
10
16
  ### Added
11
17
 
12
- - Add `push_reissue` option to control pushing changes to the remote repository.
18
+ - Add `retain_changelogs` option to control how to retain the changelog files for the previous versions.
13
19
 
14
20
  ### Changed
15
21
 
16
- - Default behavior of _this_ gem's release is to push finalize without a branch.
17
-
18
- ## [0.2.3] - Unreleased
22
+ - Set the name of the `reissue:branch` argument to `branch_name` to be clearer.
23
+ - Inject the constants in the `create` method.
24
+ - Updated the tested Ruby version to 3.4.
data/README.md CHANGED
@@ -104,6 +104,16 @@ Reissue::Task.create :your_name_and_namespace do |task|
104
104
  # Optional: The file to update with the new version number. Defaults to "CHANGELOG.md".
105
105
  task.changelog_file = "path/to/CHANGELOG.md"
106
106
 
107
+ # Optional: A Boolean, String, or Proc to retain the changelog files for the previous versions. Defaults to false.
108
+ # Setting to true will retain the changelog files in the "changelogs" directory.
109
+ # Setting to a String will use that path as the directory to retain the changelog files.
110
+ # The Proc receives a version hash and the changelog content.
111
+ task.retain_changelogs = ->(version, content) do
112
+ # your special retention logic
113
+ end
114
+ # or task.retain_changelogs = "path/to/changelogs"
115
+ # or task.retain_changelogs = true
116
+
107
117
  # Optional: Whether to commit the changes automatically. Defaults to true.
108
118
  task.commit = false
109
119
 
@@ -18,23 +18,24 @@ module Reissue
18
18
  # @param changes [Hash] The changes for the version (default: {}).
19
19
  # @param changelog_file [String] The path to the changelog file (default: @changelog_file).
20
20
  # @param version_limit [Integer] The number of versions to keep (default: 2).
21
- def call(version, date: "Unreleased", changes: {}, changelog_file: @changelog_file, version_limit: 2)
21
+ def call(version, date: "Unreleased", changes: {}, changelog_file: @changelog_file, version_limit: 2, retain_changelogs: false)
22
22
  update(version, date:, changes:, version_limit:)
23
- write(changelog_file)
23
+ write(changelog_file, retain_changelogs:)
24
24
  changelog
25
25
  end
26
26
 
27
- def finalize(date: Date.today, changelog_file: @changelog_file)
27
+ def finalize(date: Date.today, changelog_file: @changelog_file, retain_changelogs: false)
28
28
  @changelog = Parser.parse(File.read(changelog_file))
29
+
29
30
  # find the highest version number and if it is unreleased, update the date
30
- version = changelog["versions"].max_by { |v| ::Gem::Version.new(v["version"]) }
31
+ version = latest_version
31
32
  version_date = version["date"]
32
33
  if version_date.nil? || version_date == "Unreleased"
33
34
  changelog["versions"].find do |v|
34
35
  v["version"] == version["version"]
35
36
  end["date"] = date
36
37
  end
37
- write
38
+ write(changelog_file, retain_changelogs:)
38
39
  changelog
39
40
  end
40
41
 
@@ -57,10 +58,10 @@ module Reissue
57
58
  #
58
59
  # @param changelog_file [String] The path to the changelog file (default: @changelog_file).
59
60
  # @return [Hash] The parsed changelog.
60
- def reformat(result_file = @changelog_file, version_limit: 2)
61
+ def reformat(result_file = @changelog_file, version_limit: 2, retain_changelogs: false)
61
62
  @changelog = Parser.parse(File.read(@changelog_file))
62
63
  changelog["versions"] = changelog["versions"].first(version_limit)
63
- write(result_file)
64
+ write(result_file, retain_changelogs:)
64
65
  changelog
65
66
  end
66
67
 
@@ -74,8 +75,34 @@ module Reissue
74
75
  # Writes the changelog to the specified file.
75
76
  #
76
77
  # @param changelog_file [String] The path to the changelog file (default: @changelog_file).
77
- def write(changelog_file = @changelog_file)
78
+ def write(changelog_file = @changelog_file, retain_changelogs: false)
79
+ if retain_changelogs
80
+ store_current_changelog(latest_version, retain_changelogs)
81
+ end
78
82
  File.write(changelog_file, to_s)
79
83
  end
84
+
85
+ # Stores the current changelog in a file.
86
+ #
87
+ # @param version [Hash] The version information.
88
+ # @param path [String, Proc] The path to store the changelog or a callable that receives the version and the changelog.
89
+ def store_current_changelog(version, path)
90
+ if path
91
+ if path.respond_to?(:call)
92
+ path.call(version, to_s)
93
+ else
94
+ require "fileutils"
95
+ path = path.is_a?(String) ? path : "changelogs"
96
+ FileUtils.mkdir_p(path)
97
+ File.write("#{path}/#{version["version"]}.md", to_s)
98
+ end
99
+ end
100
+ end
101
+
102
+ private
103
+
104
+ def latest_version
105
+ changelog["versions"].max_by { |v| ::Gem::Version.new(v["version"]) }
106
+ end
80
107
  end
81
108
  end
@@ -18,7 +18,7 @@ module Reissue
18
18
  private
19
19
 
20
20
  def versions
21
- @changelog["versions"].map do |data|
21
+ @changelog["versions"].to_a.map do |data|
22
22
  version = data["version"]
23
23
  date = data["date"]
24
24
  changes = data.fetch("changes") do
data/lib/reissue/rake.rb CHANGED
@@ -31,6 +31,11 @@ module Reissue
31
31
  # The path to the changelog file.
32
32
  attr_accessor :changelog_file
33
33
 
34
+ # Set to true to retain the changelog files for the previous versions.
35
+ # Default: false.
36
+ # Provide a callable to decide how to store the files.
37
+ attr_accessor :retain_changelogs
38
+
34
39
  # Additional paths to add to the commit.
35
40
  attr_writer :updated_paths
36
41
 
@@ -60,12 +65,15 @@ module Reissue
60
65
  # Set this to :branch to push to a new branch.
61
66
  attr_accessor :push_reissue
62
67
 
63
- def initialize(name = :reissue)
68
+ def initialize(name = :reissue, formatter: Reissue, tasker: Rake::Task)
64
69
  @name = name
70
+ @formatter = formatter
71
+ @tasker = tasker
65
72
  @description = "Prepare the code for work on a new version."
66
73
  @version_file = nil
67
74
  @updated_paths = []
68
75
  @changelog_file = "CHANGELOG.md"
76
+ @retain_changelogs = false
69
77
  @commit = true
70
78
  @commit_finalize = true
71
79
  @push_finalize = false
@@ -74,6 +82,9 @@ module Reissue
74
82
  @push_reissue = :branch
75
83
  end
76
84
 
85
+ attr_reader :formatter, :tasker
86
+ private :formatter, :tasker
87
+
77
88
  def finalize_with_branch?
78
89
  push_finalize == :branch
79
90
  end
@@ -90,29 +101,33 @@ module Reissue
90
101
  !!push_reissue
91
102
  end
92
103
 
104
+ def bundle
105
+ if defined?(Bundler)
106
+ Bundler.with_unbundled_env do
107
+ system("bundle install")
108
+ end
109
+ end
110
+ end
111
+
93
112
  def define
94
113
  desc description
95
114
  task name, [:segment] do |task, args|
96
115
  segment = args[:segment] || "patch"
97
- new_version = Reissue.call(segment:, version_file:, version_limit:, version_redo_proc:)
98
- if defined?(Bundler)
99
- Bundler.with_unbundled_env do
100
- system("bundle install")
101
- end
102
- end
116
+ new_version = formatter.call(segment:, version_file:, version_limit:, version_redo_proc:)
117
+ bundle
103
118
 
104
119
  system("git add -u")
105
- if updated_paths.any?
120
+ if updated_paths&.any?
106
121
  system("git add #{updated_paths.join(" ")}")
107
122
  end
108
123
 
109
124
  bump_message = "Bump version to #{new_version}"
110
125
  if commit
111
126
  if reissue_version_with_branch?
112
- Rake::Task["#{name}:branch"].invoke("reissue/#{new_version}")
127
+ tasker["#{name}:branch"].invoke("reissue/#{new_version}")
113
128
  end
114
129
  system("git commit -m '#{bump_message}'")
115
- Rake::Task["#{name}:push"].invoke if push_reissue?
130
+ tasker["#{name}:push"].invoke if push_reissue?
116
131
  else
117
132
  system("echo '#{bump_message}'")
118
133
  end
@@ -127,28 +142,28 @@ module Reissue
127
142
  else
128
143
  args[:version_limit].to_i
129
144
  end
130
- Reissue.reformat(changelog_file, version_limit:)
145
+ formatter.reformat(changelog_file, version_limit:, retain_changelogs:)
131
146
  end
132
147
 
133
148
  desc "Finalize the changelog for an unreleased version to set the release date."
134
149
  task "#{name}:finalize", [:date] do |task, args|
135
150
  date = args[:date] || Time.now.strftime("%Y-%m-%d")
136
- version, date = Reissue.finalize(date, changelog_file:)
151
+ version, date = formatter.finalize(date, changelog_file:)
137
152
  finalize_message = "Finalize the changelog for version #{version} on #{date}"
138
153
  if commit_finalize
139
- Rake::Task["#{name}:branch"].invoke("reissue/#{version}") if finalize_with_branch?
154
+ tasker["#{name}:branch"].invoke("reissue/#{version}") if finalize_with_branch?
140
155
  system("git add -u")
141
156
  system("git commit -m '#{finalize_message}'")
142
- Rake::Task["#{name}:push"].invoke if push_finalize?
157
+ tasker["#{name}:push"].invoke if push_finalize?
143
158
  else
144
159
  system("echo '#{finalize_message}'")
145
160
  end
146
161
  end
147
162
 
148
163
  desc "Create a new branch for the next version."
149
- task "#{name}:branch", [:branch] do |task, args|
150
- raise "No branch name specified" unless args[:branch]
151
- system("git checkout -b #{args[:branch]}")
164
+ task "#{name}:branch", [:branch_name] do |task, args|
165
+ raise "No branch name specified" unless args[:branch_name]
166
+ system("git checkout -b #{args[:branch_name]}")
152
167
  end
153
168
 
154
169
  desc "Push the current branch to the remote repository."
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Reissue
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.2"
5
5
  end
data/lib/reissue.rb CHANGED
@@ -19,6 +19,7 @@ module Reissue
19
19
  def self.call(
20
20
  version_file:,
21
21
  changelog_file: "CHANGELOG.md",
22
+ retain_changelogs: false,
22
23
  segment: "patch",
23
24
  date: "Unreleased",
24
25
  changes: {},
@@ -29,7 +30,7 @@ module Reissue
29
30
  new_version = version_updater.call(segment, version_file:)
30
31
  if changelog_file
31
32
  changelog_updater = ChangelogUpdater.new(changelog_file)
32
- changelog_updater.call(new_version, date:, changes:, changelog_file:, version_limit:)
33
+ changelog_updater.call(new_version, date:, changes:, changelog_file:, version_limit:, retain_changelogs:)
33
34
  end
34
35
  new_version
35
36
  end
@@ -50,8 +51,9 @@ module Reissue
50
51
  #
51
52
  # @param file [String] The path to the changelog file.
52
53
  # @param version_limit [Integer] The number of versions to retain in the changelog. Default: 2
53
- def self.reformat(file, version_limit: 2)
54
+ # @param retain_changelogs [Boolean, String, Proc] Whether to retain the changelog files for the previous versions.
55
+ def self.reformat(file, version_limit: 2, retain_changelogs: false)
54
56
  changelog_updater = ChangelogUpdater.new(file)
55
- changelog_updater.reformat(version_limit:)
57
+ changelog_updater.reformat(version_limit:, retain_changelogs:)
56
58
  end
57
59
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reissue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-09-06 00:00:00.000000000 Z
10
+ date: 2025-01-16 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -50,7 +49,6 @@ metadata:
50
49
  homepage_uri: https://github.com/SOFware/reissue
51
50
  source_code_uri: https://github.com/SOFware/reissue
52
51
  changelog_uri: https://github.com/SOFware/reissue/blob/main/CHANGELOG.md
53
- post_install_message:
54
52
  rdoc_options: []
55
53
  require_paths:
56
54
  - lib
@@ -65,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
63
  - !ruby/object:Gem::Version
66
64
  version: '0'
67
65
  requirements: []
68
- rubygems_version: 3.5.9
69
- signing_key:
66
+ rubygems_version: 3.6.2
70
67
  specification_version: 4
71
68
  summary: Keep your versions and changelogs up to date and prepared for release.
72
69
  test_files: []