danger-changelog 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,13 +1,21 @@
1
- require File.expand_path('spec_helper', __dir__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Danger::Changelog::Config do
4
4
  describe 'placeholder_line' do
5
+ context 'an instance of a dangerfile' do
6
+ let(:dangerfile) { testing_dangerfile }
7
+ let(:changelog) { dangerfile.changelog }
8
+
9
+ it 'defaults placeholder_line' do
10
+ expect(changelog.placeholder_line).to eq "* Your contribution here.\n"
11
+ end
12
+ end
5
13
  context 'when without markdown star' do
6
14
  before do
7
15
  Danger::Changelog.config.placeholder_line = "Nothing yet.\n"
8
16
  end
9
17
 
10
- it 'ads missing star and saves configuration' do
18
+ it 'adds missing star and saves configuration' do
11
19
  expect(Danger::Changelog.config.placeholder_line).to eq "* Nothing yet.\n"
12
20
  end
13
21
  end
@@ -17,7 +25,7 @@ describe Danger::Changelog::Config do
17
25
  Danger::Changelog.config.placeholder_line = '* Nothing yet.'
18
26
  end
19
27
 
20
- it 'ads missing trailing newline and saves configuration' do
28
+ it 'adds missing trailing newline and saves configuration' do
21
29
  expect(Danger::Changelog.config.placeholder_line).to eq "* Nothing yet.\n"
22
30
  end
23
31
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('spec_helper', __dir__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Danger::Changelog::ChangelogEntryLine do
4
4
  it_behaves_like 'validates as changelog entry line', '* Valid without PR link - [@dblock](https://github.com/dblock).'
@@ -0,0 +1,120 @@
1
+ require 'spec_helper'
2
+
3
+ describe Danger::Changelog::ChangelogFile do
4
+ subject do
5
+ Danger::Changelog::ChangelogFile.new(filename).tap(&:parse)
6
+ end
7
+
8
+ describe 'with the default format checker' do
9
+ context 'minimal example' do
10
+ let(:filename) { File.expand_path('fixtures/minimal.md', __dir__) }
11
+ it 'exists?' do
12
+ expect(subject.exists?).to be true
13
+ end
14
+ it 'bad_lines?' do
15
+ expect(subject.bad_lines).to eq []
16
+ expect(subject.bad_lines?).to be false
17
+ end
18
+ it 'is valid' do
19
+ expect(subject.bad_lines?).to be false
20
+ end
21
+ it 'has your contribution here' do
22
+ expect(subject.global_failures?).to be false
23
+ end
24
+ end
25
+ context 'missing your contribution here' do
26
+ let(:filename) { File.expand_path('fixtures/missing_your_contribution_here.md', __dir__) }
27
+ it 'is valid' do
28
+ expect(subject.bad_lines?).to be false
29
+ end
30
+ it 'is missing your contribution here' do
31
+ expect(subject.global_failures?).to be true
32
+ end
33
+ end
34
+ context 'does not exist' do
35
+ let(:filename) { 'whatever.md' }
36
+ it 'exists?' do
37
+ expect(subject.exists?).to be false
38
+ end
39
+ it 'bad_lines?' do
40
+ expect(subject.bad_lines).to be_empty
41
+ expect(subject.bad_lines?).to be false
42
+ end
43
+ end
44
+ context 'with bad lines' do
45
+ let(:filename) { File.expand_path('fixtures/lines.md', __dir__) }
46
+ it 'is invalid' do
47
+ expect(subject.bad_lines?).to be true
48
+ end
49
+ it 'reports all bad lines' do
50
+ expect(subject.bad_lines).to eq [
51
+ ["Missing star - [@dblock](https://github.com/dblock).\n", 'does not start with a star, does not include a pull request link'],
52
+ ["* [#1](https://github.com/dblock/danger-changelog/pull/1) - Not a colon - [@dblock](https://github.com/dblock).\n"],
53
+ ["* [#1](https://github.com/dblock/danger-changelog/pull/1): No final period - [@dblock](https://github.com/dblock)\n", 'is missing a period at the end of the line'],
54
+ ["# [#1](https://github.com/dblock/danger-changelog/pull/1): Hash instead of star - [@dblock](https://github.com/dblock).\n", 'does not start with a star'],
55
+ ["* [#1](https://github.com/dblock/danger-changelog/pull/1): Extra period. - [@dblock](https://github.com/dblock).\n", 'has an extra period or comma at the end of the description'],
56
+ ["* [#1](https://github.com/dblock/danger-changelog/pull/1): Unbalanced ( - [@dblock](https://github.com/dblock).\n", 'too many parenthesis'],
57
+ ["* [#1](https://github.com/dblock/danger-changelog/pull/1): Unbalanced ] - [@dblock](https://github.com/dblock).\n", 'too many parenthesis']
58
+ ]
59
+ end
60
+ it 'has your contribution here' do
61
+ expect(subject.global_failures?).to be false
62
+ end
63
+ end
64
+ context 'with a line that has an extra trailing space' do
65
+ let(:filename) { File.expand_path('fixtures/extra_trailing_space.md', __dir__) }
66
+ it 'is invalid' do
67
+ expect(subject.bad_lines?).to be true
68
+ end
69
+ it 'reports all bad lines' do
70
+ expect(subject.bad_lines).to eq [
71
+ ["* [#1](https://github.com/dblock/danger-changelog/pull/1): Extra trailing space - [@dblock](https://github.com/dblock). \n", 'has an extra trailing space, is missing a period at the end of the line']
72
+ ]
73
+ end
74
+ end
75
+ context 'with bad dates' do
76
+ let(:filename) { File.expand_path('fixtures/dates.md', __dir__) }
77
+ it 'is invalid' do
78
+ expect(subject.bad_lines?).to be true
79
+ end
80
+ it 'reports all bad dates' do
81
+ expect(subject.bad_lines).to eq [
82
+ ["### 1.2.3 (1/2/2018)\n"],
83
+ ["### 1.2.3 (2018/13/1)\n"],
84
+ ["### 1.2.3 (2018/13)\n"],
85
+ ["### 1.2.3 (2018/1/1/3)\n"]
86
+ ]
87
+ end
88
+ end
89
+ context 'with bad semver' do
90
+ let(:filename) { File.expand_path('fixtures/semver.md', __dir__) }
91
+ it 'is invalid' do
92
+ expect(subject.bad_lines?).to be true
93
+ end
94
+ it 'reports all bad dates' do
95
+ expect(subject.bad_lines).to eq [
96
+ ["### 0 (2018/1/1)\n"],
97
+ ["### 0. (2018/1/1)\n"],
98
+ ["### 0.1. (2018/1/1)\n"]
99
+ ]
100
+ end
101
+ end
102
+ context 'with imbalanced parenthesis' do
103
+ let(:filename) { File.expand_path('fixtures/imbalanced.md', __dir__) }
104
+ it 'is invalid' do
105
+ expect(subject.bad_lines?).to be true
106
+ end
107
+ it 'reports all bad lines' do
108
+ expect(subject.bad_lines).to eq [
109
+ ["### 0.0.0)\n"],
110
+ ["### (0.0.1\n"],
111
+ ["### 1.2.3 (2018/1/1\n"],
112
+ ["### 0.1.0 2018/1/1)\n"],
113
+ ["### 0 ((2018/1/1)\n"],
114
+ ["### 0. [2018/1/1)\n"],
115
+ ["### 0.1. (2018/1/1)]\n"]
116
+ ]
117
+ end
118
+ end
119
+ end
120
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path('spec_helper', __dir__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Danger::Changelog::ChangelogHeaderLine do
4
4
  it_behaves_like 'validates as changelog header line', '# 1.0.1'
@@ -1,4 +1,4 @@
1
- require File.expand_path('spec_helper', __dir__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Danger::Changelog::ChangelogLineParser do
4
4
  context 'parse' do
@@ -1,9 +1,11 @@
1
- require File.expand_path('spec_helper', __dir__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Danger::Changelog::ChangelogPlaceholderLine do
4
+ let(:config) { Danger::Changelog.config }
5
+
4
6
  context 'with a custom placeholder line' do
5
7
  before do
6
- Danger::Changelog.config.placeholder_line = "* Nothing yet here.\n"
8
+ config.placeholder_line = "* Nothing yet here.\n"
7
9
  end
8
10
 
9
11
  context 'when line is equal to placeholder_line from config' do
@@ -19,7 +21,7 @@ describe Danger::Changelog::ChangelogPlaceholderLine do
19
21
 
20
22
  context 'with a blank placeholder line' do
21
23
  before do
22
- Danger::Changelog.config.placeholder_line = nil
24
+ config.placeholder_line = nil
23
25
  end
24
26
 
25
27
  context 'when line is not blank' do
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+
3
+ describe Danger::Changelog do
4
+ describe 'with Dangerfile' do
5
+ let(:dangerfile) { testing_dangerfile }
6
+ let(:changelog) { dangerfile.changelog }
7
+ let(:status_report) { changelog.status_report }
8
+
9
+ describe 'in a PR' do
10
+ before do
11
+ # typical PR JSON looks like https://raw.githubusercontent.com/danger/danger/bffc246a11dac883d76fc6636319bd6c2acd58a3/spec/fixtures/pr_response.json
12
+ changelog.env.request_source.pr_json = {
13
+ 'number' => 123,
14
+ 'title' => 'being dangerous',
15
+ 'html_url' => 'https://github.com/dblock/danger-changelog/pull/123',
16
+ 'user' => {
17
+ 'login' => 'dblock'
18
+ }
19
+ }
20
+ end
21
+
22
+ context 'is_changelog_format_correct?' do
23
+ subject do
24
+ changelog.filename = filename
25
+ changelog.is_changelog_format_correct?
26
+ end
27
+
28
+ context 'without a CHANGELOG file' do
29
+ let(:filename) { 'does-not-exist' }
30
+ it 'complains' do
31
+ expect(subject).to be false
32
+ expect(status_report[:errors]).to eq ['The does-not-exist file does not exist.']
33
+ end
34
+ end
35
+
36
+ context 'with CHANGELOG changes' do
37
+ let(:filename) { File.expand_path('fixtures/minimal.md', __dir__) }
38
+
39
+ before do
40
+ allow(changelog.git).to receive(:modified_files).and_return([filename])
41
+ allow(changelog.git).to receive(:added_files).and_return([])
42
+ end
43
+
44
+ it 'has no complaints' do
45
+ expect(subject).to be true
46
+ expect(status_report[:errors]).to eq []
47
+ expect(status_report[:warnings]).to eq []
48
+ expect(status_report[:markdowns]).to eq []
49
+ end
50
+
51
+ context 'customized' do
52
+ before do
53
+ changelog.placeholder_line = "* Nothing yet.\n"
54
+ end
55
+
56
+ let(:filename) { File.expand_path('fixtures/customized.md', __dir__) }
57
+ it 'is ok' do
58
+ expect(subject).to be true
59
+ expect(status_report[:errors]).to eq []
60
+ expect(status_report[:warnings]).to eq []
61
+ expect(status_report[:markdowns]).to eq []
62
+ end
63
+ end
64
+
65
+ context 'missing your contribution here' do
66
+ let(:filename) { File.expand_path('fixtures/missing_your_contribution_here.md', __dir__) }
67
+
68
+ context 'when placeholder line is customized' do
69
+ before do
70
+ changelog.placeholder_line = "* Nothing yet.\n"
71
+ end
72
+
73
+ it 'complains' do
74
+ expect(subject).to be false
75
+ expect(status_report[:errors]).to eq ["Please put back the `* Nothing yet.` line into #{filename}."]
76
+ expect(status_report[:warnings]).to eq []
77
+ expect(status_report[:markdowns]).to eq []
78
+ end
79
+ end
80
+
81
+ context 'when placeholder line is default' do
82
+ it 'complains' do
83
+ expect(subject).to be false
84
+ expect(status_report[:errors]).to eq ["Please put back the `* Your contribution here.` line into #{filename}."]
85
+ expect(status_report[:warnings]).to eq []
86
+ expect(status_report[:markdowns]).to eq []
87
+ end
88
+ end
89
+
90
+ context 'when placeholder line is nil' do
91
+ before do
92
+ changelog.placeholder_line = nil
93
+ end
94
+
95
+ it 'is ok' do
96
+ expect(subject).to be true
97
+ expect(status_report[:errors]).to eq []
98
+ expect(status_report[:warnings]).to eq []
99
+ expect(status_report[:markdowns]).to eq []
100
+ end
101
+ end
102
+ end
103
+
104
+ context 'minimal example' do
105
+ let(:filename) { File.expand_path('fixtures/minimal.md', __dir__) }
106
+ it 'is ok' do
107
+ expect(subject).to be true
108
+ expect(status_report[:errors]).to eq []
109
+ expect(status_report[:warnings]).to eq []
110
+ expect(status_report[:markdowns]).to eq []
111
+ end
112
+
113
+ context 'when placeholder line is nil' do
114
+ before do
115
+ changelog.placeholder_line = nil
116
+ end
117
+
118
+ it 'complains' do
119
+ expect(subject).to be false
120
+ 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."]
121
+ expect(status_report[:warnings]).to eq []
122
+ expect(status_report[:markdowns].map(&:message)).to eq [
123
+ "```markdown\n* Your contribution here.\ndoes not include a pull request link, does not include an author link\n```\n"
124
+ ]
125
+ end
126
+ end
127
+ end
128
+
129
+ context 'with bad lines' do
130
+ let(:filename) { File.expand_path('fixtures/lines.md', __dir__) }
131
+ it 'complains' do
132
+ expect(subject).to be false
133
+ 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."]
134
+ expect(status_report[:warnings]).to eq []
135
+ expect(status_report[:markdowns].map(&:message)).to eq [
136
+ "```markdown\nMissing star - [@dblock](https://github.com/dblock).\ndoes not start with a star, does not include a pull request link\n```\n",
137
+ "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1) - Not a colon - [@dblock](https://github.com/dblock).\n```\n",
138
+ "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): No final period - [@dblock](https://github.com/dblock)\nis missing a period at the end of the line\n```\n",
139
+ "```markdown\n# [#1](https://github.com/dblock/danger-changelog/pull/1): Hash instead of star - [@dblock](https://github.com/dblock).\ndoes not start with a star\n```\n",
140
+ "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): Extra period. - [@dblock](https://github.com/dblock).\nhas an extra period or comma at the end of the description\n```\n",
141
+ "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): Unbalanced ( - [@dblock](https://github.com/dblock).\ntoo many parenthesis\n```\n",
142
+ "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): Unbalanced ] - [@dblock](https://github.com/dblock).\ntoo many parenthesis\n```\n"
143
+ ]
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,3 @@
1
+ ### Changelog
2
+
3
+ * [#1](https://github.com/dblock/danger-changelog/pull/1): Extra trailing space - [@dblock](https://github.com/dblock).
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe Danger::Changelog do
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
+ }
18
+ end
19
+
20
+ context 'is_changelog_format_correct?' do
21
+ subject do
22
+ changelog.format = :keep_a_changelog
23
+ changelog.filename = filename
24
+ changelog.is_changelog_format_correct?
25
+ end
26
+
27
+ context 'with CHANGELOG changes' do
28
+ before do
29
+ allow(changelog.git).to receive(:modified_files).and_return([filename])
30
+ allow(changelog.git).to receive(:added_files).and_return([])
31
+ end
32
+
33
+ context 'valid file' do
34
+ let(:filename) { File.expand_path('fixtures/complete.md', __dir__) }
35
+ it 'has no complaints' do
36
+ expect(subject).to be true
37
+ expect(status_report[:errors]).to eq []
38
+ expect(status_report[:warnings]).to eq []
39
+ expect(status_report[:markdowns]).to eq []
40
+ end
41
+ end
42
+
43
+ context 'with lines containing links' do
44
+ let(:filename) { File.expand_path('fixtures/lines_with_links.md', __dir__) }
45
+ it 'is valid' 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 []
50
+ end
51
+ end
52
+
53
+ context 'missing a version header' do
54
+ let(:filename) { File.expand_path('fixtures/missing_a_version_header.md', __dir__) }
55
+ it 'complains' do
56
+ expect(subject).to be false
57
+ expect(status_report[:errors]).to eq [
58
+ "One of the lines below found in #{filename} doesn't match the [expected format](https://keepachangelog.com).",
59
+ 'The changelog is missing the version header for the Keep A Changelog format. See <https://keepachangelog.com> to see the format of the header.'
60
+ ]
61
+ expect(status_report[:warnings]).to eq []
62
+ expect(status_report[:markdowns].map(&:message)).to eq [
63
+ "```markdown\nAll notable changes to this project will be documented in this file.\n```\n"
64
+ ]
65
+ end
66
+ end
67
+
68
+ context 'invalid line' do
69
+ let(:filename) { File.expand_path('fixtures/invalid_line.md', __dir__) }
70
+ it 'complains' do
71
+ expect(subject).to be false
72
+ expect(status_report[:errors]).to eq [
73
+ "One of the lines below found in #{filename} doesn't match the [expected format](https://keepachangelog.com)."
74
+ ]
75
+ expect(status_report[:warnings]).to eq []
76
+ expect(status_report[:markdowns].map(&:message)).to eq [
77
+ "```markdown\nInvalid line by [@tylerfortune8](https://github.com/tylerfortune8).\n```\n"
78
+ ]
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end