Commit f7d04e34 authored by Sean McGivern's avatar Sean McGivern Committed by Simon Knox

Merge branch 'fix-push-events-branch-removals' into 'master'

Fix displaying events of removed events and events without commit messages

Closes #36685 and #36722

See merge request !13721
parent 5cd8b331
...@@ -181,6 +181,7 @@ module EventsHelper ...@@ -181,6 +181,7 @@ module EventsHelper
end end
def event_commit_title(message) def event_commit_title(message)
message ||= ''
(message.split("\n").first || "").truncate(70) (message.split("\n").first || "").truncate(70)
rescue rescue
"--broken encoding" "--broken encoding"
......
...@@ -406,7 +406,7 @@ class Event < ActiveRecord::Base ...@@ -406,7 +406,7 @@ class Event < ActiveRecord::Base
def body? def body?
if push? if push?
push_with_commits? || rm_ref? push_with_commits?
elsif note? elsif note?
true true
else else
......
...@@ -5,9 +5,10 @@ ...@@ -5,9 +5,10 @@
%i %i
at at
= event.created_at.to_s(:short) = event.created_at.to_s(:short)
%blockquote= markdown(escape_once(event.commit_title), pipeline: :atom, project: event.project, author: event.author) - unless event.rm_ref?
- if event.commits_count > 1 %blockquote= markdown(escape_once(event.commit_title), pipeline: :atom, project: event.project, author: event.author)
%p - if event.commits_count > 1
%i %p
\... and %i
= pluralize(event.commits_count - 1, "more commit") \... and
= pluralize(event.commits_count - 1, "more commit")
...@@ -41,7 +41,3 @@ ...@@ -41,7 +41,3 @@
%li.commits-stat %li.commits-stat
= link_to create_mr_path(project.default_branch, event.ref_name, project) do = link_to create_mr_path(project.default_branch, event.ref_name, project) do
Create Merge Request Create Merge Request
- elsif event.rm_ref?
.event-body
%ul.well-list.event_commits
= render "events/commit", project: project, event: event
---
title: Fix display of push events for removed refs
merge_request:
author:
type: fixed
...@@ -106,5 +106,9 @@ describe EventsHelper do ...@@ -106,5 +106,9 @@ describe EventsHelper do
it "handles empty strings" do it "handles empty strings" do
expect(helper.event_commit_title("")).to eq("") expect(helper.event_commit_title("")).to eq("")
end end
it 'handles nil values' do
expect(helper.event_commit_title(nil)).to eq('')
end
end end
end end
...@@ -304,6 +304,50 @@ describe Event do ...@@ -304,6 +304,50 @@ describe Event do
end end
end end
describe '#body?' do
let(:push_event) do
event = build(:push_event)
allow(event).to receive(:push?).and_return(true)
event
end
it 'returns true for a push event with commits' do
allow(push_event).to receive(:push_with_commits?).and_return(true)
expect(push_event).to be_body
end
it 'returns false for a push event without a valid commit range' do
allow(push_event).to receive(:push_with_commits?).and_return(false)
expect(push_event).not_to be_body
end
it 'returns true for a Note event' do
event = build(:event)
allow(event).to receive(:note?).and_return(true)
expect(event).to be_body
end
it 'returns true if the target responds to #title' do
event = build(:event)
allow(event).to receive(:target).and_return(double(:target, title: 'foo'))
expect(event).to be_body
end
it 'returns false for a regular event without a target' do
event = build(:event)
expect(event).not_to be_body
end
end
def create_push_event(project, user) def create_push_event(project, user)
event = create(:push_event, project: project, author: user) event = create(:push_event, project: project, author: user)
......
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