summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/commit.rb1
-rw-r--r--changelogs/unreleased/21326-avoid-nil-safe-message.yml5
-rw-r--r--spec/models/commit_spec.rb6
3 files changed, 12 insertions, 0 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 27fbdc3e386..594972ad344 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -193,6 +193,7 @@ class Commit
# otherwise returns commit message without first line
def description
return safe_message if full_title.length >= 100
+ return no_commit_message if safe_message.blank?
safe_message.split("\n", 2)[1].try(:chomp)
end
diff --git a/changelogs/unreleased/21326-avoid-nil-safe-message.yml b/changelogs/unreleased/21326-avoid-nil-safe-message.yml
new file mode 100644
index 00000000000..ca1a89191a8
--- /dev/null
+++ b/changelogs/unreleased/21326-avoid-nil-safe-message.yml
@@ -0,0 +1,5 @@
+---
+title: "Avoid nil safe message"
+merge_request: 21326
+author: Yi Siliang
+type: fixed
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 5157d8fc645..d5f88e930d4 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -225,6 +225,12 @@ eos
end
describe 'description' do
+ it 'returns no_commit_message when safe_message is blank' do
+ allow(commit).to receive(:safe_message).and_return(nil)
+
+ expect(commit.description).to eq('--no commit message')
+ end
+
it 'returns description of commit message if title less than 100 characters' do
message = <<eos
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit.