Commit 611071d9 authored by Allison Browne's avatar Allison Browne

Namespace Ci files

TriggersHelper -> Ci::TriggersHelper
Enums::CommitStatus -> Enums::Ci::CommitStatus
CommitWithPipeline -> Ci::CommitWithPipeline
parent 31c61f62
# frozen_string_literal: true
class Projects::MattermostsController < Projects::ApplicationController
include TriggersHelper
include Ci::TriggersHelper
include ActionView::Helpers::AssetUrlHelper
layout 'project_settings'
......
# frozen_string_literal: true
module TriggersHelper
module Ci::TriggersHelper
def builds_trigger_url(project_id, ref: nil)
if ref.nil?
"#{Settings.gitlab.url}/api/v4/projects/#{project_id}/trigger/pipeline"
......
# frozen_string_literal: true
class Ci::CommitWithPipeline < SimpleDelegator
include Presentable
def initialize(commit)
@latest_pipelines = {}
super(commit)
end
def pipelines
project.ci_pipelines.where(sha: sha)
end
def last_pipeline
strong_memoize(:last_pipeline) do
pipelines.last
end
end
def latest_pipeline(ref = nil)
@latest_pipelines.fetch(ref) do |ref|
@latest_pipelines[ref] = latest_pipeline_for_project(ref, project)
end
end
def latest_pipeline_for_project(ref, pipeline_project)
pipeline_project.ci_pipelines.latest_pipeline_per_commit(id, ref)[id]
end
def set_latest_pipeline_for_ref(ref, pipeline)
@latest_pipelines[ref] = pipeline
end
def status(ref = nil)
latest_pipeline(ref)&.status
end
end
......@@ -148,7 +148,7 @@ class Commit
to: :with_pipeline
def with_pipeline
@with_pipeline ||= CommitWithPipeline.new(self)
@with_pipeline ||= Ci::CommitWithPipeline.new(self)
end
def id
......
......@@ -80,9 +80,9 @@ class CommitStatus < ApplicationRecord
merge(or_conditions)
end
# We use `Enums::CommitStatus.failure_reasons` here so that EE can more easily
# We use `Enums::Ci::CommitStatus.failure_reasons` here so that EE can more easily
# extend this `Hash` with new values.
enum_with_nil failure_reason: Enums::CommitStatus.failure_reasons
enum_with_nil failure_reason: Enums::Ci::CommitStatus.failure_reasons
##
# We still create some CommitStatuses outside of CreatePipelineService.
......
# frozen_string_literal: true
class CommitWithPipeline < SimpleDelegator
class Ci::CommitWithPipeline < SimpleDelegator
include Presentable
def initialize(commit)
......
# frozen_string_literal: true
module Enums
module Ci
module CommitStatus
# Returns the Hash to use for creating the `failure_reason` enum for
# `CommitStatus`.
def self.failure_reasons
{
unknown_failure: nil,
script_failure: 1,
api_failure: 2,
stuck_or_timeout_failure: 3,
runner_system_failure: 4,
missing_dependency_failure: 5,
runner_unsupported: 6,
stale_schedule: 7,
job_execution_timeout: 8,
archived_failure: 9,
unmet_prerequisites: 10,
scheduler_failure: 11,
data_integrity_failure: 12,
forward_deployment_failure: 13,
insufficient_bridge_permissions: 1_001,
downstream_bridge_project_not_found: 1_002,
invalid_bridge_trigger: 1_003,
bridge_pipeline_is_child_pipeline: 1_006, # not used anymore, but cannot be deleted because of old data
downstream_pipeline_creation_failed: 1_007,
secrets_provider_not_found: 1_008,
reached_max_descendant_pipelines_depth: 1_009
}
end
end
end
end
Enums::Ci::CommitStatus.prepend_if_ee('EE::Enums::Ci::CommitStatus')
# frozen_string_literal: true
module Enums
module CommitStatus
# Returns the Hash to use for creating the `failure_reason` enum for
# `CommitStatus`.
def self.failure_reasons
{
unknown_failure: nil,
script_failure: 1,
api_failure: 2,
stuck_or_timeout_failure: 3,
runner_system_failure: 4,
missing_dependency_failure: 5,
runner_unsupported: 6,
stale_schedule: 7,
job_execution_timeout: 8,
archived_failure: 9,
unmet_prerequisites: 10,
scheduler_failure: 11,
data_integrity_failure: 12,
forward_deployment_failure: 13,
insufficient_bridge_permissions: 1_001,
downstream_bridge_project_not_found: 1_002,
invalid_bridge_trigger: 1_003,
bridge_pipeline_is_child_pipeline: 1_006, # not used anymore, but cannot be deleted because of old data
downstream_pipeline_creation_failed: 1_007,
secrets_provider_not_found: 1_008,
reached_max_descendant_pipelines_depth: 1_009
}
end
end
end
Enums::CommitStatus.prepend_if_ee('EE::Enums::CommitStatus')
# frozen_string_literal: true
class MattermostSlashCommandsService < SlashCommandsService
include TriggersHelper
include Ci::TriggersHelper
prop_accessor :token
......
# frozen_string_literal: true
class SlackSlashCommandsService < SlashCommandsService
include TriggersHelper
include Ci::TriggersHelper
def title
'Slack slash commands'
......
# frozen_string_literal: true
module EE
module Enums
module Ci
module CommitStatus
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :failure_reasons
def failure_reasons
super.merge(protected_environment_failure: 1_000,
upstream_bridge_project_not_found: 1_004,
insufficient_upstream_permissions: 1_005)
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module Enums
module CommitStatus
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :failure_reasons
def failure_reasons
super.merge(protected_environment_failure: 1_000,
upstream_bridge_project_not_found: 1_004,
insufficient_upstream_permissions: 1_005)
end
end
end
end
end
......@@ -259,7 +259,7 @@ RSpec.describe 'Dashboard Projects' do
# 4. ProjectsHelper#load_pipeline_status
# 5. RendersMemberAccess#preload_max_member_access_for_collection
# 6. User#max_member_access_for_project_ids
# 7. CommitWithPipeline#last_pipeline
# 7. Ci::CommitWithPipeline#last_pipeline
expect { visit dashboard_projects_path }.not_to exceed_query_limit(control_count + 7)
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::TriggersHelper do
let(:project_id) { 1 }
describe '.builds_trigger_url' do
subject { helper.builds_trigger_url(project_id, ref: ref) }
context 'with no ref' do
let(:ref) { nil }
specify { expect(subject).to eq "#{Settings.gitlab.url}/api/v4/projects/1/trigger/pipeline" }
end
context 'with ref' do
let(:ref) { 'master' }
specify { expect(subject).to eq "#{Settings.gitlab.url}/api/v4/projects/1/ref/master/trigger/pipeline" }
end
end
describe '.service_trigger_url' do
subject { helper.service_trigger_url(service) }
let(:service) { double(project_id: 1, to_param: 'param') }
specify { expect(subject).to eq "#{Settings.gitlab.url}/api/v4/projects/1/services/param/trigger" }
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe CommitWithPipeline do
RSpec.describe Ci::CommitWithPipeline do
let(:project) { create(:project, :public, :repository) }
let(:commit) { described_class.new(project.commit) }
......
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