Class: Danger::Changelog::ChangelogEntryLine
- Inherits:
-
ChangelogLine
- Object
- ChangelogLine
- Danger::Changelog::ChangelogEntryLine
- Defined in:
- lib/changelog/changelog_line/changelog_entry_line.rb
Overview
A CHANGELOG.md line represents the change entry.
Constant Summary
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
-
.ends_with_period?(line) ⇒ Boolean
checks whether line ends with a period.
-
.ends_with_space?(line) ⇒ Boolean
checks whether line ends with a space.
-
.example(github) ⇒ Object
provide an example of a CHANGELOG line based on a commit message.
-
.starts_with_star?(line) ⇒ Boolean
checks whether line starts with *.
- .validates_as_changelog_line?(line) ⇒ Boolean
-
.with_author_link?(line) ⇒ Boolean
checks whether line contains a MARKDOWN link to an author.
-
.with_changelog_description?(line) ⇒ Boolean
checks whether line contains a capitalized Text, treated as a description.
-
.with_pr_link?(line) ⇒ Boolean
checks whether line contains a MARKDOWN link to a PR.
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
.ends_with_period?(line) ⇒ Boolean
checks whether line ends with a period
67 68 69 70 71 |
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 67 def self.ends_with_period?(line) return true if line =~ /\.\n$/ false end |
.ends_with_space?(line) ⇒ Boolean
checks whether line ends with a space
60 61 62 63 64 |
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 60 def self.ends_with_space?(line) return true if line =~ /[[:blank:]]\n$/ false end |
.example(github) ⇒ Object
provide an example of a CHANGELOG line based on a commit message
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 41 def self.example(github) pr_number = github.pr_json['number'] pr_url = github.pr_json['html_url'] pr_title = github.pr_title .sub(/[?.!,;]?$/, '') .capitalize = github. = "https://github.com/#{github.pr_author}" "* [##{pr_number}](#{pr_url}): #{pr_title} - [@#{pr_author}](#{pr_author_url})." end |
.starts_with_star?(line) ⇒ Boolean
checks whether line starts with *
53 54 55 56 57 |
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 53 def self.starts_with_star?(line) return true if line =~ /^\*\s/ false end |
.validates_as_changelog_line?(line) ⇒ Boolean
31 32 33 34 35 36 37 38 |
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 31 def self.validates_as_changelog_line?(line) matched_rules_count = 0 matched_rules_count += 1 if starts_with_star?(line) matched_rules_count += 1 if with_pr_link?(line) matched_rules_count += 1 if with_changelog_description?(line) matched_rules_count += 1 if (line) matched_rules_count >= 2 end |
.with_author_link?(line) ⇒ Boolean
checks whether line contains a MARKDOWN link to an author
88 89 90 91 92 |
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 88 def self.(line) return true if line =~ %r{\[@[\w\d\-_]+\]\(https?://github\.com/.*[\w\d\-_]+/?\)} false end |
.with_changelog_description?(line) ⇒ Boolean
checks whether line contains a capitalized Text, treated as a description
81 82 83 84 85 |
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 81 def self.with_changelog_description?(line) return true if line =~ /[`[:upper:]].*/ false end |
.with_pr_link?(line) ⇒ Boolean
checks whether line contains a MARKDOWN link to a PR
74 75 76 77 78 |
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 74 def self.with_pr_link?(line) return true if line =~ %r{\[\#\d+\]\(https?://github\.com/.*\d+/?\)} false end |
Instance Method Details
#valid? ⇒ Boolean
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 7 def valid? return validation_result.valid? if validation_result @validation_result = Parsers::ValidationResult.new validation_result.error! 'too many parenthesis' unless balanced?(line) return false if validation_result.invalid? return true if line =~ %r{^\*\s[`[:upper:]].*[^.,] - \[@[\w\d\-_]+\]\(https://github\.com/.*[\w\d\-_]+\).$} return true if line =~ %r{^\*\s\[\#\d+\]\(https://github\.com/.*\d+\): [`[:upper:]].*[^.,] - \[@[\w\d\-_]+\]\(https://github\.com/.*[\w\d\-_]+\).$} validation_result.error! 'does not start with a star' unless ChangelogEntryLine.starts_with_star?(line) validation_result.error! 'does not include a pull request link' unless ChangelogEntryLine.with_pr_link?(line) validation_result.error! 'does not have a description' unless ChangelogEntryLine.with_changelog_description?(line) validation_result.error! 'does not include an author link' unless ChangelogEntryLine.(line) validation_result.error! 'has an extra trailing space' if ChangelogEntryLine.ends_with_space?(line) validation_result.error! 'is missing a period at the end of the line' unless ChangelogEntryLine.ends_with_period?(line) validation_result.error! 'has an extra period or comma at the end of the description' if line =~ %r{^\*\s[`[:upper:]].*[.,] - \[@[\w\d\-_]+\]\(https://github\.com/.*[\w\d\-_]+\).$} || line =~ %r{^\*\s\[\#\d+\]\(https://github\.com/.*\d+\): [`[:upper:]].*[.,] - \[@[\w\d\-_]+\]\(https://github\.com/.*[\w\d\-_]+\).$} false end |