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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03270bfff2f0983bbf17c710358dfb6850d727f28afa131593deaed8c6824c0f
4
- data.tar.gz: 8723e715d8f3f357e3d72d8e181c3d9174085de6c32ea79a87fbdbcf61160085
3
+ metadata.gz: 022eb51f3fa39d8abf589c65dd0c6ebabb20404289c3181447d26417a5ea7a52
4
+ data.tar.gz: b20da654d12c3cb01061eb4dc329cf9b8cf5f7f83b2736798679fb551334458d
5
5
  SHA512:
6
- metadata.gz: 21fe62c2ce3142983ad12dcdee2dca0e3e1246ed376924619dba25151bd4556608f978d1e1b2225a9cfc5ae548eca5302e48a589b1e70711fafc01f759a09d2e
7
- data.tar.gz: 02c819d7ec4819b83c76c146778beb44f9a9c716726113d41d5cbaee70523ca91ed0c137b5dd92c52540b34a1e24faaa8dab846f73ea72c4cbd73a99e2232d22
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' ]
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.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  AllCops:
2
+ NewCops: enable
2
3
  Exclude:
3
4
  - vendor/**/*
4
5
 
@@ -11,7 +12,7 @@ Style/Documentation:
11
12
  Metrics:
12
13
  Enabled: false
13
14
 
14
- Metrics/LineLength:
15
+ Layout/LineLength:
15
16
  Max: 256
16
17
 
17
18
  Style/FrozenStringLiteralComment:
@@ -19,9 +20,12 @@ Style/FrozenStringLiteralComment:
19
20
 
20
21
  Naming/PredicateName:
21
22
  Enabled: true
22
- NameWhitelist:
23
+ AllowedMethods:
23
24
  - is_a?
24
25
  - have_you_updated_changelog?
25
26
  - is_changelog_format_correct?
26
27
 
27
28
  inherit_from: .rubocop_todo.yml
