Class: Danger::Changelog::ChangelogHeaderLine
- Inherits:
-
ChangelogLine
- Object
- ChangelogLine
- Danger::Changelog::ChangelogHeaderLine
- Defined in:
- lib/changelog/changelog_line/changelog_header_line.rb
Overview
A CHANGELOG.md line represents the version header.
Constant Summary collapse
- OPEN_PARENS =
/[\(\[\{]?/.freeze
- CLOSE_PARENS =
/[\)\]\}]?/.freeze
- HASHES =
/\#{1,4}/.freeze
- SEMVER =
/(?<semver>(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/.freeze
- ISO8601_DATE =
%r{(?<date>([0-9]{4})[-/]?(1[0-2]|0?[1-9])[-/]+(3[01]|0?[1-9]|[12][0-9]))}.freeze
Constants inherited from ChangelogLine
Danger::Changelog::ChangelogLine::DELIMITER, Danger::Changelog::ChangelogLine::NON_DELIMITERS, Danger::Changelog::ChangelogLine::PAIRED
Instance Attribute Summary
Attributes inherited from ChangelogLine
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from ChangelogLine
#balanced?, #initialize, #invalid?
Constructor Details
This class inherits a constructor from Danger::Changelog::ChangelogLine
Class Method Details
.validates_as_changelog_line?(line) ⇒ Boolean
22 23 24 25 26 |
# File 'lib/changelog/changelog_line/changelog_header_line.rb', line 22 def self.validates_as_changelog_line?(line) return true if line =~ /^#{HASHES}\s.+/ false end |
Instance Method Details
#valid? ⇒ Boolean
12 13 14 15 16 17 18 19 20 |
# File 'lib/changelog/changelog_line/changelog_header_line.rb', line 12 def valid? stripped_line = line.strip m = stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}[\w\s\:]*#{CLOSE_PARENS}$/) # title m ||= stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}#{SEMVER}#{CLOSE_PARENS}$/) # semver only m ||= stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}#{SEMVER}#{CLOSE_PARENS}[\s\-]+#{OPEN_PARENS}(#{ISO8601_DATE}|\w*)#{CLOSE_PARENS}$/) # semver and iso 8601 date or next version description !m.nil? && balanced?(stripped_line) end |