Skip to content
代码片段 群组 项目
未验证 提交 d1d9eb80 编辑于 作者: Payton Burdette's avatar Payton Burdette 提交者: GitLab
浏览文件

Expose schedule name

Expose pipeline schedule name in place
of pipeline name when pipeline was created
from a pipeline schedule.

Changelog: changed
上级 d2f7a7bc
No related branches found
No related tags found
无相关合并请求
...@@ -120,8 +120,24 @@ export default { ...@@ -120,8 +120,24 @@ export default {
commitTitle() { commitTitle() {
return this.pipeline?.commit?.title; return this.pipeline?.commit?.title;
}, },
pipelineName() { pipelineIdentifier() {
return this.pipeline?.name; const { name, path, pipeline_schedule: pipelineSchedule } = this.pipeline || {};
if (pipelineSchedule) {
return {
text: pipelineSchedule.description,
link: pipelineSchedule.path,
};
}
if (name) {
return {
text: name,
link: path,
};
}
return false;
}, },
}, },
methods: { methods: {
...@@ -133,17 +149,27 @@ export default { ...@@ -133,17 +149,27 @@ export default {
</script> </script>
<template> <template>
<div class="pipeline-tags" data-testid="pipeline-url-table-cell"> <div class="pipeline-tags" data-testid="pipeline-url-table-cell">
<div v-if="pipelineName" class="gl-mb-2" data-testid="pipeline-name-container"> <div v-if="pipelineIdentifier" class="gl-mb-2" data-testid="pipeline-identifier-container">
<span class="gl-flex"> <span class="gl-flex">
<tooltip-on-truncate :title="pipelineName" class="gl-grow gl-truncate gl-text-gray-900"> <tooltip-on-truncate
<gl-link :href="pipeline.path" class="!gl-text-link" data-testid="pipeline-url-link">{{ :title="pipelineIdentifier.text"
pipelineName class="gl-grow gl-truncate gl-text-gray-900"
}}</gl-link> >
<gl-link
:href="pipelineIdentifier.link"
class="!gl-text-link"
data-testid="pipeline-identifier-link"
>{{ pipelineIdentifier.text }}</gl-link
>
</tooltip-on-truncate> </tooltip-on-truncate>
</span> </span>
</div> </div>
<div v-if="!pipelineName" class="commit-title gl-mb-2" data-testid="commit-title-container"> <div
v-if="!pipelineIdentifier"
class="commit-title gl-mb-2"
data-testid="commit-title-container"
>
<span v-if="commitTitle" class="gl-flex"> <span v-if="commitTitle" class="gl-flex">
<tooltip-on-truncate <tooltip-on-truncate
:title="commitTitle" :title="commitTitle"
...@@ -162,6 +188,7 @@ export default { ...@@ -162,6 +188,7 @@ export default {
__("Can't find HEAD commit for this branch") __("Can't find HEAD commit for this branch")
}}</span> }}</span>
</div> </div>
<div class="gl-mb-2"> <div class="gl-mb-2">
<gl-link <gl-link
:href="pipeline.path" :href="pipeline.path"
...@@ -200,6 +227,7 @@ export default { ...@@ -200,6 +227,7 @@ export default {
> >
</tooltip-on-truncate> </tooltip-on-truncate>
</div> </div>
<div class="gl-inline-block gl-rounded-base gl-bg-gray-50 gl-px-2 gl-text-sm gl-text-default"> <div class="gl-inline-block gl-rounded-base gl-bg-gray-50 gl-px-2 gl-text-sm gl-text-default">
<gl-icon <gl-icon
v-gl-tooltip v-gl-tooltip
...@@ -217,6 +245,7 @@ export default { ...@@ -217,6 +245,7 @@ export default {
>{{ commitShortSha }}</gl-link >{{ commitShortSha }}</gl-link
> >
</div> </div>
<user-avatar-link <user-avatar-link
v-if="commitAuthor" v-if="commitAuthor"
:link-href="commitAuthor.path" :link-href="commitAuthor.path"
......
...@@ -96,6 +96,8 @@ class Ci::PipelineEntity < Grape::Entity ...@@ -96,6 +96,8 @@ class Ci::PipelineEntity < Grape::Entity
pipeline.failed_builds.size pipeline.failed_builds.size
end end
expose :pipeline_schedule, using: Ci::PipelineScheduleEntity
private private
alias_method :pipeline, :object alias_method :pipeline, :object
......
# frozen_string_literal: true
module Ci
class PipelineScheduleEntity < Grape::Entity
include RequestAwareEntity
expose :id
expose :description
expose :path do |schedule|
pipeline_schedules_path(schedule.project)
end
end
end
...@@ -33,6 +33,7 @@ def represent_stages(resource) ...@@ -33,6 +33,7 @@ def represent_stages(resource)
def preloaded_relations(preload_statuses: true, preload_downstream_statuses: true, **) def preloaded_relations(preload_statuses: true, preload_downstream_statuses: true, **)
[ [
:pipeline_metadata, :pipeline_metadata,
:pipeline_schedule,
:cancelable_statuses, :cancelable_statuses,
:retryable_builds, :retryable_builds,
:stages, :stages,
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
mockPipeline, mockPipeline,
mockPipelineBranch, mockPipelineBranch,
mockPipelineTag, mockPipelineTag,
} from 'jest/ci/pipeline_details/mock_data'; } from '../../pipeline_details/mock_data';
const projectPath = 'test/test'; const projectPath = 'test/test';
...@@ -18,6 +18,7 @@ describe('Pipeline Url Component', () => { ...@@ -18,6 +18,7 @@ describe('Pipeline Url Component', () => {
const findTableCell = () => wrapper.findByTestId('pipeline-url-table-cell'); const findTableCell = () => wrapper.findByTestId('pipeline-url-table-cell');
const findPipelineUrlLink = () => wrapper.findByTestId('pipeline-url-link'); const findPipelineUrlLink = () => wrapper.findByTestId('pipeline-url-link');
const findPipelineIdentifierLink = () => wrapper.findByTestId('pipeline-identifier-link');
const findRefName = () => wrapper.findByTestId('merge-request-ref'); const findRefName = () => wrapper.findByTestId('merge-request-ref');
const findCommitShortSha = () => wrapper.findByTestId('commit-short-sha'); const findCommitShortSha = () => wrapper.findByTestId('commit-short-sha');
const findCommitIcon = () => wrapper.findByTestId('commit-icon'); const findCommitIcon = () => wrapper.findByTestId('commit-icon');
...@@ -25,7 +26,8 @@ describe('Pipeline Url Component', () => { ...@@ -25,7 +26,8 @@ describe('Pipeline Url Component', () => {
const findCommitRefName = () => wrapper.findByTestId('commit-ref-name'); const findCommitRefName = () => wrapper.findByTestId('commit-ref-name');
const findCommitTitleContainer = () => wrapper.findByTestId('commit-title-container'); const findCommitTitleContainer = () => wrapper.findByTestId('commit-title-container');
const findPipelineNameContainer = () => wrapper.findByTestId('pipeline-name-container'); const findPipelineIdentifierContainer = () =>
wrapper.findByTestId('pipeline-identifier-container');
const findCommitTitle = (commitWrapper) => commitWrapper.find('[data-testid="commit-title"]'); const findCommitTitle = (commitWrapper) => commitWrapper.find('[data-testid="commit-title"]');
const defaultProps = { ...mockPipeline(projectPath), refClass: 'gl-text-black' }; const defaultProps = { ...mockPipeline(projectPath), refClass: 'gl-text-black' };
...@@ -46,20 +48,43 @@ describe('Pipeline Url Component', () => { ...@@ -46,20 +48,43 @@ describe('Pipeline Url Component', () => {
createComponent(); createComponent();
expect(findPipelineUrlLink().attributes('href')).toBe('foo'); expect(findPipelineUrlLink().attributes('href')).toBe('foo');
expect(findPipelineUrlLink().text()).toBe('#1'); expect(findPipelineUrlLink().text()).toBe('#1');
}); });
it('should render the pipeline name instead of commit title', () => { it('should render the pipeline schedule identifier instead of pipeline name', () => {
createComponent(merge(mockPipeline(projectPath), { pipeline: { name: 'Build pipeline' } })); createComponent(
merge(mockPipeline(projectPath), {
pipeline: {
name: 'Build pipeline',
pipeline_schedule: { id: 1, description: 'Schedule', path: 'schedule/path' },
},
}),
);
expect(findCommitTitleContainer().exists()).toBe(false);
expect(findPipelineIdentifierContainer().exists()).toBe(true);
expect(findRefName().exists()).toBe(true);
expect(findCommitShortSha().exists()).toBe(true);
expect(findPipelineIdentifierLink().text()).toBe('Schedule');
expect(findPipelineIdentifierLink().attributes('href')).toBe('schedule/path');
});
it('should render the pipeline name identifier instead of commit title', () => {
createComponent(
merge(mockPipeline(projectPath), {
pipeline: { name: 'Build pipeline', pipeline_schedule: null },
}),
);
expect(findCommitTitleContainer().exists()).toBe(false); expect(findCommitTitleContainer().exists()).toBe(false);
expect(findPipelineNameContainer().exists()).toBe(true); expect(findPipelineIdentifierContainer().exists()).toBe(true);
expect(findRefName().exists()).toBe(true); expect(findRefName().exists()).toBe(true);
expect(findCommitShortSha().exists()).toBe(true); expect(findCommitShortSha().exists()).toBe(true);
expect(findPipelineIdentifierLink().text()).toBe('Build pipeline');
expect(findPipelineIdentifierLink().attributes('href')).toBe('foo');
}); });
it('should render the commit title when pipeline has no name', () => { it('should render the commit title when pipeline has no identifier', () => {
createComponent(); createComponent();
const commitWrapper = findCommitTitleContainer(); const commitWrapper = findCommitTitleContainer();
...@@ -67,7 +92,8 @@ describe('Pipeline Url Component', () => { ...@@ -67,7 +92,8 @@ describe('Pipeline Url Component', () => {
expect(findCommitTitle(commitWrapper).exists()).toBe(true); expect(findCommitTitle(commitWrapper).exists()).toBe(true);
expect(findRefName().exists()).toBe(true); expect(findRefName().exists()).toBe(true);
expect(findCommitShortSha().exists()).toBe(true); expect(findCommitShortSha().exists()).toBe(true);
expect(findPipelineNameContainer().exists()).toBe(false); expect(findPipelineIdentifierContainer().exists()).toBe(false);
expect(findPipelineIdentifierLink().exists()).toBe(false);
}); });
it('should pass the refClass prop to merge request link', () => { it('should pass the refClass prop to merge request link', () => {
......
...@@ -300,5 +300,26 @@ ...@@ -300,5 +300,26 @@
expect(subject[:coverage]).to eq('35.00') expect(subject[:coverage]).to eq('35.00')
end end
end end
context 'when pipeline has a schedule' do
let_it_be(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project) }
let_it_be(:pipeline) { create(:ci_pipeline, pipeline_schedule: pipeline_schedule, project: project) }
it 'exposes the schedule' do
expect(subject[:pipeline_schedule]).to eq({
id: pipeline_schedule.id,
description: pipeline_schedule.description,
path: pipeline_schedules_path(pipeline_schedule.project)
})
end
end
context 'when pipeline has no schedule' do
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
it 'is nil' do
expect(subject[:pipeline_schedule]).to be_nil
end
end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::PipelineScheduleEntity, feature_category: :continuous_integration do
include Gitlab::Routing
let_it_be(:project) { build_stubbed(:project) }
let_it_be(:pipeline_schedule) { build_stubbed(:ci_pipeline_schedule, :nightly, project: project) }
let(:request) { instance_double(ActionDispatch::Request) }
let(:entity) { described_class.new(pipeline_schedule, request: request) }
subject(:data) { entity.as_json }
it { is_expected.to include(:id) }
it { is_expected.to include(:description) }
it { is_expected.to include(:path) }
it { expect(data[:id]).to eq(pipeline_schedule.id) }
it { expect(data[:description]).to eq(pipeline_schedule.description) }
it { expect(data[:path]).to eq(pipeline_schedules_path(pipeline_schedule.project)) }
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册