diff --git a/changelog/fix_fix_changelog_task_to_build_a_correct.md b/changelog/fix_fix_changelog_task_to_build_a_correct.md new file mode 100644 index 00000000000..864cd401c05 --- /dev/null +++ b/changelog/fix_fix_changelog_task_to_build_a_correct.md @@ -0,0 +1 @@ +* [#8945](https://github.com/rubocop-hq/rubocop/pull/8945): Fix changelog task to build a correct changelog item when `Fix #123` is encountered. ([@dvandersluis][]) diff --git a/spec/tasks/changelog_spec.rb b/spec/tasks/changelog_spec.rb index fa69d85fd40..d2016f39a3d 100644 --- a/spec/tasks/changelog_spec.rb +++ b/spec/tasks/changelog_spec.rb @@ -46,13 +46,95 @@ body: "Do something cool#{'x' * i}", user: "johndoe#{'x' * i}") end end - let(:entry) { entries.first } describe Changelog::Entry do - it 'generates correct content' do - expect(entry.content).to eq <<~MD - * [#x](https://github.com/rubocop-hq/rubocop/pull/x): Do something cool. ([@johndoe][]) - MD + subject(:entry) do + described_class.new( + type: type, + body: body, + user: github_user + ) + end + + let(:type) { :fix } + let(:github_user) { 'johndoe' } + + describe '#content' do + context 'when there is an issue referenced' do + let(:body) { '[Fix #567] Do something cool.' } + + it 'generates correct content' do + expect(entry.content).to eq <<~MD + * [#567](https://github.com/rubocop-hq/rubocop/pull/567): Do something cool. ([@johndoe][]) + MD + end + end + + context 'when there is no issue referenced' do + let(:body) { 'Do something cool.' } + + it 'generates correct content' do + expect(entry.content).to eq <<~MD + * [#x](https://github.com/rubocop-hq/rubocop/pull/x): Do something cool. ([@johndoe][]) + MD + end + end + end + + describe '#ref_id' do + subject { entry.ref_id } + + context 'when there is no body' do + let(:body) { '' } + + it { is_expected.to eq('x') } + end + + context 'when there is no issue referenced in the body' do + let(:body) { 'Fix something' } + + it { is_expected.to eq('x') } + end + + context 'when there is an issue referenced with [Fix #x] the body' do + let(:body) { '[Fix #123] Fix something' } + + it { is_expected.to eq('123') } + end + + context 'when there is an issue referenced with [Fixes #x] the body' do + let(:body) { '[Fixes #123] Fix something' } + + it { is_expected.to eq('123') } + end + end + + describe '#body' do + subject { entry.body } + + context 'when there is no body' do + let(:body) { '' } + + it { is_expected.to eq('') } + end + + context 'when there is no issue referenced in the body' do + let(:body) { 'Fix something' } + + it { is_expected.to eq('Fix something') } + end + + context 'when there is an issue referenced with [Fix #x] the body' do + let(:body) { '[Fix #123] Fix something' } + + it { is_expected.to eq('Fix something') } + end + + context 'when there is an issue referenced with [Fixes #x] the body' do + let(:body) { '[Fixes #123] Fix something' } + + it { is_expected.to eq('Fix something') } + end end end diff --git a/tasks/changelog.rb b/tasks/changelog.rb index f312329a857..1e2946d3966 100644 --- a/tasks/changelog.rb +++ b/tasks/changelog.rb @@ -51,7 +51,7 @@ def last_commit_title end def extract_id(body) - /^\[Fixes #(\d+)\] (.*)/.match(body)&.captures || [nil, body] + /^\[Fix(?:es)? #(\d+)\] (.*)/.match(body)&.captures || [nil, body] end def str_to_filename(str)