Commit a3b9856e authored by Yorick Peterse's avatar Yorick Peterse

Handle commits without descriptions for changelogs

When processing commits to include in a changelog, we may encounter
commits without a description (= they only have a subject). This results
in Commit#description being nil, resulting in a NoMethodError when we
try to extract a revert SHA from that description.

This commit fixes this by just not matching if the description is nil.
This is fine since commits without a description are never included, due
to a lack of a trailer tag.

This fixes https://gitlab.com/gitlab-org/gitlab/-/issues/323998
parent 152c03af
......@@ -93,7 +93,7 @@ module Repositories
end
def revert_commit_sha(commit)
matches = commit.description.match(REVERT_REGEX)
matches = commit.description&.match(REVERT_REGEX)
matches[:sha] if matches
end
......
---
title: Handle commits without descriptions for changelogs
merge_request: 56224
author:
type: fixed
......@@ -64,4 +64,30 @@ RSpec.describe Repositories::ChangelogCommitsFinder do
expect(commits.count).to eq(4)
end
end
describe '#revert_commit_sha' do
let(:finder) { described_class.new(project: project, from: 'a', to: 'b') }
it 'returns the SHA of a reverted commit' do
commit = double(
:commit,
description: 'This reverts commit 152c03af1b09f50fa4b567501032b106a3a81ff3.'
)
expect(finder.send(:revert_commit_sha, commit))
.to eq('152c03af1b09f50fa4b567501032b106a3a81ff3')
end
it 'returns nil when the commit is not a revert commit' do
commit = double(:commit, description: 'foo')
expect(finder.send(:revert_commit_sha, commit)).to be_nil
end
it 'returns nil when the commit has no description' do
commit = double(:commit, description: nil)
expect(finder.send(:revert_commit_sha, commit)).to be_nil
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment