Class: Danger::Changelog::ChangelogEntryLine

Inherits:
ChangelogLine show all
Defined in:
lib/changelog/changelog_line/changelog_entry_line.rb

Overview

A CHANGELOG.md line represents the change entry.

Instance Attribute Summary

Attributes inherited from ChangelogLine

#line

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ChangelogLine

#initialize, #invalid?

Constructor Details

This class inherits a constructor from Danger::Changelog::ChangelogLine

Class Method Details

.example(github) ⇒ Object

provide an example of a CHANGELOG line based on a commit message



23
24
25
26
27
28
29
30
31
32
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 23

def self.example(github)
  pr_number = github.pr_json['number']
  pr_url = github.pr_json['html_url']
  pr_title = github.pr_title
                   .sub(/[?.!,;]?$/, '')
                   .capitalize
  pr_author = github.pr_author
  pr_author_url = "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 *

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 35

def self.starts_with_star?(line)
  return true if line =~ /^\*\s/
  false
end

.validates_as_changelog_line?(line) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 13

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 with_author_link?(line)
  matched_rules_count >= 2
end

.with_author_link?(line) ⇒ Boolean

checks whether line contains a MARKDOWN link to an author

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 53

def self.with_author_link?(line)
  return true if line =~ %r{\[\@[\w\d\-\_]+\]\(http[s]?:\/\/github\.com\/.*[\w\d\-\_]+[\/]?\)}
  false
end

.with_changelog_description?(line) ⇒ Boolean

checks whether line contains a capitalized Text, treated as a description

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 47

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

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 41

def self.with_pr_link?(line)
  return true if line =~ %r{\[\#\d+\]\(http[s]?:\/\/github\.com\/.*\d+[\/]?\)}
  false
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


7
8
9
10
11
# File 'lib/changelog/changelog_line/changelog_entry_line.rb', line 7

def valid?
  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\-\_]+\).$}
  false
end