Class: Changelogger::ChangelogGenerator
- Inherits:
-
Object
- Object
- Changelogger::ChangelogGenerator
- Defined in:
- lib/changelogger/changelog_generator.rb
Overview
Changelog generator.
Class Method Summary collapse
-
.build_sections(versioned) ⇒ String
Changelogger::ChangelogGenerator.build_sections-> String. -
.generate(commits, anchor_shas, path: 'CHANGELOG.md', major: 0, minor_start: 1, base_patch: 10) ⇒ String
Changelogger::ChangelogGenerator.generate-> String. -
.render(commits, anchor_shas, major: 0, minor_start: 1, base_patch: 10) ⇒ String
Changelogger::ChangelogGenerator.render-> String.
Class Method Details
.build_sections(versioned) ⇒ String
Changelogger::ChangelogGenerator.build_sections -> String
Build sections from versioned commits.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/changelogger/changelog_generator.rb', line 13 def build_sections(versioned) versioned.map do |(_i, c, v)| lines = [] lines << "## [#{v}] - #{c.date}" lines << '' lines << "- #{c.subject} (#{c.short})" c.body.split("\n").each { |b| lines << " #{b}" } unless c.body.nil? || c.body.empty? lines << '' lines.join("\n") end.join("\n") end |
.generate(commits, anchor_shas, path: 'CHANGELOG.md', major: 0, minor_start: 1, base_patch: 10) ⇒ String
Changelogger::ChangelogGenerator.generate -> String
Generate the changelog file.
63 64 65 66 67 |
# File 'lib/changelogger/changelog_generator.rb', line 63 def generate(commits, anchor_shas, path: 'CHANGELOG.md', major: 0, minor_start: 1, base_patch: 10) content = render(commits, anchor_shas, major: major, minor_start: minor_start, base_patch: base_patch) File.write(path, content) path end |
.render(commits, anchor_shas, major: 0, minor_start: 1, base_patch: 10) ⇒ String
Changelogger::ChangelogGenerator.render -> String
Render the changelog content.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/changelogger/changelog_generator.rb', line 35 def render(commits, anchor_shas, major: 0, minor_start: 1, base_patch: 10) sha_to_idx = commits.map(&:sha) short_to_idx = commits.map(&:short) anchor_indices = anchor_shas.filter_map do |sha| full_idx = sha_to_idx.index(sha) full_idx || short_to_idx.index(sha[0, 7]) end raise 'Need at least 2 valid commits selected' if anchor_indices.size < 2 versioned = Versioner.assign(commits, anchor_indices, major: major, minor_start: minor_start, base_patch: base_patch) header = "## [Unreleased]\n\n" sections = build_sections(versioned) [header, sections].join("\n") end |