danger-changelog 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -0
  3. data/.rubocop_todo.yml +1 -39
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +6 -0
  6. data/Dangerfile +1 -0
  7. data/Gemfile +14 -0
  8. data/LICENSE.txt +1 -1
  9. data/README.md +19 -2
  10. data/danger-changelog.gemspec +0 -11
  11. data/lib/changelog/changelog_file.rb +5 -3
  12. data/lib/changelog/changelog_line/changelog_entry_line.rb +31 -1
  13. data/lib/changelog/changelog_line/changelog_line.rb +2 -0
  14. data/lib/changelog/changelog_line/changelog_line_parser.rb +2 -2
  15. data/lib/changelog/config.rb +4 -2
  16. data/lib/changelog/gem_version.rb +1 -1
  17. data/lib/changelog/parsers.rb +1 -0
  18. data/lib/changelog/parsers/base.rb +2 -2
  19. data/lib/changelog/parsers/intridea_format.rb +2 -1
  20. data/lib/changelog/parsers/keep_a_changelog.rb +2 -2
  21. data/lib/changelog/parsers/validation_result.rb +31 -0
  22. data/lib/changelog/plugin.rb +10 -9
  23. data/spec/changelog_spec.rb +88 -254
  24. data/spec/config_spec.rb +11 -3
  25. data/spec/{changelog_entry_line_spec.rb → intridea/changelog_entry_line_spec.rb} +1 -1
  26. data/spec/intridea/changelog_file_spec.rb +120 -0
  27. data/spec/{changelog_header_line_spec.rb → intridea/changelog_header_line_spec.rb} +1 -1
  28. data/spec/{changelog_line_parser_spec.rb → intridea/changelog_line_parser_spec.rb} +1 -1
  29. data/spec/{changelog_placeholder_line_spec.rb → intridea/changelog_placeholder_line_spec.rb} +5 -3
  30. data/spec/intridea/changelog_spec.rb +150 -0
  31. data/spec/{fixtures/changelogs → intridea/fixtures}/customized.md +0 -0
  32. data/spec/{fixtures/changelogs → intridea/fixtures}/dates.md +0 -0
  33. data/spec/intridea/fixtures/extra_trailing_space.md +3 -0
  34. data/spec/{fixtures/changelogs → intridea/fixtures}/imbalanced.md +0 -0
  35. data/spec/{fixtures/changelogs → intridea/fixtures}/lines.md +0 -0
  36. data/spec/{fixtures/changelogs → intridea/fixtures}/minimal.md +0 -0
  37. data/spec/{fixtures/changelogs → intridea/fixtures}/missing_your_contribution_here.md +0 -0
  38. data/spec/{fixtures/changelogs → intridea/fixtures}/semver.md +0 -0
  39. data/spec/keep_a_changelog/changelog_spec.rb +84 -0
  40. data/spec/{fixtures/changelogs/keep_a_changelog.md → keep_a_changelog/fixtures/complete.md} +0 -0
  41. data/spec/keep_a_changelog/fixtures/invalid_line.md +23 -0
  42. data/spec/keep_a_changelog/fixtures/lines_with_links.md +14 -0
  43. data/spec/keep_a_changelog/fixtures/missing_a_version_header.md +20 -0
  44. data/spec/plugin_spec.rb +10 -0
  45. metadata +43 -168
  46. data/spec/changelog_file_spec.rb +0 -110
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dda179f0ffebc733fa943723d9b16c6db3720beab1e5c43ee57746cb6f20577
4
- data.tar.gz: b1797cb0bd4d0eef3aead4e9a0409c057205d995efc3d56f200f106055900fe9
3
+ metadata.gz: 11af2b5d7acdef3916a5d3804da6d6b3cb0b881132e5cf3fadabd562823987a5
4
+ data.tar.gz: 4dd589ec527ba8cc88326749593652e296ee908b982674a3402f7b521d74dfb3
5
5
  SHA512:
6
- metadata.gz: 897e573a11db0076fd9c7bb745b5c8f39d47d94f4d2b69b298a1565cade582a9aaadf17d0667b48a1d9569bc0566558000e9baaec7bf9a6054d4818ed5475f1d
7
- data.tar.gz: c92f5ae706ada26bb3006adffae2df8aef0b79de05d1f6464257918004511a7bdc926a2430c6386d32961df4011c3e48b29162dea763a98865087e6df8fd4375
6
+ metadata.gz: c2ea9affac3dda11f80eb7622c2e405efc0508f257e6afac328312a7ab238df755975c285b73e23c9d1cd77bdf7487f02b581d0b161c329473f99dfbb8bdece7
7
+ data.tar.gz: 927698782c171ac595a8fde12380ac7cbe8097d18018060d3821304b0ab0dd2d26baba9af561c8b275cc8423d1f53ba75b4deba072d2f21a5245a5a5689c9d8a
@@ -14,4 +14,14 @@ Metrics:
14
14
  Metrics/LineLength:
