danger-changelog 0.7.0 → 0.8.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/danger-comment.yml +10 -0
- data/.github/workflows/danger.yml +3 -17
- data/.github/workflows/lint.yml +1 -1
- data/.github/workflows/test.yml +1 -1
- data/.rubocop.yml +6 -2
- data/.rubocop_todo.yml +112 -1
- data/CHANGELOG.md +12 -0
- data/Dangerfile +2 -2
- data/Gemfile +5 -2
- data/README.md +1 -1
- data/danger-changelog.gemspec +2 -2
- data/lib/changelog/changelog_line/changelog_entry_line.rb +7 -7
- data/lib/changelog/changelog_line/changelog_header_line.rb +4 -4
- data/lib/changelog/changelog_line/changelog_line.rb +1 -2
- data/lib/changelog/config.rb +1 -1
- data/lib/changelog/gem_version.rb +1 -1
- data/lib/changelog/parsers/intridea_format.rb +7 -4
- data/lib/changelog/parsers/keep_a_changelog.rb +5 -5
- data/lib/changelog/plugin.rb +17 -2
- data/lib/changelog/pr_metadata.rb +64 -0
- data/lib/danger_plugin.rb +2 -0
- data/spec/changelog_spec.rb +14 -18
- data/spec/config_spec.rb +15 -2
- data/spec/intridea/changelog_entry_line_spec.rb +3 -0
- data/spec/intridea/changelog_file_spec.rb +27 -1
- data/spec/intridea/changelog_line_parser_spec.rb +5 -0
- data/spec/intridea/changelog_spec.rb +20 -2
- data/spec/intridea/fixtures/validation_result.md +6 -0
- data/spec/keep_a_changelog/changelog_spec.rb +5 -2
- data/spec/plugin_spec.rb +2 -1
- data/spec/pr_metadata_spec.rb +126 -0
- data/spec/spec_helper.rb +3 -3
- metadata +10 -32
data/spec/changelog_spec.rb
CHANGED
|
@@ -24,22 +24,21 @@ describe Danger::Changelog do
|
|
|
24
24
|
|
|
25
25
|
context 'without CHANGELOG changes' do
|
|
26
26
|
before do
|
|
27
|
-
allow(changelog.git).to
|
|
28
|
-
allow(changelog.git).to receive(:added_files).and_return(['some-file.txt'])
|
|
27
|
+
allow(changelog.git).to receive_messages(modified_files: ['some-file.txt'], added_files: ['some-file.txt'])
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
it 'complains when no CHANGELOG can be found' do
|
|
32
31
|
expect(subject).to be false
|
|
33
32
|
expect(status_report[:errors]).to eq []
|
|
34
33
|
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
|
|
34
|
+
expect(status_report[:markdowns].map(&:message).first).to include("Here's an example of a CHANGELOG.md entry:")
|
|
35
|
+
expect(status_report[:markdowns].map(&:message).first).to match(%r{\* \[#\d+\]\(https://github\.com/.+/pull/\d+\): .+ - \[@.+\]\(https://github\.com/.+\)\.})
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
context 'with CHANGELOG changes' do
|
|
40
40
|
before do
|
|
41
|
-
allow(changelog.git).to
|
|
42
|
-
allow(changelog.git).to receive(:added_files).and_return([])
|
|
41
|
+
allow(changelog.git).to receive_messages(modified_files: [changelog.filename], added_files: [])
|
|
43
42
|
end
|
|
44
43
|
|
|
45
44
|
it 'has no complaints' do
|
|
@@ -59,23 +58,23 @@ describe Danger::Changelog do
|
|
|
59
58
|
context 'without CHANGELOG changes' do
|
|
60
59
|
context 'when something was modified' do
|
|
61
60
|
before do
|
|
62
|
-
allow(changelog.git).to
|
|
63
|
-
allow(changelog.git).to receive(:added_files).and_return(['another-file.txt'])
|
|
61
|
+
allow(changelog.git).to receive_messages(modified_files: ['some-file.txt'], added_files: ['another-file.txt'])
|
|
64
62
|
end
|
|
65
63
|
|
|
66
64
|
it 'complains when no CHANGELOG can be found' do
|
|
67
65
|
expect(subject).to be false
|
|
68
66
|
expect(status_report[:errors]).to eq []
|
|
69
67
|
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
|
|
68
|
+
expect(status_report[:markdowns].map(&:message).first).to include("Here's an example of a #{changelog.filename} entry:")
|
|
69
|
+
expect(status_report[:markdowns].map(&:message).first).to match(%r{\* \[#\d+\]\(https://github\.com/.+/pull/\d+\): .+ - \[@.+\]\(https://github\.com/.+\)\.})
|
|
71
70
|
end
|
|
72
71
|
end
|
|
73
72
|
|
|
74
73
|
context 'with a README.md' do
|
|
75
74
|
before do
|
|
76
|
-
allow(changelog.git).to
|
|
77
|
-
allow(changelog.git).to receive(:added_files).and_return([])
|
|
75
|
+
allow(changelog.git).to receive_messages(modified_files: ['README.md'], added_files: [])
|
|
78
76
|
end
|
|
77
|
+
|
|
79
78
|
it 'has no complaints' do
|
|
80
79
|
expect(subject).to be true
|
|
81
80
|
expect(status_report[:errors]).to eq []
|
|
@@ -88,8 +87,7 @@ describe Danger::Changelog do
|
|
|
88
87
|
context 'name' do
|
|
89
88
|
before do
|
|
90
89
|
changelog.ignore_files = ['WHATEVER.md']
|
|
91
|
-
allow(changelog.git).to
|
|
92
|
-
allow(changelog.git).to receive(:added_files).and_return([])
|
|
90
|
+
allow(changelog.git).to receive_messages(modified_files: ['WHATEVER.md'], added_files: [])
|
|
93
91
|
end
|
|
94
92
|
|
|
95
93
|
it 'has no complaints' do
|
|
@@ -99,11 +97,11 @@ describe Danger::Changelog do
|
|
|
99
97
|
expect(status_report[:markdowns]).to eq []
|
|
100
98
|
end
|
|
101
99
|
end
|
|
100
|
+
|
|
102
101
|
context 'mixed' do
|
|
103
102
|
before do
|
|
104
103
|
changelog.ignore_files = ['WHATEVER.md', /\.txt$/]
|
|
105
|
-
allow(changelog.git).to
|
|
106
|
-
allow(changelog.git).to receive(:added_files).and_return(['one.txt', 'two.txt'])
|
|
104
|
+
allow(changelog.git).to receive_messages(modified_files: ['WHATEVER.md'], added_files: ['one.txt', 'two.txt'])
|
|
107
105
|
end
|
|
108
106
|
|
|
109
107
|
it 'has no complaints' do
|
|
@@ -118,8 +116,7 @@ describe Danger::Changelog do
|
|
|
118
116
|
|
|
119
117
|
context 'with a new CHANGELOG' do
|
|
120
118
|
before do
|
|
121
|
-
allow(changelog.git).to
|
|
122
|
-
allow(changelog.git).to receive(:added_files).and_return([changelog.filename])
|
|
119
|
+
allow(changelog.git).to receive_messages(modified_files: [], added_files: [changelog.filename])
|
|
123
120
|
end
|
|
124
121
|
|
|
125
122
|
it 'has no complaints' do
|
|
@@ -132,8 +129,7 @@ describe Danger::Changelog do
|
|
|
132
129
|
|
|
133
130
|
context 'with CHANGELOG changes' do
|
|
134
131
|
before do
|
|
135
|
-
allow(changelog.git).to
|
|
136
|
-
allow(changelog.git).to receive(:added_files).and_return([])
|
|
132
|
+
allow(changelog.git).to receive_messages(modified_files: [changelog.filename], added_files: [])
|
|
137
133
|
end
|
|
138
134
|
|
|
139
135
|
it 'has no complaints' do
|
data/spec/config_spec.rb
CHANGED
|
@@ -10,6 +10,7 @@ describe Danger::Changelog::Config do
|
|
|
10
10
|
expect(changelog.placeholder_line).to eq "* Your contribution here.\n"
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
|
+
|
|
13
14
|
context 'when without markdown star' do
|
|
14
15
|
before do
|
|
15
16
|
Danger::Changelog.config.placeholder_line = "Nothing yet.\n"
|
|
@@ -40,49 +41,61 @@ describe Danger::Changelog::Config do
|
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
43
|
end
|
|
44
|
+
|
|
43
45
|
describe 'format' do
|
|
44
46
|
it 'default' do
|
|
45
47
|
expect(Danger::Changelog.config.format).to eq :intridea
|
|
46
48
|
end
|
|
49
|
+
|
|
47
50
|
it 'with an invalid format' do
|
|
48
51
|
expect { Danger::Changelog.config.format = :foobar }.to raise_error ArgumentError, 'Invalid format: foobar'
|
|
49
52
|
end
|
|
53
|
+
|
|
50
54
|
it 'with a string' do
|
|
51
|
-
expect { Danger::Changelog.config.format = 'intridea' }.
|
|
55
|
+
expect { Danger::Changelog.config.format = 'intridea' }.not_to raise_error
|
|
52
56
|
end
|
|
57
|
+
|
|
53
58
|
it 'with a symbol' do
|
|
54
|
-
expect { Danger::Changelog.config.format = :intridea }.
|
|
59
|
+
expect { Danger::Changelog.config.format = :intridea }.not_to raise_error
|
|
55
60
|
end
|
|
61
|
+
|
|
56
62
|
Danger::Changelog::Parsers::FORMATS.each_pair do |format, parser|
|
|
57
63
|
context format do
|
|
58
64
|
before do
|
|
59
65
|
Danger::Changelog.config.format = format
|
|
60
66
|
end
|
|
67
|
+
|
|
61
68
|
it 'sets format' do
|
|
62
69
|
expect(Danger::Changelog.config.format).to eq format
|
|
63
70
|
end
|
|
71
|
+
|
|
64
72
|
it 'creates parser' do
|
|
65
73
|
expect(Danger::Changelog.config.parser).to be_a parser
|
|
66
74
|
end
|
|
67
75
|
end
|
|
68
76
|
end
|
|
69
77
|
end
|
|
78
|
+
|
|
70
79
|
describe 'ignore_files' do
|
|
71
80
|
it 'default' do
|
|
72
81
|
expect(Danger::Changelog.config.ignore_files).to eq(['README.md'])
|
|
73
82
|
end
|
|
83
|
+
|
|
74
84
|
context 'with a file name' do
|
|
75
85
|
before do
|
|
76
86
|
Danger::Changelog.config.ignore_files = 'WHATEVER.md'
|
|
77
87
|
end
|
|
88
|
+
|
|
78
89
|
it 'transforms it into an array' do
|
|
79
90
|
expect(Danger::Changelog.config.ignore_files).to eq(['WHATEVER.md'])
|
|
80
91
|
end
|
|
81
92
|
end
|
|
93
|
+
|
|
82
94
|
context 'with multiple names' do
|
|
83
95
|
before do
|
|
84
96
|
Danger::Changelog.config.ignore_files = ['WHATEVER.md', /\*.md$/]
|
|
85
97
|
end
|
|
98
|
+
|
|
86
99
|
it 'transforms it into an array' do
|
|
87
100
|
expect(Danger::Changelog.config.ignore_files).to eq(['WHATEVER.md', /\*.md$/])
|
|
88
101
|
end
|
|
@@ -92,6 +92,7 @@ describe Danger::Changelog::ChangelogEntryLine do
|
|
|
92
92
|
|
|
93
93
|
context 'no transformation required' do
|
|
94
94
|
let(:pr_title) { 'Test' }
|
|
95
|
+
|
|
95
96
|
it 'uses title as is' do
|
|
96
97
|
expect(described_class.example(github)).to eq '* [#123](https://github.com/dblock/danger-changelog/pull/123): Test - [@dblock](https://github.com/dblock).'
|
|
97
98
|
end
|
|
@@ -99,6 +100,7 @@ describe Danger::Changelog::ChangelogEntryLine do
|
|
|
99
100
|
|
|
100
101
|
context 'with lowercase title' do
|
|
101
102
|
let(:pr_title) { 'test' }
|
|
103
|
+
|
|
102
104
|
it 'capitalizes it' do
|
|
103
105
|
expect(described_class.example(github)).to eq '* [#123](https://github.com/dblock/danger-changelog/pull/123): Test - [@dblock](https://github.com/dblock).'
|
|
104
106
|
end
|
|
@@ -106,6 +108,7 @@ describe Danger::Changelog::ChangelogEntryLine do
|
|
|
106
108
|
|
|
107
109
|
context 'with a trailing period' do
|
|
108
110
|
let(:pr_title) { 'Test.' }
|
|
111
|
+
|
|
109
112
|
it 'removes it' do
|
|
110
113
|
expect(described_class.example(github)).to eq '* [#123](https://github.com/dblock/danger-changelog/pull/123): Test - [@dblock](https://github.com/dblock).'
|
|
111
114
|
end
|
|
@@ -2,50 +2,63 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Danger::Changelog::ChangelogFile do
|
|
4
4
|
subject do
|
|
5
|
-
|
|
5
|
+
described_class.new(filename).tap(&:parse)
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
describe 'with the default format checker' do
|
|
9
9
|
context 'minimal example' do
|
|
10
10
|
let(:filename) { File.expand_path('fixtures/minimal.md', __dir__) }
|
|
11
|
+
|
|
11
12
|
it 'exists?' do
|
|
12
13
|
expect(subject.exists?).to be true
|
|
13
14
|
end
|
|
15
|
+
|
|
14
16
|
it 'bad_lines?' do
|
|
15
17
|
expect(subject.bad_lines).to eq []
|
|
16
18
|
expect(subject.bad_lines?).to be false
|
|
17
19
|
end
|
|
20
|
+
|
|
18
21
|
it 'is valid' do
|
|
19
22
|
expect(subject.bad_lines?).to be false
|
|
20
23
|
end
|
|
24
|
+
|
|
21
25
|
it 'has your contribution here' do
|
|
22
26
|
expect(subject.global_failures?).to be false
|
|
23
27
|
end
|
|
24
28
|
end
|
|
29
|
+
|
|
25
30
|
context 'missing your contribution here' do
|
|
26
31
|
let(:filename) { File.expand_path('fixtures/missing_your_contribution_here.md', __dir__) }
|
|
32
|
+
|
|
27
33
|
it 'is valid' do
|
|
28
34
|
expect(subject.bad_lines?).to be false
|
|
29
35
|
end
|
|
36
|
+
|
|
30
37
|
it 'is missing your contribution here' do
|
|
31
38
|
expect(subject.global_failures?).to be true
|
|
32
39
|
end
|
|
33
40
|
end
|
|
41
|
+
|
|
34
42
|
context 'does not exist' do
|
|
35
43
|
let(:filename) { 'whatever.md' }
|
|
44
|
+
|
|
36
45
|
it 'exists?' do
|
|
37
46
|
expect(subject.exists?).to be false
|
|
38
47
|
end
|
|
48
|
+
|
|
39
49
|
it 'bad_lines?' do
|
|
40
50
|
expect(subject.bad_lines).to be_empty
|
|
41
51
|
expect(subject.bad_lines?).to be false
|
|
42
52
|
end
|
|
43
53
|
end
|
|
54
|
+
|
|
44
55
|
context 'with bad lines' do
|
|
45
56
|
let(:filename) { File.expand_path('fixtures/lines.md', __dir__) }
|
|
57
|
+
|
|
46
58
|
it 'is invalid' do
|
|
47
59
|
expect(subject.bad_lines?).to be true
|
|
48
60
|
end
|
|
61
|
+
|
|
49
62
|
it 'reports all bad lines' do
|
|
50
63
|
expect(subject.bad_lines).to eq [
|
|
51
64
|
["Missing star - [@dblock](https://github.com/dblock).\n", 'does not start with a star, does not include a pull request link'],
|
|
@@ -57,26 +70,33 @@ describe Danger::Changelog::ChangelogFile do
|
|
|
57
70
|
["* [#1](https://github.com/dblock/danger-changelog/pull/1): Unbalanced ] - [@dblock](https://github.com/dblock).\n", 'too many parenthesis']
|
|
58
71
|
]
|
|
59
72
|
end
|
|
73
|
+
|
|
60
74
|
it 'has your contribution here' do
|
|
61
75
|
expect(subject.global_failures?).to be false
|
|
62
76
|
end
|
|
63
77
|
end
|
|
78
|
+
|
|
64
79
|
context 'with a line that has an extra trailing space' do
|
|
65
80
|
let(:filename) { File.expand_path('fixtures/extra_trailing_space.md', __dir__) }
|
|
81
|
+
|
|
66
82
|
it 'is invalid' do
|
|
67
83
|
expect(subject.bad_lines?).to be true
|
|
68
84
|
end
|
|
85
|
+
|
|
69
86
|
it 'reports all bad lines' do
|
|
70
87
|
expect(subject.bad_lines).to eq [
|
|
71
88
|
["* [#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
89
|
]
|
|
73
90
|
end
|
|
74
91
|
end
|
|
92
|
+
|
|
75
93
|
context 'with bad dates' do
|
|
76
94
|
let(:filename) { File.expand_path('fixtures/dates.md', __dir__) }
|
|
95
|
+
|
|
77
96
|
it 'is invalid' do
|
|
78
97
|
expect(subject.bad_lines?).to be true
|
|
79
98
|
end
|
|
99
|
+
|
|
80
100
|
it 'reports all bad dates' do
|
|
81
101
|
expect(subject.bad_lines).to eq [
|
|
82
102
|
["### 1.2.3 (1/2/2018)\n"],
|
|
@@ -86,11 +106,14 @@ describe Danger::Changelog::ChangelogFile do
|
|
|
86
106
|
]
|
|
87
107
|
end
|
|
88
108
|
end
|
|
109
|
+
|
|
89
110
|
context 'with bad semver' do
|
|
90
111
|
let(:filename) { File.expand_path('fixtures/semver.md', __dir__) }
|
|
112
|
+
|
|
91
113
|
it 'is invalid' do
|
|
92
114
|
expect(subject.bad_lines?).to be true
|
|
93
115
|
end
|
|
116
|
+
|
|
94
117
|
it 'reports all bad dates' do
|
|
95
118
|
expect(subject.bad_lines).to eq [
|
|
96
119
|
["### 0 (2018/1/1)\n"],
|
|
@@ -99,11 +122,14 @@ describe Danger::Changelog::ChangelogFile do
|
|
|
99
122
|
]
|
|
100
123
|
end
|
|
101
124
|
end
|
|
125
|
+
|
|
102
126
|
context 'with imbalanced parenthesis' do
|
|
103
127
|
let(:filename) { File.expand_path('fixtures/imbalanced.md', __dir__) }
|
|
128
|
+
|
|
104
129
|
it 'is invalid' do
|
|
105
130
|
expect(subject.bad_lines?).to be true
|
|
106
131
|
end
|
|
132
|
+
|
|
107
133
|
it 'reports all bad lines' do
|
|
108
134
|
expect(subject.bad_lines).to eq [
|
|
109
135
|
["### 0.0.0)\n"],
|
|
@@ -5,6 +5,7 @@ describe Danger::Changelog::ChangelogLineParser do
|
|
|
5
5
|
context 'changelog entry line' do
|
|
6
6
|
context 'when valid' do
|
|
7
7
|
let(:line) { '* [#123](https://github.com/dblock/danger-changelog/pull/123): Test - [@dblock](https://github.com/dblock).' }
|
|
8
|
+
|
|
8
9
|
it 'returns ChangelogEntryLine' do
|
|
9
10
|
expect(described_class.parse(line)).to be_a(Danger::Changelog::ChangelogEntryLine)
|
|
10
11
|
end
|
|
@@ -26,6 +27,7 @@ describe Danger::Changelog::ChangelogLineParser do
|
|
|
26
27
|
|
|
27
28
|
context 'changelog your contribution here line' do
|
|
28
29
|
let(:line) { "* Your contribution here.\n" }
|
|
30
|
+
|
|
29
31
|
it 'returns ChangelogPlaceholderLine' do
|
|
30
32
|
expect(described_class.parse(line)).to be_a(Danger::Changelog::ChangelogPlaceholderLine)
|
|
31
33
|
end
|
|
@@ -34,6 +36,7 @@ describe Danger::Changelog::ChangelogLineParser do
|
|
|
34
36
|
context 'changelog header line' do
|
|
35
37
|
context 'when one hash' do
|
|
36
38
|
let(:line) { '# Version 1.1.1' }
|
|
39
|
+
|
|
37
40
|
it 'returns ChangelogHeaderLine' do
|
|
38
41
|
expect(described_class.parse(line)).to be_a(Danger::Changelog::ChangelogHeaderLine)
|
|
39
42
|
end
|
|
@@ -41,6 +44,7 @@ describe Danger::Changelog::ChangelogLineParser do
|
|
|
41
44
|
|
|
42
45
|
context 'when two hashes' do
|
|
43
46
|
let(:line) { '## Version 1.1.1' }
|
|
47
|
+
|
|
44
48
|
it 'returns ChangelogHeaderLine' do
|
|
45
49
|
expect(described_class.parse(line)).to be_a(Danger::Changelog::ChangelogHeaderLine)
|
|
46
50
|
end
|
|
@@ -48,6 +52,7 @@ describe Danger::Changelog::ChangelogLineParser do
|
|
|
48
52
|
|
|
49
53
|
context 'when three hashes' do
|
|
50
54
|
let(:line) { '### Version 1.1.1' }
|
|
55
|
+
|
|
51
56
|
it 'returns ChangelogHeaderLine' do
|
|
52
57
|
expect(described_class.parse(line)).to be_a(Danger::Changelog::ChangelogHeaderLine)
|
|
53
58
|
end
|
|
@@ -27,6 +27,7 @@ describe Danger::Changelog do
|
|
|
27
27
|
|
|
28
28
|
context 'without a CHANGELOG file' do
|
|
29
29
|
let(:filename) { 'does-not-exist' }
|
|
30
|
+
|
|
30
31
|
it 'complains' do
|
|
31
32
|
expect(subject).to be false
|
|
32
33
|
expect(status_report[:errors]).to eq ['The does-not-exist file does not exist.']
|
|
@@ -37,8 +38,7 @@ describe Danger::Changelog do
|
|
|
37
38
|
let(:filename) { File.expand_path('fixtures/minimal.md', __dir__) }
|
|
38
39
|
|
|
39
40
|
before do
|
|
40
|
-
allow(changelog.git).to
|
|
41
|
-
allow(changelog.git).to receive(:added_files).and_return([])
|
|
41
|
+
allow(changelog.git).to receive_messages(modified_files: [filename], added_files: [])
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it 'has no complaints' do
|
|
@@ -54,6 +54,7 @@ describe Danger::Changelog do
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
let(:filename) { File.expand_path('fixtures/customized.md', __dir__) }
|
|
57
|
+
|
|
57
58
|
it 'is ok' do
|
|
58
59
|
expect(subject).to be true
|
|
59
60
|
expect(status_report[:errors]).to eq []
|
|
@@ -103,6 +104,7 @@ describe Danger::Changelog do
|
|
|
103
104
|
|
|
104
105
|
context 'minimal example' do
|
|
105
106
|
let(:filename) { File.expand_path('fixtures/minimal.md', __dir__) }
|
|
107
|
+
|
|
106
108
|
it 'is ok' do
|
|
107
109
|
expect(subject).to be true
|
|
108
110
|
expect(status_report[:errors]).to eq []
|
|
@@ -128,6 +130,7 @@ describe Danger::Changelog do
|
|
|
128
130
|
|
|
129
131
|
context 'with bad lines' do
|
|
130
132
|
let(:filename) { File.expand_path('fixtures/lines.md', __dir__) }
|
|
133
|
+
|
|
131
134
|
it 'complains' do
|
|
132
135
|
expect(subject).to be false
|
|
133
136
|
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."]
|
|
@@ -143,6 +146,21 @@ describe Danger::Changelog do
|
|
|
143
146
|
]
|
|
144
147
|
end
|
|
145
148
|
end
|
|
149
|
+
|
|
150
|
+
context 'with a contribution line starting with a -' do
|
|
151
|
+
let(:filename) { File.expand_path('fixtures/validation_result.md', __dir__) }
|
|
152
|
+
|
|
153
|
+
it 'cannot be parsed' do
|
|
154
|
+
expect(subject).to be false
|
|
155
|
+
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."]
|
|
156
|
+
expect(status_report[:warnings]).to eq []
|
|
157
|
+
expect(status_report[:markdowns].map(&:message)).to eq [
|
|
158
|
+
"```markdown\n- [#67](https://github.com/dblock/danger-changelog/pull/67): Various build updates - [@bob](https://github.com/bob).\ndoes not start with a star\n```\n",
|
|
159
|
+
"```markdown\n- [#68](https://github.com/dblock/danger-changelog/pull/68): Properly render `example` - [@janet](https://github.com/janet).\ndoes not start with a star\n```\n",
|
|
160
|
+
"```markdown\n- Your contribution here.\ncannot be parsed\n```\n"
|
|
161
|
+
]
|
|
162
|
+
end
|
|
163
|
+
end
|
|
146
164
|
end
|
|
147
165
|
end
|
|
148
166
|
end
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
### Next
|
|
2
|
+
#### Fixes
|
|
3
|
+
- [#67](https://github.com/dblock/danger-changelog/pull/67): Various build updates - [@bob](https://github.com/bob).
|
|
4
|
+
- [#68](https://github.com/dblock/danger-changelog/pull/68): Properly render `example` - [@janet](https://github.com/janet).
|
|
5
|
+
- Your contribution here.
|
|
6
|
+
* Your contribution here.
|
|
@@ -26,12 +26,12 @@ describe Danger::Changelog do
|
|
|
26
26
|
|
|
27
27
|
context 'with CHANGELOG changes' do
|
|
28
28
|
before do
|
|
29
|
-
allow(changelog.git).to
|
|
30
|
-
allow(changelog.git).to receive(:added_files).and_return([])
|
|
29
|
+
allow(changelog.git).to receive_messages(modified_files: [filename], added_files: [])
|
|
31
30
|
end
|
|
32
31
|
|
|
33
32
|
context 'valid file' do
|
|
34
33
|
let(:filename) { File.expand_path('fixtures/complete.md', __dir__) }
|
|
34
|
+
|
|
35
35
|
it 'has no complaints' do
|
|
36
36
|
expect(subject).to be true
|
|
37
37
|
expect(status_report[:errors]).to eq []
|
|
@@ -42,6 +42,7 @@ describe Danger::Changelog do
|
|
|
42
42
|
|
|
43
43
|
context 'with lines containing links' do
|
|
44
44
|
let(:filename) { File.expand_path('fixtures/lines_with_links.md', __dir__) }
|
|
45
|
+
|
|
45
46
|
it 'is valid' do
|
|
46
47
|
expect(subject).to be true
|
|
47
48
|
expect(status_report[:errors]).to eq []
|
|
@@ -52,6 +53,7 @@ describe Danger::Changelog do
|
|
|
52
53
|
|
|
53
54
|
context 'missing a version header' do
|
|
54
55
|
let(:filename) { File.expand_path('fixtures/missing_a_version_header.md', __dir__) }
|
|
56
|
+
|
|
55
57
|
it 'complains' do
|
|
56
58
|
expect(subject).to be false
|
|
57
59
|
expect(status_report[:errors]).to eq [
|
|
@@ -67,6 +69,7 @@ describe Danger::Changelog do
|
|
|
67
69
|
|
|
68
70
|
context 'invalid line' do
|
|
69
71
|
let(:filename) { File.expand_path('fixtures/invalid_line.md', __dir__) }
|
|
72
|
+
|
|
70
73
|
it 'complains' do
|
|
71
74
|
expect(subject).to be false
|
|
72
75
|
expect(status_report[:errors]).to eq [
|
data/spec/plugin_spec.rb
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
|
|
4
|
+
describe Danger::Changelog::PRMetadata do
|
|
5
|
+
describe '.from_github_plugin' do
|
|
6
|
+
context 'when github is nil' do
|
|
7
|
+
it 'returns nil' do
|
|
8
|
+
expect(described_class.from_github_plugin(nil)).to be_nil
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context 'when github has no pr_json' do
|
|
13
|
+
let(:github) { instance_double(Danger::DangerfileGitHubPlugin, pr_json: nil) }
|
|
14
|
+
|
|
15
|
+
it 'returns nil' do
|
|
16
|
+
expect(described_class.from_github_plugin(github)).to be_nil
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'when github has pr_json' do
|
|
21
|
+
subject(:metadata) { described_class.from_github_plugin(github) }
|
|
22
|
+
|
|
23
|
+
let(:github) do
|
|
24
|
+
instance_double(
|
|
25
|
+
Danger::DangerfileGitHubPlugin,
|
|
26
|
+
pr_json: { 'number' => 123, 'html_url' => 'https://github.com/org/repo/pull/123' },
|
|
27
|
+
pr_title: 'Add feature',
|
|
28
|
+
pr_author: 'dblock'
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'creates metadata from github plugin' do
|
|
33
|
+
expect(metadata.pr_json).to eq('number' => 123, 'html_url' => 'https://github.com/org/repo/pull/123')
|
|
34
|
+
expect(metadata.pr_title).to eq 'Add feature'
|
|
35
|
+
expect(metadata.pr_author).to eq 'dblock'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context 'when github plugin raises Octokit::Error' do
|
|
40
|
+
let(:github) do
|
|
41
|
+
instance_double(Danger::DangerfileGitHubPlugin)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
[Octokit::Unauthorized, Octokit::TooManyRequests, Octokit::Forbidden].each do |error_class|
|
|
45
|
+
context "with #{error_class}" do
|
|
46
|
+
before do
|
|
47
|
+
allow(github).to receive(:pr_json).and_raise(error_class.new)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'returns nil to allow fallback' do
|
|
51
|
+
expect(described_class.from_github_plugin(github)).to be_nil
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe '.from_event_file' do
|
|
59
|
+
context 'when path is nil' do
|
|
60
|
+
it 'returns nil' do
|
|
61
|
+
expect(described_class.from_event_file(nil)).to be_nil
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context 'when file does not exist' do
|
|
66
|
+
it 'returns nil' do
|
|
67
|
+
expect(described_class.from_event_file('/nonexistent/path.json')).to be_nil
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context 'when file contains pull_request event' do
|
|
72
|
+
subject(:metadata) { described_class.from_event_file(event_file.path) }
|
|
73
|
+
|
|
74
|
+
let(:event_file) { Tempfile.new(['github_event', '.json']) }
|
|
75
|
+
let(:event_data) do
|
|
76
|
+
{
|
|
77
|
+
'pull_request' => {
|
|
78
|
+
'number' => 456,
|
|
79
|
+
'html_url' => 'https://github.com/org/repo/pull/456',
|
|
80
|
+
'title' => 'Fix bug',
|
|
81
|
+
'user' => { 'login' => 'contributor' }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
before do
|
|
87
|
+
event_file.write(JSON.generate(event_data))
|
|
88
|
+
event_file.close
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
after { event_file.unlink }
|
|
92
|
+
|
|
93
|
+
it 'creates metadata from event file' do
|
|
94
|
+
expect(metadata.pr_json).to eq event_data['pull_request']
|
|
95
|
+
expect(metadata.pr_title).to eq 'Fix bug'
|
|
96
|
+
expect(metadata.pr_author).to eq 'contributor'
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context 'when file contains non-PR event' do
|
|
101
|
+
let(:event_file) { Tempfile.new(['github_event', '.json']) }
|
|
102
|
+
let(:event_data) { { 'push' => { 'ref' => 'refs/heads/main' } } }
|
|
103
|
+
|
|
104
|
+
before do
|
|
105
|
+
event_file.write(JSON.generate(event_data))
|
|
106
|
+
event_file.close
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
after { event_file.unlink }
|
|
110
|
+
|
|
111
|
+
it 'returns nil' do
|
|
112
|
+
expect(described_class.from_event_file(event_file.path)).to be_nil
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe '.fallback' do
|
|
118
|
+
subject(:metadata) { described_class.fallback }
|
|
119
|
+
|
|
120
|
+
it 'returns metadata with example values' do
|
|
121
|
+
expect(metadata.pr_json).to eq('number' => 123, 'html_url' => 'https://github.com/org/repo/pull/123')
|
|
122
|
+
expect(metadata.pr_title).to eq 'Your contribution'
|
|
123
|
+
expect(metadata.pr_author).to eq 'username'
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'pathname'
|
|
2
2
|
ROOT = Pathname.new(File.expand_path('..', __dir__))
|
|
3
|
-
$LOAD_PATH.unshift(
|
|
4
|
-
$LOAD_PATH.unshift(
|
|
3
|
+
$LOAD_PATH.unshift("#{ROOT}lib".to_s)
|
|
4
|
+
$LOAD_PATH.unshift("#{ROOT}spec".to_s)
|
|
5
5
|
|
|
6
6
|
require 'bundler/setup'
|
|
7
7
|
require 'pry'
|
|
@@ -42,6 +42,6 @@ end
|
|
|
42
42
|
|
|
43
43
|
require 'active_support'
|
|
44
44
|
|
|
45
|
-
Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|
|
|
45
|
+
Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].sort.each do |file|
|
|
46
46
|
require file
|
|
47
47
|
end
|