danger-changelog 0.7.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e13e8dd279d1b68b2703760929b9c2ab4420db154c5420f27c8f6e6a25834719
4
- data.tar.gz: a6d5eb4a335dc87df1d586f7f644da0965bb88f7040049797684ac315b3c1ee8
3
+ metadata.gz: 022eb51f3fa39d8abf589c65dd0c6ebabb20404289c3181447d26417a5ea7a52
4
+ data.tar.gz: b20da654d12c3cb01061eb4dc329cf9b8cf5f7f83b2736798679fb551334458d
5
5
  SHA512:
6
- metadata.gz: 7ad171e3366fafab0a20cbf65b5a67e8b77d1fd0d0833f8c45d2668b7e796d51556e939c337ecb08ea67f23462a13902c31034a315102a596747a08e48ef8699
7
- data.tar.gz: d191579322f931bbc1e4848cc7c4252c3a5a617a1e3291f9c96d11ceb2171156b487b9879ff5f6631a3de8c44c10b1388dcf2d8b1ce491588cb4248605dc0b7d
6
+ metadata.gz: 4ce70cd1afc862965c8abcf61a6626a29dc726d0a9cd8c6646f4898bde775024e088cb38b1725b88d3481f19cd11efca477094930d5e1442a113344c242ffb9a
7
+ data.tar.gz: cfae9454953b6fd99ebf1187f74ecaec27d6fd2e44e03c2028c4b7b2632e5a27a0c24bd3fffd7a743bdf3b5dbf4ac96100bb0798ba2c93140fd7a3503fa96a0d
@@ -0,0 +1,10 @@
1
+ name: Danger Comment
2
+ on:
3
+ workflow_run:
4
+ workflows: [Danger]
5
+ types: [completed]
6
+
7
+ jobs:
8
+ comment:
9
+ uses: ruby-grape/danger/.github/workflows/danger-comment.yml@master
10
+ secrets: inherit
@@ -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
- name: Danger
8
- runs-on: ubuntu-latest
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
@@ -10,7 +10,7 @@ jobs:
10
10
  - name: Set up Ruby
11
11
  uses: ruby/setup-ruby@v1
12
12
  with:
13
- ruby-version: 2.7
13
+ ruby-version: 3.3
14
14
  bundler-cache: true
15
15
  - name: RuboCop
16
16
  run: bundle exec rubocop
@@ -7,7 +7,7 @@ jobs:
7
7
  strategy:
8
8
  fail-fast: false
9
9
  matrix:
10
- ruby-version: [ '2.7', '3.1', '3.3' ]
10
+ ruby-version: [ '2.7', '3.1', '3.3', '3.4', 'head' ]
11
11
  steps:
12
12
  - name: Checkout
13
13
  uses: actions/checkout@v3
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: 10
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,12 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.8.0 (2025/12/18)
4
+
5
+ * [#70](https://github.com/dblock/danger-changelog/pull/70): Workflow postreview improvments - [@numbata](https://github.com/numbata).
6
+ * [#68](https://github.com/dblock/danger-changelog/pull/68): Fix Danger comment workflow artifact download and script core injection - [@numbata](https://github.com/numbata).
7
+ * [#66](https://github.com/dblock/danger-changelog/pull/66): Update danger workflow with tokenless execution and two-workflow pattern - [@numbata](https://github.com/numbata).
8
+ * [#65](https://github.com/dblock/danger-changelog/pull/65): Add support for running changelog checks without GitHub API token - [@numbata](https://github.com/numbata).
9
+
3
10
  ### 0.7.1 (2024/04/12)
4
11
 
5
12
  * [#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
@@ -1,4 +1,4 @@
1
1
  # danger.systems
2
2
 
3
- toc.check!
4
- changelog.check!
3
+ # Import ruby-grape-danger for automatic danger report export
4
+ danger.import_dangerfile(gem: 'ruby-grape-danger')
data/Gemfile CHANGED
@@ -15,5 +15,6 @@ group :development, :test do
15
15
  gem 'rubocop', '~> 1.63.1'
16
16
  gem 'rubocop-rake'
17
17
  gem 'rubocop-rspec'
18
+ gem 'ruby-grape-danger'
18
19
  gem 'yard', '~> 0.9.11'
19
20
  end
data/README.md CHANGED
@@ -55,7 +55,7 @@ changelog.filename = 'CHANGES.md'
55
55
 
56
56
  ### changelog.format
57
57
 
58
- Set the format of the CHANGELOG file.
58
+ Set the format of the CHANGELOG file.
59
59
 
60
60
  ```ruby
61
61
  changelog.format = :keep_a_changelog
@@ -1,3 +1,3 @@
1
1
  module Changelog
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
@@ -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
- #{Danger::Changelog::ChangelogEntryLine.example(github)}
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'
@@ -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 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"]
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 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"]
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
 
@@ -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,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-changelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dblock
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-04-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: danger-plugin-api
@@ -31,6 +30,7 @@ executables: []
31
30
  extensions: []
32
31
  extra_rdoc_files: []
33
32
  files:
33
+ - ".github/workflows/danger-comment.yml"
34
34
  - ".github/workflows/danger.yml"
35
35
  - ".github/workflows/lint.yml"
36
36
  - ".github/workflows/test.yml"
@@ -66,6 +66,7 @@ files:
66
66
  - lib/changelog/parsers/keep_a_changelog.rb
67
67
  - lib/changelog/parsers/validation_result.rb
68
68
  - lib/changelog/plugin.rb
69
+ - lib/changelog/pr_metadata.rb
69
70
  - lib/danger_changelog.rb
70
71
  - lib/danger_plugin.rb
71
72
  - spec/changelog_spec.rb
@@ -91,6 +92,7 @@ files:
91
92
  - spec/keep_a_changelog/fixtures/lines_with_links.md
92
93
  - spec/keep_a_changelog/fixtures/missing_a_version_header.md
93
94
  - spec/plugin_spec.rb
95
+ - spec/pr_metadata_spec.rb
94
96
  - spec/spec_helper.rb
95
97
  - spec/support/shared/changelog.rb
96
98
  homepage: https://github.com/dblock/danger-changelog
@@ -98,7 +100,6 @@ licenses:
98
100
  - MIT
99
101
  metadata:
100
102
  rubygems_mfa_required: 'true'
101
- post_install_message:
102
103
  rdoc_options: []
103
104
  require_paths:
104
105
  - lib
@@ -113,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  - !ruby/object:Gem::Version
114
115
  version: '0'
115
116
  requirements: []
116
- rubygems_version: 3.3.7
117
- signing_key:
117
+ rubygems_version: 3.6.8
118
118
  specification_version: 4
119
119
  summary: A danger.systems plugin that is OCD about your CHANGELOG.
120
120
  test_files: []