Class: Danger::DangerChangelog
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerChangelog
- Defined in:
- lib/changelog/plugin.rb
Overview
Enforce CHANGELOG.md O.C.D. in your projects.
This plugin can, for example, make sure the changes are attributes properly and that they are always terminated with a period.
Instance Attribute Summary collapse
-
#filename ⇒ String
The changelog file name, defaults to ‘CHANGELOG.md`.
Instance Method Summary collapse
-
#changelog_changes? ⇒ boolean
Has the CHANGELOG file been modified?.
-
#check ⇒ void
Run all checks.
-
#have_you_updated_changelog? ⇒ boolean
Have you updated CHANGELOG.md?.
-
#initialize(dangerfile) ⇒ DangerChangelog
constructor
A new instance of DangerChangelog.
-
#is_changelog_format_correct? ⇒ boolean
Is the CHANGELOG.md format correct?.
Constructor Details
#initialize(dangerfile) ⇒ DangerChangelog
Returns a new instance of DangerChangelog.
23 24 25 26 |
# File 'lib/changelog/plugin.rb', line 23 def initialize(dangerfile) @filename = 'CHANGELOG.md' super end |
Instance Attribute Details
#filename ⇒ String
The changelog file name, defaults to ‘CHANGELOG.md`.
21 22 23 |
# File 'lib/changelog/plugin.rb', line 21 def filename @filename end |
Instance Method Details
#changelog_changes? ⇒ boolean
Has the CHANGELOG file been modified?
37 38 39 |
# File 'lib/changelog/plugin.rb', line 37 def changelog_changes? git.modified_files.include?(filename) || git.added_files.include?(filename) end |
#check ⇒ void
This method returns an undefined value.
Run all checks.
30 31 32 33 |
# File 'lib/changelog/plugin.rb', line 30 def check have_you_updated_changelog? is_changelog_format_correct? end |
#have_you_updated_changelog? ⇒ boolean
Have you updated CHANGELOG.md?
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/changelog/plugin.rb', line 43 def have_you_updated_changelog? if changelog_changes? true else markdown <<-MARKDOWN Here's an example of a #{filename} entry: ```markdown #{Danger::Changelog::ChangelogEntryLine.example(github)} ``` MARKDOWN warn "Unless you're refactoring existing code or improving documentation, please update #{filename}.", sticky: false false end end |
#is_changelog_format_correct? ⇒ boolean
Is the CHANGELOG.md format correct?
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/changelog/plugin.rb', line 61 def is_changelog_format_correct? changelog_file = Danger::Changelog::ChangelogFile.new(filename) if changelog_file.exists? changelog_file.bad_lines.each do |line| markdown <<-MARKDOWN ```markdown #{line}``` MARKDOWN end messaging.fail("One of the lines below found in #{filename} doesn't match the expected format. Please make it look like the other lines, pay attention to periods and spaces.", sticky: false) if changelog_file.bad_lines? messaging.fail("Please put back the `#{Danger::Changelog.config.placeholder_line.chomp}` line into #{filename}.", sticky: false) unless changelog_file.your_contribution_here? || !Danger::Changelog.config.placeholder_line? changelog_file.good? else messaging.fail("The #{filename} file does not exist.", sticky: false) false end end |