Merge branch '25136-last-deployment-link' into 'master'

Fix broken link for latest deployment

## What does this MR do?

Creates a new helper for the latest deployment link.

## Why was this MR needed?

A helper that returns a link was being called inside another helper that creates a link, resulting in  `builds/<a href="builds/ID>#id</a>`

## What are the relevant issue numbers?

Closes #25136

See merge request !7839
parents 3e8118d6 4eb53036
Pipeline #5389860 failed with stages
in 199 minutes and 8 seconds
......@@ -14,10 +14,12 @@ module EnvironmentHelper
end
end
def deployment_link(deployment)
def deployment_link(deployment, text: nil)
return unless deployment
link_to "##{deployment.iid}", [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable]
link_label = text ? text : "##{deployment.iid}"
link_to link_label, [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable]
end
def last_deployment_link_for_environment_build(project, build)
......
......@@ -46,8 +46,7 @@
- else
This build is creating a deployment to #{environment_link_for_build(@build.project, @build)}
- if environment.try(:last_deployment)
and will overwrite the
= link_to 'latest deployment', deployment_link(environment.last_deployment)
and will overwrite the #{deployment_link(environment.last_deployment, text: 'latest deployment')}
.prepend-top-default
- if @build.erased?
......
---
title: Fix Latest deployment link is broken
merge_request: 7839
author:
......@@ -227,6 +227,43 @@ feature 'Builds', :feature do
expect(page).to have_selector('.js-build-value', text: 'TRIGGER_VALUE_1')
end
end
context 'when build starts environment' do
let(:environment) { create(:environment, project: project) }
let(:pipeline) { create(:ci_pipeline, project: project) }
context 'build is successfull and has deployment' do
let(:deployment) { create(:deployment) }
let(:build) { create(:ci_build, :success, environment: environment.name, deployments: [deployment], pipeline: pipeline) }
it 'shows a link for the build' do
visit namespace_project_build_path(project.namespace, project, build)
expect(page).to have_link environment.name
end
end
context 'build is complete and not successfull' do
let(:build) { create(:ci_build, :failed, environment: environment.name, pipeline: pipeline) }
it 'shows a link for the build' do
visit namespace_project_build_path(project.namespace, project, build)
expect(page).to have_link environment.name
end
end
context 'build creates a new deployment' do
let!(:deployment) { create(:deployment, environment: environment, sha: project.commit.id) }
let(:build) { create(:ci_build, :success, environment: environment.name, pipeline: pipeline) }
it 'shows a link to lastest deployment' do
visit namespace_project_build_path(project.namespace, project, build)
expect(page).to have_link('latest deployment')
end
end
end
end
describe "POST /:project/builds/:id/cancel" do
......
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