danger-changelog 0.7.1 → 0.9.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_todo.yml +2 -17
- data/CHANGELOG.md +15 -0
- data/Dangerfile +2 -2
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/doc/intridea.md +3 -0
- data/lib/changelog/changelog_line/changelog_entry_line.rb +8 -5
- data/lib/changelog/gem_version.rb +1 -1
- data/lib/changelog/plugin.rb +16 -1
- data/lib/changelog/pr_metadata.rb +64 -0
- data/lib/danger_plugin.rb +2 -0
- data/spec/changelog_spec.rb +4 -2
- data/spec/intridea/changelog_entry_line_spec.rb +57 -0
- data/spec/intridea/changelog_file_spec.rb +9 -0
- data/spec/intridea/fixtures/bot_authors.md +5 -0
- data/spec/pr_metadata_spec.rb +126 -0
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 173f58cbaf43ff80a454e062c19f6674e0742c37fbd59c5bb4e85bc00c8d3899
|
|
4
|
+
data.tar.gz: 21ac5d08f53444c17cf3231880fc4f45beaca225970ecd1862002909ebbcf8fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e98417f1d4a0d74eeea613d876eca5b39dd5e12337255c08ba3598cde50731fce8533eaddd4b3bde26a20e84baa4674eff409a8b0564f4f539a2f23d0a0534b
|
|
7
|
+
data.tar.gz: ae509fd46287e51ab6a78ff32fbcfe69ca5c7841abc57f37e6f1a822ddb2d42a627687ca1ea30ff26c7bbbd06c2acb93f431aac3af8d932707c2030ebf73cb4d
|
|
@@ -2,22 +2,8 @@ name: Danger
|
|
|
2
2
|
on:
|
|
3
3
|
pull_request:
|
|
4
4
|
types: [ opened, reopened, edited, synchronize ]
|
|
5
|
+
|
|
5
6
|
jobs:
|
|
6
7
|
danger:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
steps:
|
|
10
|
-
- name: Checkout
|
|
11
|
-
uses: actions/checkout@v3
|
|
12
|
-
with:
|
|
13
|
-
fetch-depth: 0
|
|
14
|
-
- name: Set up Ruby
|
|
15
|
-
uses: ruby/setup-ruby@v1
|
|
16
|
-
with:
|
|
17
|
-
ruby-version: 2.7
|
|
18
|
-
bundler-cache: true
|
|
19
|
-
- name: Run Danger
|
|
20
|
-
run: |
|
|
21
|
-
# the personal token is public, this is ok, base64 encode to avoid tripping Github
|
|
22
|
-
TOKEN=$(echo -n Z2hwX0xNQ3VmanBFeTBvYkZVTWh6NVNqVFFBOEUxU25abzBqRUVuaAo= | base64 --decode)
|
|
23
|
-
DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose
|
|
8
|
+
uses: ruby-grape/danger/.github/workflows/danger-run.yml@master
|
|
9
|
+
secrets: inherit
|
data/.github/workflows/lint.yml
CHANGED
data/.github/workflows/test.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -51,22 +51,6 @@ RSpec/ContextWording:
|
|
|
51
51
|
RSpec/ExampleLength:
|
|
52
52
|
Max: 12
|
|
53
53
|
|
|
54
|
-
# Offense count: 10
|
|
55
|
-
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
|
|
56
|
-
# Include: **/*_spec*rb*, **/spec/**/*
|
|
57
|
-
RSpec/FilePath:
|
|
58
|
-
Exclude:
|
|
59
|
-
- 'spec/changelog_spec.rb'
|
|
60
|
-
- 'spec/config_spec.rb'
|
|
61
|
-
- 'spec/intridea/changelog_entry_line_spec.rb'
|
|
62
|
-
- 'spec/intridea/changelog_file_spec.rb'
|
|
63
|
-
- 'spec/intridea/changelog_header_line_spec.rb'
|
|
64
|
-
- 'spec/intridea/changelog_line_parser_spec.rb'
|
|
65
|
-
- 'spec/intridea/changelog_placeholder_line_spec.rb'
|
|
66
|
-
- 'spec/intridea/changelog_spec.rb'
|
|
67
|
-
- 'spec/keep_a_changelog/changelog_spec.rb'
|
|
68
|
-
- 'spec/plugin_spec.rb'
|
|
69
|
-
|
|
70
54
|
# Offense count: 25
|
|
71
55
|
RSpec/MultipleExpectations:
|
|
72
56
|
Max: 8
|
|
@@ -103,7 +87,7 @@ RSpec/RepeatedIncludeExample:
|
|
|
103
87
|
- 'spec/intridea/changelog_entry_line_spec.rb'
|
|
104
88
|
- 'spec/intridea/changelog_header_line_spec.rb'
|
|
105
89
|
|
|
106
|
-
# Offense count:
|
|
90
|
+
# Offense count: 11
|
|
107
91
|
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
|
|
108
92
|
# Include: **/*_spec.rb
|
|
109
93
|
RSpec/SpecFilePathFormat:
|
|
@@ -119,6 +103,7 @@ RSpec/SpecFilePathFormat:
|
|
|
119
103
|
- 'spec/intridea/changelog_spec.rb'
|
|
120
104
|
- 'spec/keep_a_changelog/changelog_spec.rb'
|
|
121
105
|
- 'spec/plugin_spec.rb'
|
|
106
|
+
- 'spec/pr_metadata_spec.rb'
|
|
122
107
|
|
|
123
108
|
# Offense count: 1
|
|
124
109
|
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
+
### 0.9.1 (Next)
|
|
4
|
+
|
|
5
|
+
* Your contribution here.
|
|
6
|
+
|
|
7
|
+
### 0.9.0 (2026/10/14)
|
|
8
|
+
|
|
9
|
+
* [#72](https://github.com/dblock/danger-changelog/pull/72): Accept bot author links with a `[bot]` suffix without changing their attribution - [@dblock](https://github.com/dblock).
|
|
10
|
+
|
|
11
|
+
### 0.8.0 (2025/12/18)
|
|
12
|
+
|
|
13
|
+
* [#70](https://github.com/dblock/danger-changelog/pull/70): Workflow postreview improvments - [@numbata](https://github.com/numbata).
|
|
14
|
+
* [#68](https://github.com/dblock/danger-changelog/pull/68): Fix Danger comment workflow artifact download and script core injection - [@numbata](https://github.com/numbata).
|
|
15
|
+
* [#66](https://github.com/dblock/danger-changelog/pull/66): Update danger workflow with tokenless execution and two-workflow pattern - [@numbata](https://github.com/numbata).
|
|
16
|
+
* [#65](https://github.com/dblock/danger-changelog/pull/65): Add support for running changelog checks without GitHub API token - [@numbata](https://github.com/numbata).
|
|
17
|
+
|
|
3
18
|
### 0.7.1 (2024/04/12)
|
|
4
19
|
|
|
5
20
|
* [#63](https://github.com/dblock/danger-changelog/pull/63): Fix: report on lines that start with a - and cannot be parsed - [@dblock](https://github.com/dblock).
|
data/Dangerfile
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/doc/intridea.md
CHANGED
|
@@ -99,9 +99,12 @@ The Intridea style changelog was pioneered on the Hashie project. It has many el
|
|
|
99
99
|
```markdown
|
|
100
100
|
* Entry without a PR link - [@ivoanjo](https://github.com/ivoanjo).
|
|
101
101
|
* [#1](https://github.com/dblock/danger-changelog/pull/1): Entry with a PR link - [@dblock](https://github.com/dblock).
|
|
102
|
+
* [#2](https://github.com/dblock/danger-changelog/pull/2): Update dependencies - [@github-actions[bot]](https://github.com/apps/github-actions).
|
|
102
103
|
* Yes, this is a weird entry, but it's still valid! Also Beyoncé is welcome here, as is 松本 行弘 and our nice emojis 👍 - [@ivoanjo](https://github.com/ivoanjo).
|
|
103
104
|
```
|
|
104
105
|
|
|
106
|
+
Bot author names may end in a literal `[bot]` suffix, such as `github-actions[bot]` or `dependabot[bot]`. Keep the suffix in the attribution; links to GitHub app pages and bot profiles are supported.
|
|
107
|
+
|
|
105
108
|
❌ Entry descriptions need to start with an uppercase A-Z letter
|
|
106
109
|
|
|
107
110
|
```markdown
|
|
@@ -4,6 +4,9 @@ module Danger
|
|
|
4
4
|
module Changelog
|
|
5
5
|
# A CHANGELOG.md line represents the change entry.
|
|
6
6
|
class ChangelogEntryLine < ChangelogLine
|
|
7
|
+
AUTHOR_NAME = /[\w-]+(?:\[bot\])?/.freeze
|
|
8
|
+
AUTHOR_LINK = %r{\[@#{AUTHOR_NAME}\]\(https://github\.com/.*#{AUTHOR_NAME}\)}.freeze
|
|
9
|
+
|
|
7
10
|
def valid?
|
|
8
11
|
return validation_result.valid? if validation_result
|
|
9
12
|
|
|
@@ -12,8 +15,8 @@ module Danger
|
|
|
12
15
|
validation_result.error! 'too many parenthesis' unless balanced?(line)
|
|
13
16
|
return false if validation_result.invalid?
|
|
14
17
|
|
|
15
|
-
return true if line =~
|
|
16
|
-
return true if line =~ %r{^\*\s\[\#\d+\]\(https://github\.com/.*\d+\): [`[:upper:]].*[^.,] -
|
|
18
|
+
return true if line =~ /^\*\s[`[:upper:]].*[^.,] - #{AUTHOR_LINK}.$/
|
|
19
|
+
return true if line =~ %r{^\*\s\[\#\d+\]\(https://github\.com/.*\d+\): [`[:upper:]].*[^.,] - #{AUTHOR_LINK}.$}
|
|
17
20
|
|
|
18
21
|
validation_result.error! 'does not start with a star' unless ChangelogEntryLine.starts_with_star?(line)
|
|
19
22
|
validation_result.error! 'does not include a pull request link' unless ChangelogEntryLine.with_pr_link?(line)
|
|
@@ -22,8 +25,8 @@ module Danger
|
|
|
22
25
|
validation_result.error! 'has an extra trailing space' if ChangelogEntryLine.ends_with_space?(line)
|
|
23
26
|
validation_result.error! 'is missing a period at the end of the line' unless ChangelogEntryLine.ends_with_period?(line)
|
|
24
27
|
validation_result.error! 'has an extra period or comma at the end of the description' if
|
|
25
|
-
line =~
|
|
26
|
-
line =~ %r{^\*\s\[\#\d+\]\(https://github\.com/.*\d+\): [`[:upper:]].*[.,] -
|
|
28
|
+
line =~ /^\*\s[`[:upper:]].*[.,] - #{AUTHOR_LINK}.$/ ||
|
|
29
|
+
line =~ %r{^\*\s\[\#\d+\]\(https://github\.com/.*\d+\): [`[:upper:]].*[.,] - #{AUTHOR_LINK}.$}
|
|
27
30
|
|
|
28
31
|
false
|
|
29
32
|
end
|
|
@@ -86,7 +89,7 @@ module Danger
|
|
|
86
89
|
|
|
87
90
|
# checks whether line contains a MARKDOWN link to an author
|
|
88
91
|
def self.with_author_link?(line)
|
|
89
|
-
return true if line =~ %r{\[
|
|
92
|
+
return true if line =~ %r{\[@#{AUTHOR_NAME}\]\(https?://github\.com/.*#{AUTHOR_NAME}/?\)}
|
|
90
93
|
|
|
91
94
|
false
|
|
92
95
|
end
|
data/lib/changelog/plugin.rb
CHANGED
|
@@ -96,12 +96,27 @@ module Danger
|
|
|
96
96
|
|
|
97
97
|
private
|
|
98
98
|
|
|
99
|
+
def pr_metadata
|
|
100
|
+
Danger::Changelog::PRMetadata.from_event_file(ENV.fetch('GITHUB_EVENT_PATH', nil)) ||
|
|
101
|
+
Danger::Changelog::PRMetadata.from_github_plugin(github_plugin) ||
|
|
102
|
+
Danger::Changelog::PRMetadata.fallback
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def github_plugin
|
|
106
|
+
github
|
|
107
|
+
rescue NoMethodError
|
|
108
|
+
# github plugin is not available in dry_run mode (LocalOnly request source)
|
|
109
|
+
nil
|
|
110
|
+
end
|
|
111
|
+
|
|
99
112
|
def warn_update_changelog
|
|
113
|
+
example = Danger::Changelog::ChangelogEntryLine.example(pr_metadata)
|
|
114
|
+
|
|
100
115
|
markdown <<~MARKDOWN
|
|
101
116
|
Here's an example of a #{filename} entry:
|
|
102
117
|
|
|
103
118
|
```markdown
|
|
104
|
-
#{
|
|
119
|
+
#{example}
|
|
105
120
|
```
|
|
106
121
|
MARKDOWN
|
|
107
122
|
warn "Unless you're refactoring existing code or improving documentation, please update #{filename}.", sticky: false
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module Danger
|
|
2
|
+
module Changelog
|
|
3
|
+
class PRMetadata
|
|
4
|
+
EXAMPLE_PR_JSON = {
|
|
5
|
+
'number' => 123,
|
|
6
|
+
'html_url' => 'https://github.com/org/repo/pull/123'
|
|
7
|
+
}.freeze
|
|
8
|
+
EXAMPLE_TITLE = 'Your contribution'.freeze
|
|
9
|
+
EXAMPLE_AUTHOR = 'username'.freeze
|
|
10
|
+
|
|
11
|
+
attr_reader :pr_json, :pr_title, :pr_author
|
|
12
|
+
|
|
13
|
+
def initialize(pr_json:, pr_title:, pr_author:)
|
|
14
|
+
@pr_json = pr_json
|
|
15
|
+
@pr_title = pr_title
|
|
16
|
+
@pr_author = pr_author
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Attempt to fetch PR metadata from the GitHub plugin.
|
|
20
|
+
# Returns nil if GitHub API access fails for any reason (authentication, rate limiting, network errors, etc).
|
|
21
|
+
# This allows the fallback chain to proceed to other sources like GITHUB_EVENT_PATH.
|
|
22
|
+
def self.from_github_plugin(github = nil)
|
|
23
|
+
return nil unless github
|
|
24
|
+
|
|
25
|
+
begin
|
|
26
|
+
pr_json = github.pr_json
|
|
27
|
+
return nil unless pr_json
|
|
28
|
+
|
|
29
|
+
new(
|
|
30
|
+
pr_json: pr_json,
|
|
31
|
+
pr_title: github.pr_title,
|
|
32
|
+
pr_author: github.pr_author
|
|
33
|
+
)
|
|
34
|
+
rescue Octokit::Error => e
|
|
35
|
+
warn "[Changelog::PRMetadata] GitHub API request failed (#{e.class}: #{e.message}). Falling back to other PR metadata sources."
|
|
36
|
+
nil
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.from_event_file(path)
|
|
41
|
+
return nil unless path
|
|
42
|
+
return nil unless File.exist?(path)
|
|
43
|
+
|
|
44
|
+
event = JSON.parse(File.read(path))
|
|
45
|
+
pr = event['pull_request']
|
|
46
|
+
return nil unless pr
|
|
47
|
+
|
|
48
|
+
new(
|
|
49
|
+
pr_json: pr,
|
|
50
|
+
pr_title: pr['title'],
|
|
51
|
+
pr_author: pr.dig('user', 'login')
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.fallback
|
|
56
|
+
new(
|
|
57
|
+
pr_json: EXAMPLE_PR_JSON,
|
|
58
|
+
pr_title: EXAMPLE_TITLE,
|
|
59
|
+
pr_author: EXAMPLE_AUTHOR
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/danger_plugin.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'json'
|
|
1
2
|
require 'changelog/changelog_line/changelog_entry_line'
|
|
2
3
|
require 'changelog/changelog_line/changelog_header_line'
|
|
3
4
|
require 'changelog/changelog_line/changelog_line_parser'
|
|
@@ -6,4 +7,5 @@ require 'changelog/changelog_line/changelog_line'
|
|
|
6
7
|
require 'changelog/changelog_file'
|
|
7
8
|
require 'changelog/parsers'
|
|
8
9
|
require 'changelog/config'
|
|
10
|
+
require 'changelog/pr_metadata'
|
|
9
11
|
require 'changelog/plugin'
|
data/spec/changelog_spec.rb
CHANGED
|
@@ -31,7 +31,8 @@ describe Danger::Changelog do
|
|
|
31
31
|
expect(subject).to be false
|
|
32
32
|
expect(status_report[:errors]).to eq []
|
|
33
33
|
expect(status_report[:warnings]).to eq ["Unless you're refactoring existing code or improving documentation, please update CHANGELOG.md."]
|
|
34
|
-
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/.+\)\.})
|
|
35
36
|
end
|
|
36
37
|
end
|
|
37
38
|
|
|
@@ -64,7 +65,8 @@ describe Danger::Changelog do
|
|
|
64
65
|
expect(subject).to be false
|
|
65
66
|
expect(status_report[:errors]).to eq []
|
|
66
67
|
expect(status_report[:warnings]).to eq ["Unless you're refactoring existing code or improving documentation, please update #{changelog.filename}."]
|
|
67
|
-
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/.+\)\.})
|
|
68
70
|
end
|
|
69
71
|
end
|
|
70
72
|
|
|
@@ -113,5 +113,62 @@ describe Danger::Changelog::ChangelogEntryLine do
|
|
|
113
113
|
expect(described_class.example(github)).to eq '* [#123](https://github.com/dblock/danger-changelog/pull/123): Test - [@dblock](https://github.com/dblock).'
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
|
+
|
|
117
|
+
context 'with a bot author' do
|
|
118
|
+
let(:pr_title) { 'Update dependencies' }
|
|
119
|
+
|
|
120
|
+
%w[github-actions[bot] dependabot[bot]].each do |author|
|
|
121
|
+
it "generates a valid example for #{author}" do
|
|
122
|
+
allow(github).to receive(:pr_author).and_return(author)
|
|
123
|
+
example = described_class.example(github)
|
|
124
|
+
expect(example).to include("[@#{author}](https://github.com/#{author})")
|
|
125
|
+
expect(described_class.new(example).valid?).to be true
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
context 'with bot attribution' do
|
|
132
|
+
[
|
|
133
|
+
'[@github-actions[bot]](https://github.com/apps/github-actions)',
|
|
134
|
+
'[@dependabot[bot]](https://github.com/dependabot[bot])',
|
|
135
|
+
'[@renovate[bot]](https://github.com/apps/renovate)'
|
|
136
|
+
].each do |author_link|
|
|
137
|
+
context author_link do
|
|
138
|
+
[
|
|
139
|
+
"* Update dependencies - #{author_link}.",
|
|
140
|
+
"* [#1](https://github.com/dblock/danger-changelog/pull/1): Update dependencies - #{author_link}."
|
|
141
|
+
].each do |line|
|
|
142
|
+
it_behaves_like 'validates as changelog entry line', line
|
|
143
|
+
it_behaves_like 'valid changelog entry line', line
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it 'recognizes an author link on its own' do
|
|
147
|
+
expect(described_class.with_author_link?(author_link)).to be true
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
['.', ','].each do |punctuation|
|
|
151
|
+
it "reports an extra #{punctuation} at the end of the description" do
|
|
152
|
+
entry = described_class.new("* Update dependencies#{punctuation} - #{author_link}.\n")
|
|
153
|
+
expect(entry.valid?).to be false
|
|
154
|
+
expect(entry.validation_result.errors)
|
|
155
|
+
.to include('has an extra period or comma at the end of the description')
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it_behaves_like 'invalid changelog entry line', "* Update dependencies - #{author_link}"
|
|
160
|
+
it_behaves_like 'invalid changelog entry line', "* Update dependencies - #{author_link}. \n"
|
|
161
|
+
it_behaves_like 'invalid changelog entry line', "* Update dependencies - #{author_link.sub('https:', 'http:')}."
|
|
162
|
+
it_behaves_like 'invalid changelog entry line', "* Update dependencies - #{author_link.sub('github.com', 'gitlab.com')}."
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
%w[github-actions[Bot] github-actions[bot]extra github-actions[bot][bot] github-actions[]].each do |author|
|
|
167
|
+
it "rejects malformed bot suffix in #{author}" do
|
|
168
|
+
link = "[@#{author}](https://github.com/apps/github-actions)"
|
|
169
|
+
expect(described_class.with_author_link?(link)).to be false
|
|
170
|
+
expect(described_class.new("* Update dependencies - #{link}.").valid?).to be false
|
|
171
|
+
end
|
|
172
|
+
end
|
|
116
173
|
end
|
|
117
174
|
end
|
|
@@ -6,6 +6,15 @@ describe Danger::Changelog::ChangelogFile do
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
describe 'with the default format checker' do
|
|
9
|
+
context 'with bot authors' do
|
|
10
|
+
let(:filename) { File.expand_path('fixtures/bot_authors.md', __dir__) }
|
|
11
|
+
|
|
12
|
+
it 'accepts bot entries in a complete changelog' do
|
|
13
|
+
expect(subject.bad_lines).to eq []
|
|
14
|
+
expect(subject.global_failures?).to be false
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
9
18
|
context 'minimal example' do
|
|
10
19
|
let(:filename) { File.expand_path('fixtures/minimal.md', __dir__) }
|
|
11
20
|
|
|
@@ -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
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: danger-changelog
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dblock
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-10-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: danger-plugin-api
|
|
@@ -31,6 +31,7 @@ executables: []
|
|
|
31
31
|
extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
|
33
33
|
files:
|
|
34
|
+
- ".github/workflows/danger-comment.yml"
|
|
34
35
|
- ".github/workflows/danger.yml"
|
|
35
36
|
- ".github/workflows/lint.yml"
|
|
36
37
|
- ".github/workflows/test.yml"
|
|
@@ -66,6 +67,7 @@ files:
|
|
|
66
67
|
- lib/changelog/parsers/keep_a_changelog.rb
|
|
67
68
|
- lib/changelog/parsers/validation_result.rb
|
|
68
69
|
- lib/changelog/plugin.rb
|
|
70
|
+
- lib/changelog/pr_metadata.rb
|
|
69
71
|
- lib/danger_changelog.rb
|
|
70
72
|
- lib/danger_plugin.rb
|
|
71
73
|
- spec/changelog_spec.rb
|
|
@@ -76,6 +78,7 @@ files:
|
|
|
76
78
|
- spec/intridea/changelog_line_parser_spec.rb
|
|
77
79
|
- spec/intridea/changelog_placeholder_line_spec.rb
|
|
78
80
|
- spec/intridea/changelog_spec.rb
|
|
81
|
+
- spec/intridea/fixtures/bot_authors.md
|
|
79
82
|
- spec/intridea/fixtures/customized.md
|
|
80
83
|
- spec/intridea/fixtures/dates.md
|
|
81
84
|
- spec/intridea/fixtures/extra_trailing_space.md
|
|
@@ -91,6 +94,7 @@ files:
|
|
|
91
94
|
- spec/keep_a_changelog/fixtures/lines_with_links.md
|
|
92
95
|
- spec/keep_a_changelog/fixtures/missing_a_version_header.md
|
|
93
96
|
- spec/plugin_spec.rb
|
|
97
|
+
- spec/pr_metadata_spec.rb
|
|
94
98
|
- spec/spec_helper.rb
|
|
95
99
|
- spec/support/shared/changelog.rb
|
|
96
100
|
homepage: https://github.com/dblock/danger-changelog
|
|
@@ -113,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
113
117
|
- !ruby/object:Gem::Version
|
|
114
118
|
version: '0'
|
|
115
119
|
requirements: []
|
|
116
|
-
rubygems_version: 3.
|
|
120
|
+
rubygems_version: 3.5.16
|
|
117
121
|
signing_key:
|
|
118
122
|
specification_version: 4
|
|
119
123
|
summary: A danger.systems plugin that is OCD about your CHANGELOG.
|