Class: Danger::Changelog::Parsers::KeepAChangelog

Inherits:
Base
  • Object
show all
Defined in:
lib/changelog/parsers/keep_a_changelog.rb

Instance Attribute Summary

Attributes inherited from Base

#listeners

Instance Method Summary collapse

Methods inherited from Base

#add_listener, #initialize

Constructor Details

This class inherits a constructor from Danger::Changelog::Parsers::Base

Instance Method Details

#bad_line_message(filename) ⇒ Object



5
6
7
8
# File 'lib/changelog/parsers/keep_a_changelog.rb', line 5

def bad_line_message(filename)
  "One of the lines below found in #{filename} doesn't match the " \
  '[expected format](https://keepachangelog.com).'
end

#parse(filename) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/changelog/parsers/keep_a_changelog.rb', line 10

def parse(filename)
  blocks = parse_into_blocks(File.open(filename).each_line)

  if contains_header_block?(blocks.first)
    blocks = blocks[1..-1]
  else
    notify_of_global_failure(
      'The changelog is missing the version header for the Keep A ' \
      'Changelog format. See <https://keepachangelog.com> to see ' \
      'the format of the header'
    )
  end

  blocks.each do |header, *body|
    notify_of_bad_line(header) unless ChangelogHeaderLine.new(header).valid?

    body.each do |line|
      next if approved_section?(line)
      next if markdown_link?(line)
      next if markdown_list_item_or_continuation?(line)

      notify_of_bad_line(line)
    end
  end
end