15
15
  Max: 256
16
16
 
17
+ Style/FrozenStringLiteralComment:
18
+ Enabled: false
19
+
20
+ Naming/PredicateName:
21
+ Enabled: true
22
+ NameWhitelist:
23
+ - is_a?
24
+ - have_you_updated_changelog?
25
+ - is_changelog_format_correct?
26
+
17
27
  inherit_from: .rubocop_todo.yml
@@ -1,45 +1,7 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-07-28 16:00:45 -0400 using RuboCop version 0.61.1.
3
+ # on 2020-05-08 17:23:39 -0400 using RuboCop version 0.73.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 2
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: EnforcedStyle.
12
- # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
13
- Layout/IndentHeredoc:
14
- Exclude:
15
- - 'lib/changelog/plugin.rb'
16
-
17
- # Offense count: 1
18
- # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
19
- Lint/UselessAccessModifier:
20
- Exclude:
21
- - 'lib/changelog/changelog_line/changelog_line_parser.rb'
22
-
23
- # Offense count: 2
24
- # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
25
- # NamePrefix: is_, has_, have_
26
- # NamePrefixBlacklist: is_, has_, have_
27
- # NameWhitelist: is_a?
28
- # MethodDefinitionMacros: define_method, define_singleton_method
29
- Naming/PredicateName:
30
- Exclude:
31
- - 'spec/**/*'
32
- - 'lib/changelog/plugin.rb'
33
-
34
- # Offense count: 1
35
- Style/DoubleNegation:
36
- Exclude:
37
- - 'lib/changelog/changelog_file.rb'
38
-
39
- # Offense count: 1
40
- # Cop supports --auto-correct.
41
- # Configuration parameters: EnforcedStyle.
42
- # SupportedStyles: module_function, extend_self
43
- Style/ModuleFunction:
44
- Exclude:
45
- - 'lib/changelog/config.rb'
@@ -5,7 +5,7 @@ cache:
5
5
  - bundle
6
6
 
7
7
  rvm:
8
- - 2.3.1
8
+ - 2.6.2
9
9
 
10
10
  before_script:
11
11
  - bundle exec danger
