Class: Changelog

Inherits:
Object
  • Object
show all
Defined in:
lib/ratatui_ruby/devtools/tasks/bump/changelog.rb

Overview

Manages the project’s CHANGELOG.md file.

Changelogs track user-facing changes. During a release, the Unreleased section becomes a versioned section. Links update. The Unreleased section resets. Doing this by hand invites errors.

This class orchestrates the changelog update. It parses the sections, moves content, updates links, and writes the result. One call. Clean changelog.

Use it during version bumps to update the release notes.

Instance Method Summary collapse

Constructor Details

#initialize(path: "CHANGELOG.md") ⇒ Changelog

Creates a new Changelog manager.

path

The path to the changelog file. Defaults to CHANGELOG.md.



27
28
29
# File 'lib/ratatui_ruby/devtools/tasks/bump/changelog.rb', line 27

def initialize(path: "CHANGELOG.md")
  @path = path
end

Instance Method Details

#commit_message(version) ⇒ Object

Generates a commit message for the release.

Extracts the unreleased changes and formats them for a commit body.

version

The version being released.



60
61
62
63
64
65
66
# File 'lib/ratatui_ruby/devtools/tasks/bump/changelog.rb', line 60

def commit_message(version)
  content = File.read(@path)
  unreleased = UnreleasedSection.parse(content)
  return nil unless unreleased

  "chore: release v#{version}\n\n#{unreleased.commit_body}"
end

#release(new_version) ⇒ Object

Releases a new version in the changelog.

Moves unreleased changes to a dated version section. Resets the Unreleased section. Updates the comparison links.

new_version

The SemVer or version string to release.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ratatui_ruby/devtools/tasks/bump/changelog.rb', line 37

def release(new_version)
  content = File.read(@path)

  header = Header.parse(content)
  unreleased = UnreleasedSection.parse(content)
  links = Links.from_markdown(content)

  raise "Could not parse CHANGELOG.md" unless header && unreleased && links

  history = History.parse(content, header.length, unreleased.to_s.length, links.to_s)

  links.release(new_version)
  history.add(unreleased.as_version(new_version))

  File.write(@path, "#{header}#{UnreleasedSection.fresh}\n\n#{history}\n#{links}")
  nil
end