Skip to content

Commit

Permalink
Fix changelog task to build a correct changelog item when [Fix #123] …
Browse files Browse the repository at this point in the history
…is encountered.
  • Loading branch information
dvandersluis committed Oct 26, 2020
1 parent 9426a59 commit 4cd1337
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 6 deletions.
1 change: 1 addition & 0 deletions 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][])
92 changes: 87 additions & 5 deletions spec/tasks/changelog_spec.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tasks/changelog.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 4cd1337

Please sign in to comment.