BigW Consortium Gitlab

Commit b097d065 by Grzegorz Bizon

Merge branch '5836-move-lib-ci-into-gitlab-namespace' into 'master'

Resolve "Move `lib/ci` to `lib/gitlab/ci`" Closes #5836 See merge request !14078
parents 373ff978 e83a8187
...@@ -7,11 +7,11 @@ module Ci ...@@ -7,11 +7,11 @@ module Ci
def create def create
@content = params[:content] @content = params[:content]
@error = Ci::GitlabCiYamlProcessor.validation_message(@content) @error = Gitlab::Ci::YamlProcessor.validation_message(@content)
@status = @error.blank? @status = @error.blank?
if @error.blank? if @error.blank?
@config_processor = Ci::GitlabCiYamlProcessor.new(@content) @config_processor = Gitlab::Ci::YamlProcessor.new(@content)
@stages = @config_processor.stages @stages = @config_processor.stages
@builds = @config_processor.builds @builds = @config_processor.builds
@jobs = @config_processor.jobs @jobs = @config_processor.jobs
......
...@@ -132,10 +132,10 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -132,10 +132,10 @@ class Projects::PipelinesController < Projects::ApplicationController
def charts def charts
@charts = {} @charts = {}
@charts[:week] = Ci::Charts::WeekChart.new(project) @charts[:week] = Gitlab::Ci::Charts::WeekChart.new(project)
@charts[:month] = Ci::Charts::MonthChart.new(project) @charts[:month] = Gitlab::Ci::Charts::MonthChart.new(project)
@charts[:year] = Ci::Charts::YearChart.new(project) @charts[:year] = Gitlab::Ci::Charts::YearChart.new(project)
@charts[:pipeline_times] = Ci::Charts::PipelineTime.new(project) @charts[:pipeline_times] = Gitlab::Ci::Charts::PipelineTime.new(project)
@counts = {} @counts = {}
@counts[:total] = @project.pipelines.count(:all) @counts[:total] = @project.pipelines.count(:all)
......
...@@ -13,7 +13,7 @@ module BlobViewer ...@@ -13,7 +13,7 @@ module BlobViewer
prepare! prepare!
@validation_message = Ci::GitlabCiYamlProcessor.validation_message(blob.data) @validation_message = Gitlab::Ci::YamlProcessor.validation_message(blob.data)
end end
def valid? def valid?
......
...@@ -446,8 +446,8 @@ module Ci ...@@ -446,8 +446,8 @@ module Ci
return unless trace return unless trace
trace = trace.dup trace = trace.dup
Ci::MaskSecret.mask!(trace, project.runners_token) if project Gitlab::Ci::MaskSecret.mask!(trace, project.runners_token) if project
Ci::MaskSecret.mask!(trace, token) Gitlab::Ci::MaskSecret.mask!(trace, token)
trace trace
end end
......
module Ci module Ci
class GroupVariable < ActiveRecord::Base class GroupVariable < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
include HasVariable include HasVariable
include Presentable include Presentable
......
module Ci module Ci
class Pipeline < ActiveRecord::Base class Pipeline < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
include HasStatus include HasStatus
include Importable include Importable
include AfterCommitQueue include AfterCommitQueue
...@@ -336,8 +336,8 @@ module Ci ...@@ -336,8 +336,8 @@ module Ci
return @config_processor if defined?(@config_processor) return @config_processor if defined?(@config_processor)
@config_processor ||= begin @config_processor ||= begin
Ci::GitlabCiYamlProcessor.new(ci_yaml_file, project.full_path) Gitlab::Ci::YamlProcessor.new(ci_yaml_file, project.full_path)
rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e rescue Gitlab::Ci::YamlProcessor::ValidationError, Psych::SyntaxError => e
self.yaml_errors = e.message self.yaml_errors = e.message
nil nil
rescue rescue
......
module Ci module Ci
class PipelineSchedule < ActiveRecord::Base class PipelineSchedule < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
include Importable include Importable
acts_as_paranoid acts_as_paranoid
......
module Ci module Ci
class PipelineScheduleVariable < ActiveRecord::Base class PipelineScheduleVariable < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
include HasVariable include HasVariable
belongs_to :pipeline_schedule belongs_to :pipeline_schedule
......
module Ci module Ci
class PipelineVariable < ActiveRecord::Base class PipelineVariable < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
include HasVariable include HasVariable
belongs_to :pipeline belongs_to :pipeline
......
module Ci module Ci
class Runner < ActiveRecord::Base class Runner < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
RUNNER_QUEUE_EXPIRY_TIME = 60.minutes RUNNER_QUEUE_EXPIRY_TIME = 60.minutes
ONLINE_CONTACT_TIMEOUT = 1.hour ONLINE_CONTACT_TIMEOUT = 1.hour
......
module Ci module Ci
class RunnerProject < ActiveRecord::Base class RunnerProject < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
belongs_to :runner belongs_to :runner
belongs_to :project belongs_to :project
......
module Ci module Ci
class Stage < ActiveRecord::Base class Stage < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
include Importable include Importable
include HasStatus include HasStatus
include Gitlab::OptimisticLocking include Gitlab::OptimisticLocking
......
module Ci module Ci
class Trigger < ActiveRecord::Base class Trigger < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
acts_as_paranoid acts_as_paranoid
......
module Ci module Ci
class TriggerRequest < ActiveRecord::Base class TriggerRequest < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
belongs_to :trigger belongs_to :trigger
belongs_to :pipeline, foreign_key: :commit_id belongs_to :pipeline, foreign_key: :commit_id
......
module Ci module Ci
class Variable < ActiveRecord::Base class Variable < ActiveRecord::Base
extend Ci::Model extend Gitlab::Ci::Model
include HasVariable include HasVariable
include Presentable include Presentable
......
---
title: Move `lib/ci` to `lib/gitlab/ci`
merge_request: 14078
author: Maxim Rydkin
type: other
...@@ -6,7 +6,7 @@ module API ...@@ -6,7 +6,7 @@ module API
requires :content, type: String, desc: 'Content of .gitlab-ci.yml' requires :content, type: String, desc: 'Content of .gitlab-ci.yml'
end end
post '/lint' do post '/lint' do
error = Ci::GitlabCiYamlProcessor.validation_message(params[:content]) error = Gitlab::Ci::YamlProcessor.validation_message(params[:content])
status 200 status 200
......
module Ci module Gitlab
module Charts module Ci
module DailyInterval module Charts
def grouped_count(query) module DailyInterval
query def grouped_count(query)
.group("DATE(#{Ci::Pipeline.table_name}.created_at)")
.count(:created_at)
.transform_keys { |date| date.strftime(@format) }
end
def interval_step
@interval_step ||= 1.day
end
end
module MonthlyInterval
def grouped_count(query)
if Gitlab::Database.postgresql?
query query
.group("to_char(#{Ci::Pipeline.table_name}.created_at, '01 Month YYYY')") .group("DATE(#{::Ci::Pipeline.table_name}.created_at)")
.count(:created_at)
.transform_keys(&:squish)
else
query
.group("DATE_FORMAT(#{Ci::Pipeline.table_name}.created_at, '01 %M %Y')")
.count(:created_at) .count(:created_at)
.transform_keys { |date| date.strftime(@format) }
end
def interval_step
@interval_step ||= 1.day
end end
end end
def interval_step module MonthlyInterval
@interval_step ||= 1.month def grouped_count(query)
if Gitlab::Database.postgresql?
query
.group("to_char(#{::Ci::Pipeline.table_name}.created_at, '01 Month YYYY')")
.count(:created_at)
.transform_keys(&:squish)
else
query
.group("DATE_FORMAT(#{::Ci::Pipeline.table_name}.created_at, '01 %M %Y')")
.count(:created_at)
end
end
def interval_step
@interval_step ||= 1.month
end
end end
end
class Chart class Chart
attr_reader :labels, :total, :success, :project, :pipeline_times attr_reader :labels, :total, :success, :project, :pipeline_times
def initialize(project) def initialize(project)
@labels = [] @labels = []
@total = [] @total = []
@success = [] @success = []
@pipeline_times = [] @pipeline_times = []
@project = project @project = project
collect collect
end end
def collect def collect
query = project.pipelines query = project.pipelines
.where("? > #{Ci::Pipeline.table_name}.created_at AND #{Ci::Pipeline.table_name}.created_at > ?", @to, @from) # rubocop:disable GitlabSecurity/SqlInjection .where("? > #{::Ci::Pipeline.table_name}.created_at AND #{::Ci::Pipeline.table_name}.created_at > ?", @to, @from) # rubocop:disable GitlabSecurity/SqlInjection
totals_count = grouped_count(query) totals_count = grouped_count(query)
success_count = grouped_count(query.success) success_count = grouped_count(query.success)
current = @from current = @from
while current < @to while current < @to
label = current.strftime(@format) label = current.strftime(@format)
@labels << label @labels << label
@total << (totals_count[label] || 0) @total << (totals_count[label] || 0)
@success << (success_count[label] || 0) @success << (success_count[label] || 0)
current += interval_step current += interval_step
end
end end
end end
end
class YearChart < Chart class YearChart < Chart
include MonthlyInterval include MonthlyInterval
def initialize(*) def initialize(*)
@to = Date.today.end_of_month @to = Date.today.end_of_month
@from = @to.years_ago(1).beginning_of_month @from = @to.years_ago(1).beginning_of_month
@format = '%d %B %Y' @format = '%d %B %Y'
super super
end
end end
end
class MonthChart < Chart class MonthChart < Chart
include DailyInterval include DailyInterval
def initialize(*) def initialize(*)
@to = Date.today @to = Date.today
@from = @to - 30.days @from = @to - 30.days
@format = '%d %B' @format = '%d %B'
super super
end
end end
end
class WeekChart < Chart class WeekChart < Chart
include DailyInterval include DailyInterval
def initialize(*) def initialize(*)
@to = Date.today @to = Date.today
@from = @to - 7.days @from = @to - 7.days
@format = '%d %B' @format = '%d %B'
super super
end
end end
end
class PipelineTime < Chart class PipelineTime < Chart
def collect def collect
commits = project.pipelines.last(30) commits = project.pipelines.last(30)
commits.each do |commit| commits.each do |commit|
@labels << commit.short_sha @labels << commit.short_sha
duration = commit.duration || 0 duration = commit.duration || 0
@pipeline_times << (duration / 60) @pipeline_times << (duration / 60)
end
end end
end end
end end
......
module Ci::MaskSecret module Gitlab
class << self module Ci::MaskSecret
def mask!(value, token) class << self
return value unless value.present? && token.present? def mask!(value, token)
return value unless value.present? && token.present?
value.gsub!(token, 'x' * token.length) value.gsub!(token, 'x' * token.length)
value value
end
end end
end end
end end
module Ci module Gitlab
module Model module Ci
def table_name_prefix module Model
"ci_" def table_name_prefix
end "ci_"
end
def model_name def model_name
@model_name ||= ActiveModel::Name.new(self, nil, self.name.split("::").last) @model_name ||= ActiveModel::Name.new(self, nil, self.name.split("::").last)
end
end end
end end
end end
...@@ -56,13 +56,13 @@ module Gitlab ...@@ -56,13 +56,13 @@ module Gitlab
end end
def html_with_state(state = nil) def html_with_state(state = nil)
::Ci::Ansi2html.convert(stream, state) ::Gitlab::Ci::Ansi2html.convert(stream, state)
end end
def html(last_lines: nil) def html(last_lines: nil)
text = raw(last_lines: last_lines) text = raw(last_lines: last_lines)
buffer = StringIO.new(text) buffer = StringIO.new(text)
::Ci::Ansi2html.convert(buffer).html ::Gitlab::Ci::Ansi2html.convert(buffer).html
end end
def extract_coverage(regex) def extract_coverage(regex)
......
require 'spec_helper' require 'spec_helper'
describe Ci::Ansi2html do describe Gitlab::Ci::Ansi2html do
subject { described_class } subject { described_class }
it "prints non-ansi as-is" do it "prints non-ansi as-is" do
......
require 'spec_helper' require 'spec_helper'
describe Ci::Charts do describe Gitlab::Ci::Charts do
context "pipeline_times" do context "pipeline_times" do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:chart) { Ci::Charts::PipelineTime.new(project) } let(:chart) { Gitlab::Ci::Charts::PipelineTime.new(project) }
subject { chart.pipeline_times } subject { chart.pipeline_times }
......
require 'spec_helper' require 'spec_helper'
describe Ci::MaskSecret do describe Gitlab::Ci::MaskSecret do
subject { described_class } subject { described_class }
describe '#mask' do describe '#mask' do
......
...@@ -119,7 +119,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver do ...@@ -119,7 +119,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
it 'has no when YML attributes but only the DB column' do it 'has no when YML attributes but only the DB column' do
allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file).and_return(File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))) allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file).and_return(File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')))
expect_any_instance_of(Ci::GitlabCiYamlProcessor).not_to receive(:build_attributes) expect_any_instance_of(Gitlab::Ci::YamlProcessor).not_to receive(:build_attributes)
saved_project_json saved_project_json
end end
......
...@@ -4,7 +4,7 @@ describe 'ci/lints/show' do ...@@ -4,7 +4,7 @@ describe 'ci/lints/show' do
include Devise::Test::ControllerHelpers include Devise::Test::ControllerHelpers
describe 'XSS protection' do describe 'XSS protection' do
let(:config_processor) { Ci::GitlabCiYamlProcessor.new(YAML.dump(content)) } let(:config_processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(content)) }
before do before do
assign(:status, true) assign(:status, true)
assign(:builds, config_processor.builds) assign(:builds, config_processor.builds)
...@@ -59,7 +59,7 @@ describe 'ci/lints/show' do ...@@ -59,7 +59,7 @@ describe 'ci/lints/show' do
} }
end end
let(:config_processor) { Ci::GitlabCiYamlProcessor.new(YAML.dump(content)) } let(:config_processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(content)) }
context 'when the content is valid' do context 'when the content is valid' do
before do before 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