29
+ require:
30
+ - rubocop-rake
31
+ - rubocop-rspec
data/.rubocop_todo.yml CHANGED
@@ -1,7 +1,118 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-05-08 17:23:39 -0400 using RuboCop version 0.73.0.
3
+ # on 2024-04-12 18:13:29 UTC using RuboCop version 1.63.1.
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: 1
10
+ # Configuration parameters: Severity, Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'danger-changelog.gemspec'
15
+
16
+ # Offense count: 3
17
+ # This cop supports safe autocorrection (--autocorrect).
18
+ # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
19
+ # URISchemes: http, https
20
+ Layout/LineLength:
21
+ Exclude:
22
+ - 'spec/intridea/changelog_spec.rb'
23
+
24
+ # Offense count: 1
25
+ # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
26
+ Lint/DuplicateBranch:
27
+ Exclude:
28
+ - 'lib/changelog/plugin.rb'
29
+
30
+ # Offense count: 2
31
+ Lint/MixedRegexpCaptureTypes:
32
+ Exclude:
33
+ - 'lib/changelog/changelog_line/changelog_header_line.rb'
34
+
35
+ # Offense count: 30
36
+ # Configuration parameters: Prefixes, AllowedPatterns.
37
+ # Prefixes: when, with, without
38
+ RSpec/ContextWording:
39
+ Exclude:
40
+ - 'spec/changelog_spec.rb'
41
+ - 'spec/config_spec.rb'
42
+ - 'spec/intridea/changelog_entry_line_spec.rb'
43
+ - 'spec/intridea/changelog_file_spec.rb'
44
+ - 'spec/intridea/changelog_header_line_spec.rb'
45
+ - 'spec/intridea/changelog_line_parser_spec.rb'
46
+ - 'spec/intridea/changelog_spec.rb'
47
+ - 'spec/keep_a_changelog/changelog_spec.rb'
48
+
49
+ # Offense count: 9
50
+ # Configuration parameters: CountAsOne.
51
+ RSpec/ExampleLength:
52
+ Max: 12
53
+
54
+ # Offense count: 25
55
+ RSpec/MultipleExpectations:
56
+ Max: 8
57
+
58
+ # Offense count: 44
59
+ # Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
60
+ # SupportedStyles: always, named_only
61
+ RSpec/NamedSubject:
62
+ Exclude:
63
+ - 'spec/changelog_spec.rb'
64
+ - 'spec/intridea/changelog_file_spec.rb'
65
+ - 'spec/intridea/changelog_spec.rb'
66
+ - 'spec/keep_a_changelog/changelog_spec.rb'
67
+ - 'spec/plugin_spec.rb'
68
+
69
+ # Offense count: 32
70
+ # Configuration parameters: AllowedGroups.
71
+ RSpec/NestedGroups:
72
+ Max: 7
73
+
74
+ # Offense count: 2
75
+ RSpec/RepeatedExampleGroupBody:
76
+ Exclude:
77
+ - 'spec/intridea/changelog_header_line_spec.rb'
78
+
79
+ # Offense count: 2
80
+ RSpec/RepeatedExampleGroupDescription:
81
+ Exclude:
82
+ - 'spec/intridea/changelog_header_line_spec.rb'
83
+
84
+ # Offense count: 4
85
+ RSpec/RepeatedIncludeExample:
86
+ Exclude:
87
+ - 'spec/intridea/changelog_entry_line_spec.rb'
88
+ - 'spec/intridea/changelog_header_line_spec.rb'
89
+
90
+ # Offense count: 11
91
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
92
+ # Include: **/*_spec.rb
93
+ RSpec/SpecFilePathFormat:
94
+ Exclude:
95
+ - '**/spec/routing/**/*'
96
+ - 'spec/changelog_spec.rb'
97
+ - 'spec/config_spec.rb'
98
+ - 'spec/intridea/changelog_entry_line_spec.rb'
99
+ - 'spec/intridea/changelog_file_spec.rb'
100
+ - 'spec/intridea/changelog_header_line_spec.rb'
101
+ - 'spec/intridea/changelog_line_parser_spec.rb'
102
+ - 'spec/intridea/changelog_placeholder_line_spec.rb'
103
+ - 'spec/intridea/changelog_spec.rb'
104
+ - 'spec/keep_a_changelog/changelog_spec.rb'
105
+ - 'spec/plugin_spec.rb'
106
+ - 'spec/pr_metadata_spec.rb'
107
+
108
+ # Offense count: 1
109
+ # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
110
+ RSpec/VerifiedDoubles:
111
+ Exclude:
112
+ - 'spec/intridea/changelog_entry_line_spec.rb'
113
+
114
+ # Offense count: 1
115
+ # This cop supports safe autocorrection (--autocorrect).
116
+ Rake/Desc:
117
+ Exclude:
118
+ - 'Rakefile'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
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
+
10
+ ### 0.7.1 (2024/04/12)
11
+
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).
13
+ * [#64](https://github.com/dblock/danger-changelog/pull/64): Upgraded to RuboCop 1.63.1 - [@dblock](https://github.com/dblock).
14
+
3
15
  ### 0.7.0 (2023/11/21)
4
16
 
5
17
  * [#62](https://github.com/dblock/danger-changelog/pull/62): Migrate CI from Travis to GitHub Actions - [@mathroule](https://github.com/mathroule).
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
@@ -10,8 +10,11 @@ group :development, :test do
10
10
  gem 'guard-rspec', '~> 4.7'
11
11
  gem 'listen', '3.0.7'
12
12
  gem 'pry'
13
- gem 'rake', '~> 10.0'
13
+ gem 'rake', '~> 13.2.1'
14
14
  gem 'rspec', '~> 3.4'
15
- gem 'rubocop', '~> 0.73.0'
15
+ gem 'rubocop', '~> 1.63.1'
16
+ gem 'rubocop-rake'
17
+ gem 'rubocop-rspec'
18
+ gem 'ruby-grape-danger'
16
19
  gem 'yard', '~> 0.9.11'
17
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,6 +1,6 @@
1
1
  lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'changelog/gem_version.rb'
3
+ require 'changelog/gem_version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'danger-changelog'
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
14
14
 
15
15
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
17
  spec.require_paths = ['lib']
19
18
 
20
19
  spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
20
+ spec.metadata['rubygems_mfa_required'] = 'true'
21
21
  end
@@ -12,8 +12,8 @@ module Danger
12
12
  validation_result.error! 'too many parenthesis' unless balanced?(line)
13
13
  return false if validation_result.invalid?
14
14
 
15
- return true if line =~ %r{^\*\s[\`[:upper:]].*[^.,] \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\).$}
16
- return true if line =~ %r{^\*\s\[\#\d+\]\(https:\/\/github\.com\/.*\d+\)\: [\`[:upper:]].*[^.,] \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\).$}
15
+ return true if line =~ %r{^\*\s[`[:upper:]].*[^.,] - \[@[\w\d\-_]+\]\(https://github\.com/.*[\w\d\-_]+\).$}
16
+ return true if line =~ %r{^\*\s\[\#\d+\]\(https://github\.com/.*\d+\): [`[:upper:]].*[^.,] - \[@[\w\d\-_]+\]\(https://github\.com/.*[\w\d\-_]+\).$}
17
17
 
18
18
  validation_result.error! 'does not start with a star' unless ChangelogEntryLine.starts_with_star?(line)
19
19
  validation_result.error! 'does not include a pull request link' unless ChangelogEntryLine.with_pr_link?(line)
@@ -22,8 +22,8 @@ module Danger
22
22
  validation_result.error! 'has an extra trailing space' if ChangelogEntryLine.ends_with_space?(line)
23
23
  validation_result.error! 'is missing a period at the end of the line' unless ChangelogEntryLine.ends_with_period?(line)
24
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\-\_]+\).$}
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
27
 
28
28
  false
29
29
  end
@@ -72,21 +72,21 @@ module Danger
72
72
 
73
73
  # checks whether line contains a MARKDOWN link to a PR
74
74
  def self.with_pr_link?(line)
75
- return true if line =~ %r{\[\#\d+\]\(http[s]?:\/\/github\.com\/.*\d+[\/]?\)}
75
+ return true if line =~ %r{\[\#\d+\]\(https?://github\.com/.*\d+/?\)}
76
76
 
77
77
  false
78
78
  end
79
79
 
80
80
  # checks whether line contains a capitalized Text, treated as a description
81
81
  def self.with_changelog_description?(line)
82
- return true if line =~ /[\`[:upper:]].*/
82
+ return true if line =~ /[`[:upper:]].*/
83
83
 
84
84
  false
85
85
  end
86
86
 
87
87
  # checks whether line contains a MARKDOWN link to an author
88
88
  def self.with_author_link?(line)
89
- return true if line =~ %r{\[\@[\w\d\-\_]+\]\(http[s]?:\/\/github\.com\/.*[\w\d\-\_]+[\/]?\)}
89
+ return true if line =~ %r{\[@[\w\d\-_]+\]\(https?://github\.com/.*[\w\d\-_]+/?\)}
90
90
 
91
91
  false
92
92
  end
@@ -2,8 +2,8 @@ module Danger
2
2
  module Changelog
3
3
  # A CHANGELOG.md line represents the version header.
4
4
  class ChangelogHeaderLine < ChangelogLine
5
- OPEN_PARENS = /[\(\[\{]?/.freeze
6
- CLOSE_PARENS = /[\)\]\}]?/.freeze
5
+ OPEN_PARENS = /[(\[{]?/.freeze
6
+ CLOSE_PARENS = /[)\]}]?/.freeze
7
7
 
8
8
  HASHES = /\#{1,4}/.freeze
9
9
  SEMVER = /(?<semver>(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/.freeze
@@ -12,9 +12,9 @@ module Danger
12
12
  def valid?
13
13
  stripped_line = line.strip
14
14
 
15
- m = stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}[\w\s\:]*#{CLOSE_PARENS}$/) # title
15
+ m = stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}[\w\s:]*#{CLOSE_PARENS}$/) # title
16
16
  m ||= stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}#{SEMVER}#{CLOSE_PARENS}$/) # semver only
17
- m ||= stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}#{SEMVER}#{CLOSE_PARENS}[\s\-]+#{OPEN_PARENS}(#{ISO8601_DATETIME}|\w*)#{CLOSE_PARENS}$/) # semver and ISO 8601 date & time or next version description
17
+ m ||= stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}#{SEMVER}#{CLOSE_PARENS}[\s-]+#{OPEN_PARENS}(#{ISO8601_DATETIME}|\w*)#{CLOSE_PARENS}$/) # semver and ISO 8601 date & time or next version description
18
18
 
19
19
  !m.nil? && balanced?(stripped_line)
20
20
  end
@@ -6,8 +6,7 @@ module Danger
6
6
  PAIRED = /\(#{NON_DELIMITERS}\)|\{#{NON_DELIMITERS}\}|\[#{NON_DELIMITERS}\]/.freeze
7
7
  DELIMITER = /[(){}\[\]]/.freeze
8
8
 
9
- attr_accessor :line
10
- attr_accessor :validation_result
9
+ attr_accessor :line, :validation_result
11
10
 
12
11
  def initialize(line)
13
12
  self.line = line
@@ -10,7 +10,7 @@ module Danger
10
10
  ignore_files
11
11
  ].freeze
12
12
 
13
- ACCESSORS = ATTRIBUTES.map { |name| "#{name}=".to_sym }
13
+ ACCESSORS = ATTRIBUTES.map { |name| :"#{name}=" }
14
14
 
15
15
  DELEGATORS = ATTRIBUTES + ACCESSORS
16
16
 
@@ -1,3 +1,3 @@
1
1
  module Changelog
2
- VERSION = '0.7.0'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
@@ -4,9 +4,9 @@ module Danger
4
4
  class IntrideaFormat < Base
5
5
  def bad_line_message(filename)
6
6
  "One of the lines below found in #{filename} doesn't match the " \
7
- '[expected format](https://github.com/dblock/danger-changelog/blob/master/README.md#whats-a-correctly-formatted-changelog-file). ' \
8
- 'Please make it look like the other lines, pay attention to version ' \
9
- 'numbers, periods, spaces and date formats.'
7
+ '[expected format](https://github.com/dblock/danger-changelog/blob/master/README.md#whats-a-correctly-formatted-changelog-file). ' \
8
+ 'Please make it look like the other lines, pay attention to version ' \
9
+ 'numbers, periods, spaces and date formats.'
10
10
  end
11
11
 
12
12
  def parse(filename)
@@ -17,7 +17,10 @@ module Danger
17
17
 
18
18
  changelog_line = ChangelogLineParser.parse(line)
19
19
 
20
- if changelog_line.nil? || changelog_line.invalid?
20
+ if changelog_line.nil?
21
+ notify_of_bad_line line, 'cannot be parsed'
22
+ next
23
+ elsif changelog_line.invalid?
21
24
  detail = changelog_line.validation_result.to_s if changelog_line.validation_result&.invalid?
22
25
  notify_of_bad_line line, detail
23
26
  next
@@ -4,14 +4,14 @@ module Danger
4
4
  class KeepAChangelog < Base
5
5
  def bad_line_message(filename)
6
6
  "One of the lines below found in #{filename} doesn't match the " \
7
- '[expected format](https://keepachangelog.com).'
7
+ '[expected format](https://keepachangelog.com).'
8
8
  end
9
9
 
10
10
  def parse(filename)
11
11
  blocks = parse_into_blocks(File.open(filename).each_line)
12
12
 
13
13
  if contains_header_block?(blocks.first)
14
- blocks = blocks[1..-1]
14
+ blocks = blocks[1..]
15
15
  else
16
16
  notify_of_global_failure(
17
17
  'The changelog is missing the version header for the Keep A ' \
@@ -61,9 +61,9 @@ module Danger
61
61
  return false unless block
62
62
  return false unless block.first == '# Changelog'
63
63
 
64
- regex = %r{All notable changes to this project will be documented in this file. The format is based on \[Keep a Changelog\]\(https://keepachangelog.com/en/\d\.\d\.\d/\), and this project adheres to \[Semantic Versioning\]\(https:\/\/semver.org\/spec\/v2.0.0.html\).}
64
+ regex = %r{All notable changes to this project will be documented in this file. The format is based on \[Keep a Changelog\]\(https://keepachangelog.com/en/\d\.\d\.\d/\), and this project adheres to \[Semantic Versioning\]\(https://semver.org/spec/v2.0.0.html\).}
65
65
 
66
- block_content = block[1..-1].join(' ')
66
+ block_content = block[1..].join(' ')
67
67
 
68
68
  regex.match?(block_content)
69
69
  end
@@ -73,7 +73,7 @@ module Danger
73
73
  end
74
74
 
75
75
  def markdown_list_item_or_continuation?(line)
76
- /^(?:[\*-]\s| )/.match?(line)
76
+ /^(?:[*-]\s| )/.match?(line)
77
77
  end
78
78
  end
79
79
  end
@@ -28,7 +28,7 @@ module Danger
28
28
  end
29
29
 
30
30
  # Run all checks.
31
- # @param format [Symbol] the format to check against
31
+ # @param parser [Symbol] the parser to check with
32
32
  # @return [Boolean] true when the check passes
33
33
  def check(parser = Danger::Changelog::Config.format)
34
34
  warn '[DEPRECATION] `check` is deprecated. Set format with `.format` and use `check!` instead.'
@@ -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'