Refactor build_metadata
This commit is contained in:
parent
7d7b0688b8
commit
973e4030b1
6 changed files with 25 additions and 28 deletions
|
@ -44,10 +44,16 @@
|
||||||
runnerId() {
|
runnerId() {
|
||||||
return `#${this.job.runner.id}`;
|
return `#${this.job.runner.id}`;
|
||||||
},
|
},
|
||||||
|
hasTimeout() {
|
||||||
|
return this.job.metadata != null && this.job.metadata.timeout_human_readable !== '';
|
||||||
|
},
|
||||||
timeout() {
|
timeout() {
|
||||||
let t = `${this.job.metadata.timeout_human_readable}`;
|
if (this.job.metadata == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if (this.job.metadata.timeout_source != null) {
|
let t = this.job.metadata.timeout_human_readable;
|
||||||
|
if (this.job.metadata.timeout_source !== '') {
|
||||||
t += ` (from ${this.job.metadata.timeout_source})`;
|
t += ` (from ${this.job.metadata.timeout_source})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +136,7 @@
|
||||||
/>
|
/>
|
||||||
<detail-row
|
<detail-row
|
||||||
class="js-job-timeout"
|
class="js-job-timeout"
|
||||||
v-if="job.metadata.timeout_human_readable"
|
v-if="hasTimeout"
|
||||||
title="Timeout"
|
title="Timeout"
|
||||||
:help-url="runnerHelpUrl"
|
:help-url="runnerHelpUrl"
|
||||||
:value="timeout"
|
:value="timeout"
|
||||||
|
|
|
@ -162,7 +162,7 @@ module Ci
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_metadata
|
def ensure_metadata
|
||||||
metadata || build_metadata
|
metadata || build_metadata(project: project)
|
||||||
end
|
end
|
||||||
|
|
||||||
def detailed_status(current_user)
|
def detailed_status(current_user)
|
||||||
|
|
|
@ -11,9 +11,9 @@ module Ci
|
||||||
belongs_to :build, class_name: 'Ci::Build'
|
belongs_to :build, class_name: 'Ci::Build'
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
chronic_duration_attr_reader :timeout_human_readable, :timeout
|
validates :project, presence: true
|
||||||
|
|
||||||
after_initialize :set_project_id
|
chronic_duration_attr_reader :timeout_human_readable, :timeout
|
||||||
|
|
||||||
enum timeout_source: {
|
enum timeout_source: {
|
||||||
unknown_timeout_source: 1,
|
unknown_timeout_source: 1,
|
||||||
|
@ -24,19 +24,11 @@ module Ci
|
||||||
def save_timeout_state!
|
def save_timeout_state!
|
||||||
return unless build.runner.present?
|
return unless build.runner.present?
|
||||||
|
|
||||||
project_timeout = build.project&.build_timeout
|
project_timeout = project&.build_timeout
|
||||||
timeout = [project_timeout, build.runner.maximum_timeout].compact.min
|
timeout = [project_timeout, build.runner.maximum_timeout].compact.min
|
||||||
timeout_source = timeout < project_timeout ? :runner_timeout_source : :project_timeout_source
|
timeout_source = timeout < project_timeout ? :runner_timeout_source : :project_timeout_source
|
||||||
|
|
||||||
update_attributes(timeout: timeout, timeout_source: timeout_source)
|
update!(timeout: timeout, timeout_source: timeout_source)
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def set_project_id
|
|
||||||
return unless self.project_id.nil?
|
|
||||||
|
|
||||||
self.project_id = build&.project&.id
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,9 +5,7 @@ class BuildDetailsEntity < JobEntity
|
||||||
expose :runner, using: RunnerEntity
|
expose :runner, using: RunnerEntity
|
||||||
expose :pipeline, using: PipelineEntity
|
expose :pipeline, using: PipelineEntity
|
||||||
|
|
||||||
expose :metadata, using: BuildMetadataEntity do |build|
|
expose :metadata, using: BuildMetadataEntity
|
||||||
build.ensure_metadata
|
|
||||||
end
|
|
||||||
|
|
||||||
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
|
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
|
||||||
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build|
|
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build|
|
||||||
|
|
9
spec/factories/ci/build_metadata.rb
Normal file
9
spec/factories/ci/build_metadata.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :ci_build_metadata, class: Ci::BuildMetadata do
|
||||||
|
build factory: :ci_build
|
||||||
|
|
||||||
|
after(:build) do |build_metadata, _|
|
||||||
|
build_metadata.project ||= build_metadata.build.project
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -13,15 +13,7 @@ describe Ci::BuildMetadata do
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:build) { create(:ci_build, pipeline: pipeline) }
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
||||||
let(:build_metadata) { described_class.create(build: build) }
|
let(:build_metadata) { create(:ci_build_metadata, build: build) }
|
||||||
|
|
||||||
context 'when creating' do
|
|
||||||
subject { build_metadata.project_id }
|
|
||||||
|
|
||||||
it 'saves project_id' do
|
|
||||||
is_expected.to eq(project.id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#save_timeout_state!' do
|
describe '#save_timeout_state!' do
|
||||||
subject { build_metadata }
|
subject { build_metadata }
|
||||||
|
|
Loading…
Reference in a new issue