Class: Kettle::Dev::ChangelogEntryAdder
- Inherits:
-
Object
- Object
- Kettle::Dev::ChangelogEntryAdder
- Defined in:
- lib/kettle/dev/changelog_entry_adder.rb
Constant Summary collapse
- SECTIONS =
%w[Added Changed Deprecated Removed Fixed Security].freeze
Instance Method Summary collapse
-
#initialize(section:, entry:, root: Kettle::Dev::CIHelpers.project_root) ⇒ ChangelogEntryAdder
constructor
A new instance of ChangelogEntryAdder.
- #run ⇒ Object
Constructor Details
#initialize(section:, entry:, root: Kettle::Dev::CIHelpers.project_root) ⇒ ChangelogEntryAdder
Returns a new instance of ChangelogEntryAdder.
8 9 10 11 12 13 |
# File 'lib/kettle/dev/changelog_entry_adder.rb', line 8 def initialize(section:, entry:, root: Kettle::Dev::CIHelpers.project_root) @root = root @section = section.to_s @entry = normalize_entry(entry) @changelog_path = File.join(@root, "CHANGELOG.md") end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kettle/dev/changelog_entry_adder.rb', line 15 def run raise Error, "unsupported changelog section #{@section.inspect}" unless SECTIONS.include?(@section) raise Error, "missing CHANGELOG.md in #{Kettle::Dev.display_path(@root)}" unless File.file?(@changelog_path) require_markly_crispr! source = File.read(@changelog_path) context = Ast::Crispr::Markdown::Markly.document_context(content: source, source_label: @changelog_path) sections = context.structural_owners(owner_scope: :heading_sections) unreleased = find_unreleased_heading!(sections) target = find_unreleased_section!(sections, unreleased) slice = target_slice(source, target) return :unchanged if entry_present?(slice) updated = insert_entry(source, target) File.write(@changelog_path, updated) :changed end |