@@ -1,5 +1,11 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.6.1 (2020/05/08)
4
+
5
+ * [#33](https://github.com/dblock/danger-changelog/issues/33): Attempt to point out known problems in Intridea format - [@dblock](https://github.com/dblock).
6
+ * [#51](https://github.com/dblock/danger-changelog/pull/51): Allow markdown links in keep-a-changelog lines - [@dblock](https://github.com/dblock).
7
+ * [#50](https://github.com/dblock/danger-changelog/pull/50): Added TOC to README - [@dblock](https://github.com/dblock).
8
+
3
9
  ### 0.6.0 (2019/07/28)
4
10
 
5
11
  * [#47](https://github.com/dblock/danger-changelog/pull/47): Configure `Config#placeholder_line` at plugin level - [@dblock](https://github.com/dblock).
data/Dangerfile CHANGED
@@ -1,3 +1,4 @@
1
1
  # danger.systems
2
2
 
3
+ toc.check!
3
4
  changelog.check!
data/Gemfile CHANGED
@@ -1,3 +1,17 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ group :development, :test do
6
+ gem 'activesupport'
7
+ gem 'bundler'
8
+ gem 'danger-toc', '~> 0.2.0'
9
+ gem 'guard', '~> 2.14'
10
+ gem 'guard-rspec', '~> 4.7'
11
+ gem 'listen', '3.0.7'
12
+ gem 'pry'
13
+ gem 'rake', '~> 10.0'
14
+ gem 'rspec', '~> 3.4'
15
+ gem 'rubocop', '~> 0.73.0'
16
+ gem 'yard', '~> 0.9.11'
17
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2016 Daniel Doubrovkine <dblock@dblock.org>
1
+ Copyright (c) 2016-2019 Daniel Doubrovkine <dblock@dblock.org>
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # danger-changelog
1
+ # Danger-Changelog
2
2
 
3
3
  A plugin for [danger.systems](http://danger.systems) that obsessive-compulsively lints your project’s `CHANGELOG.md`.
4
4
  It can make sure, for example, that changes are attributed properly, have a valid version number, a date in the ISO8601 format, balanced parenthesis and brackets, and that they’re always terminated with a period.
@@ -6,6 +6,23 @@ It can make sure, for example, that changes are attributed properly, have a vali
6
6
  [![Gem Version](https://badge.fury.io/rb/danger-changelog.svg)](https://badge.fury.io/rb/danger-changelog)
7
7
  [![Build Status](https://travis-ci.org/dblock/danger-changelog.svg?branch=master)](https://travis-ci.org/dblock/danger-changelog)
8
8
 
9
+ # Table of Contents
10
+
11
+ - [What’s a correctly formatted CHANGELOG file?](#whats-a-correctly-formatted-changelog-file)
12
+ - [Installation](#installation)
13
+ - [Usage](#usage)
14
+ - [Configuration](#configuration)
15
+ - [changelog.filename](#changelogfilename)
16
+ - [changelog.format](#changelogformat)
17
+ - [changelog.placeholder_line](#changelogplaceholder_line)
18
+ - [changelog.ignore_files](#changelogignore_files)
19
+ - [Checks](#checks)
20
+ - [changelog.check!](#changelogcheck)
21
+ - [changelog.have_you_updated_changelog?](#changeloghave_you_updated_changelog)
22
+ - [changelog.is_changelog_format_correct?](#changelogis_changelog_format_correct)
23
+ - [Contributing](#contributing)
24
+ - [Copyright](#copyright)
25
+
9
26
  ## What's a correctly formatted CHANGELOG file?
10
27
 
11
28
  By design, `danger-changelog` is quite strict with what it allows as a valid changelog file, using the [Intridea style](doc/intridea.md), [used by this library itself](CHANGELOG.md). It also supports the [Keep a Changelog](doc/keep_a_changelog.md) format.
@@ -90,6 +107,6 @@ See [CONTRIBUTING](CONTRIBUTING.md).
90
107
 
91
108
  ## Copyright
92
109
 
93
- Copyright (c) Daniel Doubrovkine, 2016
110
+ Copyright (c) Daniel Doubrovkine, 2016-2019
94
111
 
95
112
  MIT License, see [LICENSE](LICENSE.txt) for details.
@@ -18,15 +18,4 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
21
-
22
- spec.add_development_dependency 'activesupport'
23
- spec.add_development_dependency 'bundler'
24
- spec.add_development_dependency 'guard', '~> 2.14'
25
- spec.add_development_dependency 'guard-rspec', '~> 4.7'
26
- spec.add_development_dependency 'listen', '3.0.7'
27
- spec.add_development_dependency 'pry'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rspec', '~> 3.4'
30
- spec.add_development_dependency 'rubocop', '~> 0.61.1'
31
- spec.add_development_dependency 'yard', '~> 0.9.11'
32
21
  end
@@ -14,8 +14,10 @@ module Danger
14
14
  parser.add_listener(self)
15
15
  end
16
16
 
17
- def add_bad_line(line)
18
- @bad_lines << line
17
+ def add_bad_line(line, detail = nil)
18
+ return unless line || detail
19
+
20
+ @bad_lines << [line, detail].compact
19
21
  end
20
22
 
21
23
  def add_global_failure(message)
@@ -38,7 +40,7 @@ module Danger
38
40
  end
39
41
 
40
42
  def exists?
41
- !!@exists
43
+ @exists
42
44
  end
43
45
 
44
46
  def bad?
@@ -5,10 +5,26 @@ module Danger
5
5
  # A CHANGELOG.md line represents the change entry.
6
6
  class ChangelogEntryLine < ChangelogLine
7
7
  def valid?
8
- return false unless balanced?(line)
8
+ return validation_result.valid? if validation_result
9
+
10
+ @validation_result = Parsers::ValidationResult.new
11
+
12
+ validation_result.error! 'too many parenthesis' unless balanced?(line)
13
+ return false if validation_result.invalid?
14
+
9
15
  return true if line =~ %r{^\*\s[\`[:upper:]].*[^.,] \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\).$}
10
16
  return true if line =~ %r{^\*\s\[\#\d+\]\(https:\/\/github\.com\/.*\d+\)\: [\`[:upper:]].*[^.,] \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\).$}
11
17
 
18
+ validation_result.error! 'does not start with a star' unless ChangelogEntryLine.starts_with_star?(line)
19
+ validation_result.error! 'does not include a pull request link' unless ChangelogEntryLine.with_pr_link?(line)
20
+ validation_result.error! 'does not have a description' unless ChangelogEntryLine.with_changelog_description?(line)
21
+ validation_result.error! 'does not include an author link' unless ChangelogEntryLine.with_author_link?(line)
22
+ validation_result.error! 'has an extra trailing space' if ChangelogEntryLine.ends_with_space?(line)
23
+ validation_result.error! 'is missing a period at the end of the line' unless ChangelogEntryLine.ends_with_period?(line)
24
+ validation_result.error! 'has an extra period or comma at the end of the description' if
25
+ line =~ %r{^\*\s[\`[:upper:]].*[.,] \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\).$} ||
26
+ line =~ %r{^\*\s\[\#\d+\]\(https:\/\/github\.com\/.*\d+\)\: [\`[:upper:]].*[.,] \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\).$}
27
+
12
28
  false
13
29
  end
14
30
 
@@ -40,6 +56,20 @@ module Danger
40
56
  false
41
57
  end
42
58
 
59
+ # checks whether line ends with a space
60
+ def self.ends_with_space?(line)
61
+ return true if line =~ /[[:blank:]]\n$/
62
+
63
+ false
64
+ end
65
+
66
+ # checks whether line ends with a period
67
+ def self.ends_with_period?(line)
68
+ return true if line =~ /\.\n$/
69
+
70
+ false
71
+ end
72
+
43
73
  # checks whether line contains a MARKDOWN link to a PR
44
74
  def self.with_pr_link?(line)
45
75
  return true if line =~ %r{\[\#\d+\]\(http[s]?:\/\/github\.com\/.*\d+[\/]?\)}
@@ -7,9 +7,11 @@ module Danger
7
7
  DELIMITER = /[(){}\[\]]/.freeze
8
8
 
9
9
  attr_accessor :line
10
+ attr_accessor :validation_result
10
11
 
11
12
  def initialize(line)
12
13
  self.line = line
14
+ self.validation_result = nil
13
15
  end
14
16
 
15
17
  # Match the line with the validation rules
@@ -16,12 +16,12 @@ module Danger
16
16
  changelog_line_class.new(line)
17
17
  end
18
18
 
19
- private_class_method
20
-
21
19
  def self.available_changelog_lines
22
20
  # Order is important
23
21
  [ChangelogPlaceholderLine, ChangelogEntryLine, ChangelogHeaderLine]
24
22
  end
23
+
24
+ private_class_method :available_changelog_lines
25
25
  end
26
26
  end
27
27
  end
@@ -1,7 +1,7 @@
1
1
  module Danger
2
2
  module Changelog
3
3
  module Config
4
- extend self
4
+ module_function
5
5
 
6
6
  ATTRIBUTES = %i[
7
7
  placeholder_line
@@ -14,7 +14,9 @@ module Danger
14
14
 
15
15
  DELEGATORS = ATTRIBUTES + ACCESSORS
16
16
 
17
- attr_accessor(*Config::ATTRIBUTES)
17
+ class << self
18
+ attr_accessor(*Config::ATTRIBUTES)
19
+ end
18
20
 
19
21
  def placeholder_line=(value)
20
22
  if value
@@ -1,3 +1,3 @@
1
1
  module Changelog
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.6.1'.freeze
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'changelog/parsers/base'
2
+ require 'changelog/parsers/validation_result'
2
3
  require 'changelog/parsers/intridea_format'
3
4
  require 'changelog/parsers/keep_a_changelog'
4
5
 
@@ -14,8 +14,8 @@ module Danger
14
14
 
15
15
  private
16
16
 
17
- def notify_of_bad_line(message)
18
- listeners.each { |changelog| changelog.add_bad_line(message) }
17
+ def notify_of_bad_line(message, detail = nil)
18
+ listeners.each { |changelog| changelog.add_bad_line(message, detail) }
19
19
  end
20
20
 
21
21
  def notify_of_global_failure(message)
@@ -18,7 +18,8 @@ module Danger
18
18
  changelog_line = ChangelogLineParser.parse(line)
19
19
 
20
20
  if changelog_line.nil? || changelog_line.invalid?
21
- notify_of_bad_line line
21
+ detail = changelog_line.validation_result.to_s if changelog_line.validation_result&.invalid?
22
+ notify_of_bad_line line, detail
22
23
  next
23
24
  end
24
25
 
@@ -16,7 +16,7 @@ module Danger
16
16
  notify_of_global_failure(
17
17
  'The changelog is missing the version header for the Keep A ' \
18
18
  'Changelog format. See <https://keepachangelog.com> to see ' \
19
- 'the format of the header'
19
+ 'the format of the header.'
20
20
  )
21
21
  end
22
22
 
@@ -42,7 +42,7 @@ module Danger
42
42
  lines.each do |line|
43
43
  line = line.chomp
44
44
 
45
- if /##?[^#]/.match?(line)
45
+ if /^##?[^#]/.match?(line)
46
46
  blocks << block.dup unless block.empty?
47
47
  block.clear
48
48
  end
@@ -0,0 +1,31 @@
1
+ module Danger
2
+ module Changelog
3
+ module Parsers
4
+ class ValidationResult
5
+ def initialize
6
+ @errors = []
7
+ end
8
+
9
+ attr_reader :errors
10
+
11
+ def valid?
12
+ errors.empty?
13
+ end
14
+
15
+ def invalid?
16
+ !valid?
17
+ end
18
+
19
+ def error!(message)
20
+ errors << message
21
+ end
22
+
23
+ def to_s
24
+ return nil if valid?
25
+
26
+ errors.join(', ')
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -75,15 +75,16 @@ module Danger
75
75
  if changelog_file.exists?
76
76
  changelog_file.parse
77
77
  changelog_file.bad_lines.each do |line|
78
- markdown <<-MARKDOWN
79
- ```markdown
80
- #{line}```
78
+ markdown <<~MARKDOWN
79
+ ```markdown
80
+ #{line.map(&:strip).join("\n")}
81
+ ```
81
82
  MARKDOWN
82
83
  end
83
84
  messaging.fail(parser.bad_line_message(filename), sticky: false) if changelog_file.bad_lines?
84
85
 
85
86
  changelog_file.global_failures.each do |failure|
86
- messaging.fail(failure, sticy: false)
87
+ messaging.fail(failure, sticky: false)
87
88
  end
88
89
 
89
90
  changelog_file.good?
@@ -96,12 +97,12 @@ module Danger
96
97
  private
97
98
 
98
99
  def warn_update_changelog
99
- markdown <<-MARKDOWN
100
- Here's an example of a #{filename} entry:
100
+ markdown <<~MARKDOWN
101
+ Here's an example of a #{filename} entry:
101
102
 
102
- ```markdown
103
- #{Danger::Changelog::ChangelogEntryLine.example(github)}
104
- ```
103
+ ```markdown
104
+ #{Danger::Changelog::ChangelogEntryLine.example(github)}
105
+ ```
105
106
  MARKDOWN
106
107
  warn "Unless you're refactoring existing code or improving documentation, please update #{filename}.", sticky: false
107
108
  end
@@ -1,312 +1,146 @@
1
- require File.expand_path('spec_helper', __dir__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Danger::Changelog do
4
- it 'is a Danger plugin' do
5
- expect(Danger::DangerChangelog.new(nil)).to be_a Danger::Plugin
6
- end
7
-
8
- describe 'with Dangerfile' do
9
- let(:filename) { File.expand_path('fixtures/changelogs/minimal.md', __dir__) }
10
- let(:dangerfile) { testing_dangerfile }
11
- let(:changelog) do
12
- dangerfile.changelog.filename = filename
13
- dangerfile.changelog
14
- end
15
- let(:status_report) { changelog.status_report }
16
-
17
- describe 'config' do
18
- it 'placeholder_line' do
19
- expect(changelog.placeholder_line).to eq "* Your contribution here.\n"
20
- end
4
+ let(:dangerfile) { testing_dangerfile }
5
+ let(:changelog) { dangerfile.changelog }
6
+ let(:status_report) { changelog.status_report }
7
+
8
+ describe 'in a PR' do
9
+ before do
10
+ changelog.env.request_source.pr_json = {
11
+ 'number' => 123,
12
+ 'title' => 'being dangerous',
13
+ 'html_url' => 'https://github.com/dblock/danger-changelog/pull/123',
14
+ 'user' => {
15
+ 'login' => 'dblock'
16
+ }
17
+ }
21
18
  end
22
19
 
23
- describe 'in a PR' do
24
- before do
25
- # typical PR JSON looks like https://raw.githubusercontent.com/danger/danger/bffc246a11dac883d76fc6636319bd6c2acd58a3/spec/fixtures/pr_response.json
26
- changelog.env.request_source.pr_json = {
27
- 'number' => 123,
28
- 'title' => 'being dangerous',
29
- 'html_url' => 'https://github.com/dblock/danger-changelog/pull/123',
30
- 'user' => {
31
- 'login' => 'dblock'
32
- }
33
- }
20
+ context 'check!' do
21
+ subject do
22
+ changelog.check!
34
23
  end
35
24
 
36
- context 'have_you_updated_changelog?' do
37
- subject do
38
- changelog.have_you_updated_changelog?
25
+ context 'without CHANGELOG changes' do
26
+ before do
27
+ allow(changelog.git).to receive(:modified_files).and_return(['some-file.txt'])
28
+ allow(changelog.git).to receive(:added_files).and_return(['some-file.txt'])
39
29
  end
40
30
 
41
- context 'without CHANGELOG changes' do
42
- context 'when something was modified' do
43
- before do
44
- allow(changelog.git).to receive(:modified_files).and_return(['some-file.txt'])
45
- allow(changelog.git).to receive(:added_files).and_return(['another-file.txt'])
46
- end
47
-
48
- it 'complains when no CHANGELOG can be found' do
49
- expect(subject).to be false
50
- expect(status_report[:errors]).to eq []
51
- expect(status_report[:warnings]).to eq ["Unless you're refactoring existing code or improving documentation, please update #{filename}."]
52
- expect(status_report[:markdowns].map(&:message)).to eq ["Here's an example of a #{filename} entry:\n\n```markdown\n* [#123](https://github.com/dblock/danger-changelog/pull/123): Being dangerous - [@dblock](https://github.com/dblock).\n```\n"]
53
- end
54
- end
55
-
56
- context 'with a README.md' do
57
- before do
58
- allow(changelog.git).to receive(:modified_files).and_return(['README.md'])
59
- allow(changelog.git).to receive(:added_files).and_return([])
60
- end
61
- it 'has no complaints' do
62
- expect(subject).to be true
63
- expect(status_report[:errors]).to eq []
64
- expect(status_report[:warnings]).to eq []
65
- expect(status_report[:markdowns]).to eq []
66
- end
67
- end
68
-
69
- context 'with files being ignored' do
70
- context 'name' do
71
- before do
72
- changelog.ignore_files = ['WHATEVER.md']
73
- allow(changelog.git).to receive(:modified_files).and_return(['WHATEVER.md'])
74
- allow(changelog.git).to receive(:added_files).and_return([])
75
- end
76
-
77
- it 'has no complaints' do
78
- expect(subject).to be true
79
- expect(status_report[:errors]).to eq []
80
- expect(status_report[:warnings]).to eq []
81
- expect(status_report[:markdowns]).to eq []
82
- end
83
- end
84
- context 'mixed' do
85
- before do
86
- changelog.ignore_files = ['WHATEVER.md', /\.txt$/]
87
- allow(changelog.git).to receive(:modified_files).and_return(['WHATEVER.md'])
88
- allow(changelog.git).to receive(:added_files).and_return(['one.txt', 'two.txt'])
89
- end
90
-
91
- it 'has no complaints' do
92
- expect(subject).to be true
93
- expect(status_report[:errors]).to eq []
94
- expect(status_report[:warnings]).to eq []
95
- expect(status_report[:markdowns]).to eq []
96
- end
97
- end
98
- end
31
+ it 'complains when no CHANGELOG can be found' do
32
+ expect(subject).to be false
33
+ expect(status_report[:errors]).to eq []
34
+ expect(status_report[:warnings]).to eq ["Unless you're refactoring existing code or improving documentation, please update CHANGELOG.md."]
35
+ expect(status_report[:markdowns].map(&:message)).to eq ["Here's an example of a CHANGELOG.md entry:\n\n```markdown\n* [#123](https://github.com/dblock/danger-changelog/pull/123): Being dangerous - [@dblock](https://github.com/dblock).\n```\n"]
99
36
  end
37
+ end
100
38
 
101
- context 'with a new CHANGELOG' do
102
- before do
103
- allow(changelog.git).to receive(:modified_files).and_return([])
104
- allow(changelog.git).to receive(:added_files).and_return([filename])
105
- end
106
-
107
- it 'has no complaints' do
108
- expect(subject).to be true
109
- expect(status_report[:errors]).to eq []
110
- expect(status_report[:warnings]).to eq []
111
- expect(status_report[:markdowns]).to eq []
112
- end
39
+ context 'with CHANGELOG changes' do
40
+ before do
41
+ allow(changelog.git).to receive(:modified_files).and_return([changelog.filename])
42
+ allow(changelog.git).to receive(:added_files).and_return([])
113
43
  end
114
44
 
115
- context 'with CHANGELOG changes' do
116
- before do
117
- allow(changelog.git).to receive(:modified_files).and_return([filename])
118
- allow(changelog.git).to receive(:added_files).and_return([])
119
- end
120
-
121
- it 'has no complaints' do
122
- expect(subject).to be true
123
- expect(status_report[:errors]).to eq []
124
- expect(status_report[:warnings]).to eq []
125
- expect(status_report[:markdowns]).to eq []
126
- end
45
+ it 'has no complaints' do
46
+ expect(subject).to be true
47
+ expect(status_report[:errors]).to eq []
48
+ expect(status_report[:warnings]).to eq []
49
+ expect(status_report[:markdowns]).to eq []
127
50
  end
128
51
  end
52
+ end
129
53
 
130
- context 'is_changelog_format_correct?' do
131
- subject do
132
- changelog.format = Danger::Changelog::Parsers.default_format
133
- changelog.is_changelog_format_correct?
134
- end
54
+ context 'have_you_updated_changelog?' do
55
+ subject do
56
+ changelog.have_you_updated_changelog?
57
+ end
135
58
 
136
- context 'without a CHANGELOG file' do
137
- let(:filename) { 'does-not-exist' }
138
- it 'complains' do
59
+ context 'without CHANGELOG changes' do
60
+ context 'when something was modified' do
61
+ before do
62
+ allow(changelog.git).to receive(:modified_files).and_return(['some-file.txt'])
63
+ allow(changelog.git).to receive(:added_files).and_return(['another-file.txt'])
64
+ end
65
+
66
+ it 'complains when no CHANGELOG can be found' do
139
67
  expect(subject).to be false
140
- expect(status_report[:errors]).to eq ['The does-not-exist file does not exist.']
68
+ expect(status_report[:errors]).to eq []
69
+ expect(status_report[:warnings]).to eq ["Unless you're refactoring existing code or improving documentation, please update #{changelog.filename}."]
70
+ expect(status_report[:markdowns].map(&:message)).to eq ["Here's an example of a #{changelog.filename} entry:\n\n```markdown\n* [#123](https://github.com/dblock/danger-changelog/pull/123): Being dangerous - [@dblock](https://github.com/dblock).\n```\n"]
141
71
  end
142
72
  end
143
73
 
144
- context 'with CHANGELOG changes' do
74
+ context 'with a README.md' do
145
75
  before do
146
- allow(changelog.git).to receive(:modified_files).and_return([filename])
76
+ allow(changelog.git).to receive(:modified_files).and_return(['README.md'])
147
77
  allow(changelog.git).to receive(:added_files).and_return([])
148
78
  end
149
-
150
79
  it 'has no complaints' do
151
80
  expect(subject).to be true
152
81
  expect(status_report[:errors]).to eq []
153
82
  expect(status_report[:warnings]).to eq []
154
83
  expect(status_report[:markdowns]).to eq []
155
84
  end
85
+ end
156
86
 
157
- context 'customized' do
87
+ context 'with files being ignored' do
88
+ context 'name' do
158
89
  before do
159
- changelog.placeholder_line = "* Nothing yet.\n"
90
+ changelog.ignore_files = ['WHATEVER.md']
91
+ allow(changelog.git).to receive(:modified_files).and_return(['WHATEVER.md'])
92
+ allow(changelog.git).to receive(:added_files).and_return([])
160
93
  end
161
94
 
162
- let(:filename) { File.expand_path('fixtures/changelogs/customized.md', __dir__) }
163
- it 'is ok' do
95
+ it 'has no complaints' do
164
96
  expect(subject).to be true
165
97
  expect(status_report[:errors]).to eq []
166
98
  expect(status_report[:warnings]).to eq []
167
99
  expect(status_report[:markdowns]).to eq []
168
100
  end
169
101
  end
170
-
171
- context 'missing your contribution here' do
172
- let(:filename) { File.expand_path('fixtures/changelogs/missing_your_contribution_here.md', __dir__) }
173
-
174
- context 'when placeholder line is customized' do
175
- before do
176
- changelog.placeholder_line = "* Nothing yet.\n"
177
- end
178
-
179
- it 'complains' do
180
- expect(subject).to be false
181
- expect(status_report[:errors]).to eq ["Please put back the `* Nothing yet.` line into #{filename}."]
182
- expect(status_report[:warnings]).to eq []
183
- expect(status_report[:markdowns]).to eq []
184
- end
185
- end
186
-
187
- context 'when placeholder line is default' do
188
- it 'complains' do
189
- expect(subject).to be false
190
- expect(status_report[:errors]).to eq ["Please put back the `* Your contribution here.` line into #{filename}."]
191
- expect(status_report[:warnings]).to eq []
192
- expect(status_report[:markdowns]).to eq []
193
- end
102
+ context 'mixed' do
103
+ before do
104
+ changelog.ignore_files = ['WHATEVER.md', /\.txt$/]
105
+ allow(changelog.git).to receive(:modified_files).and_return(['WHATEVER.md'])
106
+ allow(changelog.git).to receive(:added_files).and_return(['one.txt', 'two.txt'])
194
107
  end
195
108
 
196
- context 'when placeholder line is nil' do
197
- before do
198
- changelog.placeholder_line = nil
199
- end
200
-
201
- it 'is ok' do
202
- expect(subject).to be true
203
- expect(status_report[:errors]).to eq []
204
- expect(status_report[:warnings]).to eq []
205
- expect(status_report[:markdowns]).to eq []
206
- end
207
- end
208
- end
209
-
210
- context 'minimal example' do
211
- let(:filename) { File.expand_path('fixtures/changelogs/minimal.md', __dir__) }
212
- it 'is ok' do
109
+ it 'has no complaints' do
213
110
  expect(subject).to be true
214
111
  expect(status_report[:errors]).to eq []
215
112
  expect(status_report[:warnings]).to eq []
216
113
  expect(status_report[:markdowns]).to eq []
217
114
  end
218
-
219
- context 'when placeholder line is nil' do
220
- before do
221
- changelog.placeholder_line = nil
222
- end
223
-
224
- it 'complains' do
225
- expect(subject).to be false
226
- expect(status_report[:errors]).to eq ["One of the lines below found in #{filename} doesn't match the [expected format](https://github.com/dblock/danger-changelog/blob/master/README.md#whats-a-correctly-formatted-changelog-file). Please make it look like the other lines, pay attention to version numbers, periods, spaces and date formats."]
227
- expect(status_report[:warnings]).to eq []
228
- expect(status_report[:markdowns].map(&:message)).to eq [
229
- "```markdown\n* Your contribution here.\n```\n"
230
- ]
231
- end
232
- end
233
- end
234
-
235
- context 'with bad lines' do
236
- let(:filename) { File.expand_path('fixtures/changelogs/lines.md', __dir__) }
237
- it 'complains' do
238
- expect(subject).to be false
239
- expect(status_report[:errors]).to eq ["One of the lines below found in #{filename} doesn't match the [expected format](https://github.com/dblock/danger-changelog/blob/master/README.md#whats-a-correctly-formatted-changelog-file). Please make it look like the other lines, pay attention to version numbers, periods, spaces and date formats."]
240
- expect(status_report[:warnings]).to eq []
241
- expect(status_report[:markdowns].map(&:message)).to eq [
242
- "```markdown\nMissing star - [@dblock](https://github.com/dblock).\n```\n",
243
- "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1) - Not a colon - [@dblock](https://github.com/dblock).\n```\n",
244
- "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): No final period - [@dblock](https://github.com/dblock)\n```\n",
245
- "```markdown\n# [#1](https://github.com/dblock/danger-changelog/pull/1): Hash instead of star - [@dblock](https://github.com/dblock).\n```\n",
246
- "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): Extra period. - [@dblock](https://github.com/dblock).\n```\n",
247
- "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): Unbalanced ( - [@dblock](https://github.com/dblock).\n```\n",
248
- "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): Unbalanced ] - [@dblock](https://github.com/dblock).\n```\n"
249
- ]
250
- end
251
115
  end
252
116
  end
253
117
  end
254
- end
255
- end
256
-
257
- describe 'with the Keep a Changelog format' do
258
- let(:filename) { File.expand_path('fixtures/changelogs/keep_a_changelog.md', __dir__) }
259
- let(:dangerfile) { testing_dangerfile }
260
- let(:changelog) do
261
- dangerfile.changelog.format = :keep_a_changelog
262
- dangerfile.changelog.filename = filename
263
- dangerfile.changelog
264
- end
265
- let(:status_report) { changelog.status_report }
266
-
267
- describe 'in a PR' do
268
- before do
269
- changelog.env.request_source.pr_json = {
270
- 'number' => 123,
271
- 'title' => 'being dangerous',
272
- 'html_url' => 'https://github.com/dblock/danger-changelog/pull/123',
273
- 'user' => {
274
- 'login' => 'dblock'
275
- }
276
- }
277
- end
278
118
 
279
- context '#check!' do
280
- subject do
281
- changelog.check!
119
+ context 'with a new CHANGELOG' do
120
+ before do
121
+ allow(changelog.git).to receive(:modified_files).and_return([])
122
+ allow(changelog.git).to receive(:added_files).and_return([changelog.filename])
282
123
  end
283
124
 
284
- context 'without CHANGELOG changes' do
285
- before do
286
- allow(changelog.git).to receive(:modified_files).and_return(['some-file.txt'])
287
- allow(changelog.git).to receive(:added_files).and_return(['some-file.txt'])
288
- end
289
-
290
- it 'complains when no CHANGELOG can be found' do
291
- expect(subject).to be false
292
- expect(status_report[:errors]).to eq []
293
- expect(status_report[:warnings]).to eq ["Unless you're refactoring existing code or improving documentation, please update #{filename}."]
294
- expect(status_report[:markdowns].map(&:message)).to eq ["Here's an example of a #{filename} entry:\n\n```markdown\n* [#123](https://github.com/dblock/danger-changelog/pull/123): Being dangerous - [@dblock](https://github.com/dblock).\n```\n"]
295
- end
125
+ it 'has no complaints' do
126
+ expect(subject).to be true
127
+ expect(status_report[:errors]).to eq []
128
+ expect(status_report[:warnings]).to eq []
129
+ expect(status_report[:markdowns]).to eq []
296
130
  end
131
+ end
297
132
 
298
- context 'with CHANGELOG changes' do
299
- before do
300
- allow(changelog.git).to receive(:modified_files).and_return([filename])
301
- allow(changelog.git).to receive(:added_files).and_return([])
302
- end
133
+ context 'with CHANGELOG changes' do
134
+ before do
135
+ allow(changelog.git).to receive(:modified_files).and_return([changelog.filename])
136
+ allow(changelog.git).to receive(:added_files).and_return([])
137
+ end
303
138
 
304
- it 'has no complaints' do
305
- expect(subject).to be true
306
- expect(status_report[:errors]).to eq []
307
- expect(status_report[:warnings]).to eq []
308
- expect(status_report[:markdowns]).to eq []
309
- end
139
+ it 'has no complaints' do
140
+ expect(subject).to be true
141
+ expect(status_report[:errors]).to eq []
142
+ expect(status_report[:warnings]).to eq []
143
+ expect(status_report[:markdowns]).to eq []
310
144
  end
311
145
  end
312
146
  end