Commit 9b568537 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '42611-removed-branch-link' into 'master'

Resolve "Removed branch link in pipelines page is broken"

Closes #42611

See merge request gitlab-org/gitlab-ce!21451
parents 66e02d39 680afb3d
......@@ -268,6 +268,12 @@ module Ci
stage unless stage.statuses_count.zero?
end
def ref_exists?
project.repository.ref_exists?(git_ref)
rescue Gitlab::Git::Repository::NoRepository
false
end
##
# TODO We do not completely switch to persisted stages because of
# race conditions with setting statuses gitlab-ce#23257.
......@@ -674,11 +680,11 @@ module Ci
def push_details
strong_memoize(:push_details) do
Gitlab::Git::Push.new(project, before_sha, sha, push_ref)
Gitlab::Git::Push.new(project, before_sha, sha, git_ref)
end
end
def push_ref
def git_ref
if branch?
Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s
elsif tag?
......
......@@ -13,7 +13,11 @@
= pluralize @pipeline.total_size, "job"
- if @pipeline.ref
from
- if @pipeline.ref_exists?
= link_to @pipeline.ref, project_ref_path(@project, @pipeline.ref), class: "ref-name"
- else
%span.ref-name
= @pipeline.ref
- if @pipeline.duration
in
= time_interval_in_words(@pipeline.duration)
......
---
title: Only render link to branch when branch still exists in pipeline page
merge_request:
author:
type: fixed
......@@ -68,6 +68,10 @@ describe 'Pipeline', :js do
expect(page).to have_css('#js-tab-pipeline.active')
end
it 'shows link to the pipeline ref' do
expect(page).to have_link(pipeline.ref)
end
it_behaves_like 'showing user status' do
let(:user_with_status) { pipeline.user }
......@@ -236,6 +240,20 @@ describe 'Pipeline', :js do
it { expect(page).not_to have_content('Cancel running') }
end
end
context 'when pipeline ref does not exist in repository anymore' do
let(:pipeline) do
create(:ci_empty_pipeline, project: project,
ref: 'non-existent',
sha: project.commit.id,
user: user)
end
it 'does not render link to the pipeline ref' do
expect(page).not_to have_link(pipeline.ref)
expect(page).to have_content(pipeline.ref)
end
end
end
context 'when user does not have access to read jobs' do
......
......@@ -779,6 +779,41 @@ describe Ci::Pipeline, :mailer do
end
end
describe 'ref_exists?' do
context 'when repository exists' do
using RSpec::Parameterized::TableSyntax
let(:project) { create(:project, :repository) }
where(:tag, :ref, :result) do
false | 'master' | true
false | 'non-existent-branch' | false
true | 'v1.1.0' | true
true | 'non-existent-tag' | false
end
with_them do
let(:pipeline) do
create(:ci_empty_pipeline, project: project, tag: tag, ref: ref)
end
it "correctly detects ref" do
expect(pipeline.ref_exists?).to be result
end
end
end
context 'when repository does not exist' do
let(:pipeline) do
create(:ci_empty_pipeline, project: project, ref: 'master')
end
it 'always returns false' do
expect(pipeline.ref_exists?).to eq false
end
end
end
context 'with non-empty project' do
let(:project) { create(:project, :repository) }
......
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