Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [#79](https://github.com/dblock/ruby-gem-release/pull/79): Select the next development version part with `next_version: :minor` or `:major` on `Workflow::RubyGem` and `Workflow::SemanticRubyGem` - [@dblock](https://github.com/dblock).
- [#80](https://github.com/dblock/ruby-gem-release/pull/80): Skip posting empty Danger report comments - [@dblock](https://github.com/dblock).
- [#82](https://github.com/dblock/ruby-gem-release/pull/82): Create the default package and Git temporary directories only when release data is first used, so loading a workflow leaves none behind - [@dblock](https://github.com/dblock).
- [#83](https://github.com/dblock/ruby-gem-release/pull/83): Name Intridea subsections with `sections:`, dropping sections without notes from a release and starting every Next section with all of them - [@dblock](https://github.com/dblock).
- Your contribution here.

## 0.7.0 (2026/11/20)
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog/intridea.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ changelog = RubyGemRelease::Changelog::Intridea.new(path: 'CHANGELOG.md')

When the released section has headings one level below its release heading, `prepare_next!` carries those headings into the new Next section and adds the configured placeholder under each one. With no subsections, it creates the usual single placeholder. Old subsection notes are not copied.

Pass `sections:`, such as `sections: %w[Features Fixes]`, to name the subsections every Next section starts with. `release!` then removes subsection headings left without notes, so a fixes-only release has no empty `#### Features`, and `prepare_next!` always adds every configured section, including ones the previous release dropped. Names must be unique, nonempty, and on one line, and the release heading must be shallower than level six. Without `sections:`, empty subsections stay in the release and are carried forward as before.

## Release

During `release:validate`, placeholder-only or structural-only notes fail unless the selected release already has a heading. Invalid headings and missing placeholders also fail; multiple matching placeholders are allowed.
Expand Down
24 changes: 24 additions & 0 deletions lib/ruby-gem-release/changelog/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ def validate_release(version, date)
def check_absent(content, pattern, message)
raise ArgumentError, "#{message} in #{@path}" unless heading_positions(content, pattern).empty?
end

def single_line?(value)
value.is_a?(String) && !value.strip.empty? && !value.match?(/[\r\n]/)
end

def validate_sections(sections)
raise ArgumentError, 'sections must be an array of unique nonempty names' unless sections.is_a?(Array) && sections.all? { |name| single_line?(name) } && sections.uniq == sections
end

# Removes subsection headings left without notes in a released section.
def remove_empty_categories(section, separator, level)
heading_positions(section, /\A\#{#{level + 1}} /).reverse_each do |offset|
finish = section_end_position(section, offset, level + 1)
start = section.index(separator, offset) || section.length
remove_line(section, offset, separator) unless notes?(document(section[start...finish]))
end
end

def remove_line(section, offset, separator)
finish = section.index(separator, offset)
length = (finish ? finish + separator.length : section.length) - offset
length += separator.length if section[0...offset].end_with?(separator * 2) && section[offset + length, separator.length] == separator
section.slice!(offset, length)
end
end
end
end
29 changes: 22 additions & 7 deletions lib/ruby-gem-release/changelog/intridea.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ class Intridea < Base
PLACEHOLDER = '- Your contribution here.'
DATE_FORMAT = '%Y/%m/%d'

def initialize(path: 'CHANGELOG.md', placeholder: PLACEHOLDER, date_format: DATE_FORMAT)
def initialize(path: 'CHANGELOG.md', placeholder: PLACEHOLDER, date_format: DATE_FORMAT, sections: [])
raise ArgumentError, 'placeholder must be a single nonempty line' unless placeholder.is_a?(String) && !placeholder.empty? && !placeholder.match?(/[\r\n]/)
raise ArgumentError, 'date_format must be a nonempty single-line strftime string or a callable' unless valid_date_format?(date_format)

validate_sections(sections)
super(path: path)
@placeholder = placeholder
@date_format = date_format
@sections = sections.dup
end

private
Expand All @@ -30,11 +32,14 @@ def update_release(version:, date:)
prefix = heading_prefix(content, position)
check_release_absent(content, version)
section_end = section_end_position(content, position, prefix.length)
content[position...section_end] = release_heading(prefix, version, date) +
release_notes(content[line_end(content, position, separator)...section_end], separator, version)
content[position...section_end] = released_section(content[line_end(content, position, separator)...section_end], prefix, version, date, separator)
File.write(@path, content)
end

def released_section(notes, prefix, version, date, separator)
release_heading(prefix, version, date) + release_notes(notes, separator, version, prefix.length)
end

# Checked before writing, so a date_format that produces an unrecognizable heading leaves the file unchanged.
def release_heading(prefix, version, date)
heading = "#{prefix} #{version} (#{format_date(date)})"
Expand All @@ -56,9 +61,17 @@ def update_next(version:, released_version:)
write_next_section(content, position, prefix, version, separator)
end

# Configured sections start every development section, including ones the
# previous release dropped because they had no notes.
def write_next_section(content, position, prefix, version, separator)
subsections = subsection_headings(content, position, prefix.length)
File.write(@path, content.insert(position, build_next_section(prefix, version, subsections, separator)))
File.write(@path, content.insert(position, build_next_section(prefix, version, next_subsections(content, position, prefix), separator)))
end

def next_subsections(content, position, prefix)
return subsection_headings(content, position, prefix.length) if @sections.empty?
raise ArgumentError, 'section headings cannot be deeper than level six' if prefix.length == 6

@sections.map { |name| "#{prefix}# #{name}" }
end

def check_release_absent(content, version)
Expand All @@ -83,8 +96,10 @@ def valid_date_format?(date_format)
date_format.is_a?(String) && !date_format.empty? && !date_format.match?(/[\r\n]/)
end

def release_notes(section, separator, version)
check_notes(remove_placeholder(section, separator), version)
def release_notes(section, separator, version, level)
remove_placeholder(section, separator)
remove_empty_categories(section, separator, level) if @sections.any?
check_notes(section, version)
end

def remove_placeholder(section, separator)
Expand Down
20 changes: 1 addition & 19 deletions lib/ruby-gem-release/changelog/keep_a_changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ def initialize(path: 'CHANGELOG.md', placeholder: nil, sections: [])

def validate_template(placeholder, sections)
raise ArgumentError, 'placeholder must be a single nonempty line' unless placeholder.nil? || single_line?(placeholder)
raise ArgumentError, 'sections must be an array of unique nonempty names' unless sections.is_a?(Array) && sections.all? { |name| single_line?(name) } && sections.uniq == sections
end

def single_line?(value)
value.is_a?(String) && !value.strip.empty? && !value.match?(/[\r\n]/)
validate_sections(sections)
end

def release_pattern(version)
Expand Down Expand Up @@ -78,21 +75,6 @@ def clean_notes(section, separator, level)
section
end

def remove_empty_categories(section, separator, level)
heading_positions(section, /\A\#{#{level + 1}} /).reverse_each do |offset|
finish = section_end_position(section, offset, level + 1)
start = section.index(separator, offset) || section.length
remove_line(section, offset, separator) unless notes?(document(section[start...finish]))
end
end

def remove_line(section, offset, separator)
finish = section.index(separator, offset)
length = (finish ? finish + separator.length : section.length) - offset
length += separator.length if section[0...offset].end_with?(separator * 2) && section[offset + length, separator.length] == separator
section.slice!(offset, length)
end

def next_section(prefix, separator)
raise ArgumentError, 'category headings cannot be deeper than level six' if prefix.length == 6 && @sections.any?

Expand Down
27 changes: 27 additions & 0 deletions spec/ruby_gem_release/changelog/intridea_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@
expect(File.read(path)).to eq("### 1.0.1 (Next)\n\n#### Features\n\n* Your contribution here.\n\n#### Fixes\n\n* Your contribution here.\n\n### 1.0.0 (2026/11/07)\n\n#### Features\n\n* Feature.\n\n#### Fixes\n\n* Fix.\n\n### 0.9.0 (2026/11/06)\n\n* Older change.\n")
end

it 'drops configured sections without notes and restores them in the next section', :aggregate_failures do
content = "### 1.0.0 (Next)\n\n#### Features\n\n* Your contribution here.\n\n#### Fixes\n\n* Fix.\n* Your contribution here.\n\n### 0.9.0 (2026/11/06)\n\n* Older change.\n"
File.write(path, content)
updater = described_class.new(path: path, placeholder: '* Your contribution here.', sections: %w[Features Fixes])

2.times { updater.release!(release) }
expect(File.read(path)).to eq("### 1.0.0 (2026/11/07)\n\n#### Fixes\n\n* Fix.\n\n### 0.9.0 (2026/11/06)\n\n* Older change.\n")

2.times { updater.prepare_next!(next_release) }
expect(File.read(path)).to eq("### 1.0.1 (Next)\n\n#### Features\n\n* Your contribution here.\n\n#### Fixes\n\n* Your contribution here.\n\n" \
"### 1.0.0 (2026/11/07)\n\n#### Fixes\n\n* Fix.\n\n### 0.9.0 (2026/11/06)\n\n* Older change.\n")
end

it 'keeps empty subsections without configured sections' do
File.write(path, "### 1.0.0 (Next)\n\n#### Features\n\n* Your contribution here.\n\n#### Fixes\n\n* Fix.\n* Your contribution here.\n")
described_class.new(path: path, placeholder: '* Your contribution here.').release!(release)
expect(File.read(path)).to eq("### 1.0.0 (2026/11/07)\n\n#### Features\n\n#### Fixes\n\n* Fix.\n")
end

it 'rejects invalid configured sections and level-seven section headings', :aggregate_failures do
[%w[Fixes Fixes], [''], ["Two\nLines"], 'Fixes'].each do |sections|
expect { described_class.new(path: path, sections: sections) }.to raise_error(ArgumentError, /sections must be an array of unique nonempty names/)
end
File.write(path, "###### 1.0.0 (2026/11/07)\n\n- Change.\n")
expect { described_class.new(path: path, sections: %w[Fixes]).prepare_next!(next_release) }.to raise_error(ArgumentError, /deeper than level six/)
end

it 'ignores fenced headings and placeholders while releasing an Intridea section' do
content = "## 1.0.0 (Next)\n\n```\n## Example\n- Your contribution here.\n```\n\n- Your contribution here.\n"
File.write(path, content)
Expand Down
Loading