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
end
def event_commit_title(message)
message ||= ''
(message.split("\n").first || "").truncate(70)
rescue
"--broken encoding"
......
......@@ -406,7 +406,7 @@ class Event < ActiveRecord::Base
def body?
if push?
push_with_commits? || rm_ref?
push_with_commits?
elsif note?
true
else
......
......@@ -5,6 +5,7 @@
%i
at
= event.created_at.to_s(:short)
- unless event.rm_ref?
%blockquote= markdown(escape_once(event.commit_title), pipeline: :atom, project: event.project, author: event.author)
- if event.commits_count > 1
%p
......
......@@ -41,7 +41,3 @@
%li.commits-stat
= link_to create_mr_path(project.default_branch, event.ref_name, project) do
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
it "handles empty strings" do
expect(helper.event_commit_title("")).to eq("")
end
it 'handles nil values' do
expect(helper.event_commit_title(nil)).to eq('')
end
end
end
......@@ -304,6 +304,50 @@ describe Event do
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)
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