Skip to content

Commit

Permalink
Apply some changelog format tests to changelog directory
Browse files Browse the repository at this point in the history
This commit applies some changelog format tests to changelog directory
to prevent the following error when running `rake changelog:merge`.

```console
% bundle exec rake changelog:merge
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass

  entry.match(/\. \((?<contributors>.+)\)\n/)[:contributors].split(',')
                                             ^^^^^^^^^^^^^^^
/Users/koic/src/github.com/rubocop/rubocop-minitest/tasks/changelog.rb:130:in `block in contributors'
/Users/koic/src/github.com/rubocop/rubocop-minitest/tasks/changelog.rb:129:in `each'
/Users/koic/src/github.com/rubocop/rubocop-minitest/tasks/changelog.rb:129:in `flat_map'
/Users/koic/src/github.com/rubocop/rubocop-minitest/tasks/changelog.rb:129:in `contributors'
/Users/koic/src/github.com/rubocop/rubocop-minitest/tasks/changelog.rb:123:in `new_contributor_lines'
/Users/koic/src/github.com/rubocop/rubocop-minitest/tasks/changelog.rb:105:in `merge_content'
/Users/koic/src/github.com/rubocop/rubocop-minitest/tasks/changelog.rb:94:in `merge!'
tasks/changelog.rake:21:in `block (2 levels) in <top (required)>'
/Users/koic/.rbenv/versions/3.1.2/bin/bundle:25:in `load'
/Users/koic/.rbenv/versions/3.1.2/bin/bundle:25:in `<main>'
Tasks: TOP => changelog:merge
(See full trace by running task with --trace)
```

This error occurs when there is no period in the changelog format. It is because the tests
applied to CHANGELOG.md were not applied to the changelog directory.
  • Loading branch information
koic committed Nov 12, 2022
1 parent c4f9d8b commit 06bd6bf
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions test/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class ProjectTest < Minitest::Test
def setup
@issues = []
@bodies = []

load_changelog
load_feature_entries
end
Expand Down Expand Up @@ -133,18 +136,24 @@ def load_changelog
@lines = @changelog.each_line
@entries = @lines.grep(/^\*/).map(&:chomp)

@issues = @entries.map do |entry|
entry.match(/\[(?<number>[#\d]+)\]\((?<url>[^)]+)\)/)
end.compact

@bodies = @entries.map do |entry|
entry.gsub(/`[^`]+`/, '``').sub(/^\*\s*(?:\[.+?\):\s*)?/, '').sub(/\s*\([^)]+\)$/, '')
end
prepare_changelog_entries(@entries)
end

def load_feature_entries
changelog_dir = File.join(File.dirname(__FILE__), '..', 'changelog')

@feature_entries = Dir["#{changelog_dir}/*.md"]

prepare_changelog_entries(@feature_entries)
end

def prepare_changelog_entries(entries)
@issues += entries.map do |entry|
entry.match(/\[(?<number>[#\d]+)\]\((?<url>[^)]+)\)/)
end.compact

@bodies += entries.map do |entry|
entry.gsub(/`[^`]+`/, '``').sub(/^\*\s*(?:\[.+?\):\s*)?/, '').sub(/\s*\([^)]+\)$/, '')
end
end
end

0 comments on commit 06bd6bf

Please sign in to comment.