Class: Links

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

Overview

Manages the version comparison links at the botton of the changelog.

Release automation needs to update links. Manually calculating git diff URLs for every release is tedious and error-prone. SourceHut does not have standard comparison views, complicating matters further.

This class manages the collection of links. It parses them from the markdown. It generates the correct tree links for SourceHut. It properly shifts the “Unreleased” pointer.

Use it to update the changelog during a release.

Constant Summary collapse

PATTERN =

Regex to match the markdown links section.

Changelogs end with reference-style links. Scanning the whole document is wasteful. This pattern finds where the links begin.

/^(\[Unreleased\]: .*)$/m
UNRELEASED_PATTERN =

Regex to extract the base URL from the Unreleased link.

New version links derive from the Unreleased URL structure. Parsing the URL components enables programmatic link generation.

%r{^\[Unreleased\]: (.*?/refs/)HEAD$}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Links

Creates a new Links object.

text

String. The raw text of the links section.



48
49
50
# File 'lib/ratatui_ruby/devtools/tasks/bump/links.rb', line 48

def initialize(text)
  @text = text.dup
end

Instance Attribute Details

#textObject (readonly)

Returns the raw text of the links.



43
44
45
# File 'lib/ratatui_ruby/devtools/tasks/bump/links.rb', line 43

def text
  @text
end

Class Method Details

.from_markdown(content) ⇒ Object

Creates a Links object from the full markdown content.

content

String. The full text of the changelog.



35
36
37
38
39
40
# File 'lib/ratatui_ruby/devtools/tasks/bump/links.rb', line 35

def self.from_markdown(content)
  match = content.match(PATTERN)
  return unless match

  new(match[1].strip)
end

Instance Method Details

#release(version) ⇒ Object

Releases a new version.

Updates the “Unreleased” link to point to the new head. Adds a new link for the just-released version pointing to its specific tag.

version

String. The new version number (e.g., "0.5.0").



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

def release(version)
  return unless base_url

  new_unreleased = "[Unreleased]: #{base_url}HEAD" # .../HEAD
  new_version_link = "[#{version}]: #{base_url}v#{version}" # .../v1.0.0

  @text.sub!(UNRELEASED_PATTERN, "#{new_unreleased}\n#{new_version_link}")
  self
end

#to_sObject

Returns the string representation of the links.



69
70
71
# File 'lib/ratatui_ruby/devtools/tasks/bump/links.rb', line 69

def to_s
  @text
end