Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix changelog item generation #8945

Merged
merged 2 commits into from Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -3079,7 +3079,7 @@
* [#2146](https://github.com/rubocop-hq/rubocop/pull/2146): Add STDIN support. ([@caseywebdev][])
* [#2175](https://github.com/rubocop-hq/rubocop/pull/2175): Files that are excluded from a cop (e.g. using the `Exclude:` config option) are no longer being processed by that cop. ([@bquorning][])
* `Rails/ActionFilter` now handles complete list of methods found in the Rails 4.2 [release notes](https://github.com/rails/rails/blob/4115a12da1409c753c747fd4bab6e612c0c6e51a/guides/source/4_2_release_notes.md#notable-changes-1). ([@MGerrior][])
* [*2138](https://github.com/rubocop-hq/rubocop/issues/2138): Change the offense in `Style/Next` to highlight the condition instead of the iteration. ([@rrosenblum][])
* [#2138](https://github.com/rubocop-hq/rubocop/issues/2138): Change the offense in `Style/Next` to highlight the condition instead of the iteration. ([@rrosenblum][])
* `Style/EmptyLineBetweenDefs` now handles class methods as well. ([@unmanbearpig][])
* Improve handling of `super` in `Style/SymbolProc`. ([@lumeet][])
* `Style/SymbolProc` is applied to methods receiving arguments. ([@lumeet][])
Expand Down
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][])
27 changes: 22 additions & 5 deletions spec/project_spec.rb
Expand Up @@ -122,20 +122,31 @@
describe 'link to related issue' do
let(:issues) do
entries.map do |entry|
entry.match(/\[(?<number>[#\d]+)\]\((?<url>[^)]+)\)/)
entry.match(%r{
(?<=^\*\s)
\[(?<ref>(?:(?<repo>rubocop-hq/[a-z_-]+)?\#(?<number>\d+))|.*)\]
\((?<url>[^)]+)\)
}x)
end.compact
end

it 'has an issue number prefixed with #' do
it 'has a reference' do
issues.each do |issue|
expect(issue[:number]).to match(/^#\d+$/)
expect(issue[:ref].blank?).to eq(false)
end
end

it 'has a valid issue number prefixed with #' do
issues.each do |issue|
expect(issue[:number]).to match(/^\d+$/)
end
end

it 'has a valid URL' do
issues.each do |issue|
number = issue[:number].gsub(/\D/, '')
pattern = %r{^https://github\.com/rubocop-hq/rubocop/(?:issues|pull)/#{number}$}
number = issue[:number]&.gsub(/\D/, '')
repo = issue[:repo] || 'rubocop-hq/rubocop'
pattern = %r{^https://github\.com/#{repo}/(?:issues|pull)/#{number}$}
expect(issue[:url]).to match(pattern)
end
end
Expand Down Expand Up @@ -176,6 +187,12 @@
it 'ends with a punctuation' do
expect(bodies).to all(match(/[.!]$/))
end

it 'does not include a [Fix #x] directive' do
bodies.each do |body|
expect(body).not_to match(/\[Fix(es)? \#.*?\]/i)
end
end
end
end
end
Expand Down
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, didn't know we could write either 😅

end

def str_to_filename(str)
Expand Down