diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2017-10-06 12:33:10 +0200 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2017-10-06 12:33:10 +0200 |
commit | c0cfc9ebd26583c444f2cce1a23f939bfa7d8969 (patch) | |
tree | a6e7260211e51b0286afc7cca7b11e985621d5c1 /app | |
parent | ea023138bf5116a729e5accd5f81d4e586af6b02 (diff) | |
download | gitlab-ce-c0cfc9ebd26583c444f2cce1a23f939bfa7d8969.tar.gz |
Extract `Ci::Build#parse_trace_sections!` into a service37970-ci-sections-tracking
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/build.rb | 19 | ||||
-rw-r--r-- | app/services/ci/extract_sections_from_build_trace_service.rb | 30 |
2 files changed, 31 insertions, 18 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 72e646210a8..6ca46ae89c1 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -267,24 +267,7 @@ module Ci end def parse_trace_sections! - return false unless trace_sections.empty? - - sections = trace.extract_sections.map do |attr| - name = attr.delete(:name) - name_record = begin - project.build_trace_section_names.find_or_create_by!(name: name) - rescue ActiveRecord::RecordInvalid - project.build_trace_section_names.find_by!(name: name) - end - - attr.merge( - build_id: self.id, - project_id: self.project_id, - section_name_id: name_record.id) - end - - Gitlab::Database.bulk_insert(Ci::BuildTraceSection.table_name, sections) - true + ExtractSectionsFromBuildTraceService.new(project, user).execute(self) end def trace diff --git a/app/services/ci/extract_sections_from_build_trace_service.rb b/app/services/ci/extract_sections_from_build_trace_service.rb new file mode 100644 index 00000000000..75f9e0f897d --- /dev/null +++ b/app/services/ci/extract_sections_from_build_trace_service.rb @@ -0,0 +1,30 @@ +module Ci + class ExtractSectionsFromBuildTraceService < BaseService + def execute(build) + return false unless build.trace_sections.empty? + + Gitlab::Database.bulk_insert(BuildTraceSection.table_name, extract_sections(build)) + true + end + + private + + def find_or_create_name(name) + project.build_trace_section_names.find_or_create_by!(name: name) + rescue ActiveRecord::RecordInvalid + project.build_trace_section_names.find_by!(name: name) + end + + def extract_sections(build) + build.trace.extract_sections.map do |attr| + name = attr.delete(:name) + name_record = find_or_create_name(name) + + attr.merge( + build_id: build.id, + project_id: project.id, + section_name_id: name_record.id) + end + end + end +end |