Class: Danger::DangerChangelog
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerChangelog
- Extended by:
- Forwardable
- 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 Method Summary collapse
-
#changelog_changes? ⇒ boolean
Has the CHANGELOG file been modified?.
-
#check(parser = Danger::Changelog::Config.format) ⇒ Boolean
Run all checks.
-
#check! ⇒ Boolean
Run all checks.
-
#file_changes? ⇒ boolean
Are any files CHANGELOG cares about modified?.
-
#have_you_updated_changelog? ⇒ boolean
Have you updated CHANGELOG.md?.
-
#is_changelog_format_correct? ⇒ boolean
Is the CHANGELOG.md format correct?.
Instance Method Details
#changelog_changes? ⇒ boolean
Has the CHANGELOG file been modified?
41 42 43 |
# File 'lib/changelog/plugin.rb', line 41 def changelog_changes? git.modified_files.include?(filename) || git.added_files.include?(filename) end |
#check(parser = Danger::Changelog::Config.format) ⇒ Boolean
Run all checks.
33 34 35 36 37 |
# File 'lib/changelog/plugin.rb', line 33 def check(parser = Danger::Changelog::Config.format) warn '[DEPRECATION] `check` is deprecated. Set format with `.format` and use `check!` instead.' config.format = parser check! end |
#check! ⇒ Boolean
Run all checks.
26 27 28 |
# File 'lib/changelog/plugin.rb', line 26 def check! have_you_updated_changelog? && is_changelog_format_correct? end |
#file_changes? ⇒ boolean
Are any files CHANGELOG cares about modified?
47 48 49 50 51 52 53 54 |
# File 'lib/changelog/plugin.rb', line 47 def file_changes? all_files = git.modified_files + git.added_files Danger::Changelog::Config.ignore_files.each do |f| all_files.reject! { |modified_file| f.is_a?(Regexp) ? f.match?(modified_file) : f == modified_file } break if all_files.empty? end all_files.any? end |
#have_you_updated_changelog? ⇒ boolean
Have you updated CHANGELOG.md?
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/changelog/plugin.rb', line 58 def have_you_updated_changelog? if changelog_changes? true elsif file_changes? warn_update_changelog false else true end end |
#is_changelog_format_correct? ⇒ boolean
Is the CHANGELOG.md format correct?
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/changelog/plugin.rb', line 71 def is_changelog_format_correct? parser = Danger::Changelog::Config.parser changelog_file = Danger::Changelog::ChangelogFile.new(filename, parser: parser) if changelog_file.exists? changelog_file.parse changelog_file.bad_lines.each do |line| markdown <<~MARKDOWN ```markdown #{line.map(&:strip).join("\n")} ``` MARKDOWN end messaging.fail(parser.(filename), sticky: false) if changelog_file.bad_lines? changelog_file.global_failures.each do |failure| messaging.fail(failure, sticky: false) end changelog_file.good? else messaging.fail("The #{filename} file does not exist.", sticky: false) false end end |