diff --git a/app/finders/repositories/changelog_commits_finder.rb b/app/finders/repositories/changelog_commits_finder.rb index 08f1144701a9441aec6d0ab61b774d01be41b36f..b80b8e94e597698dab1e5807743cb97b10caf371 100644 --- a/app/finders/repositories/changelog_commits_finder.rb +++ b/app/finders/repositories/changelog_commits_finder.rb @@ -93,7 +93,7 @@ def fetch_commits(offset = 0) end def revert_commit_sha(commit) - matches = commit.description.match(REVERT_REGEX) + matches = commit.description&.match(REVERT_REGEX) matches[:sha] if matches end diff --git a/changelogs/unreleased/changelog-commits-without-description.yml b/changelogs/unreleased/changelog-commits-without-description.yml new file mode 100644 index 0000000000000000000000000000000000000000..41f757e5e2ba32e22f7f9148856b27704ccbef3f --- /dev/null +++ b/changelogs/unreleased/changelog-commits-without-description.yml @@ -0,0 +1,5 @@ +--- +title: Handle commits without descriptions for changelogs +merge_request: 56224 +author: +type: fixed diff --git a/spec/finders/repositories/changelog_commits_finder_spec.rb b/spec/finders/repositories/changelog_commits_finder_spec.rb index fe40666a955f191c20020ba22630483e3a5e654c..8665d36144ae8aaa575180b68822247e8d3b76ae 100644 --- a/spec/finders/repositories/changelog_commits_finder_spec.rb +++ b/spec/finders/repositories/changelog_commits_finder_spec.rb @@ -64,4 +64,30 @@ 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