Add basic implementation of CI/CD bridge job
This commit is contained in:
parent
f6d8fb6e46
commit
320b6d965e
5 changed files with 125 additions and 0 deletions
41
app/models/ci/bridge.rb
Normal file
41
app/models/ci/bridge.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Ci
|
||||
class Bridge < CommitStatus
|
||||
include Importable
|
||||
include AfterCommitQueue
|
||||
include TokenAuthenticatable
|
||||
include Gitlab::Utils::StrongMemoize
|
||||
|
||||
belongs_to :project, inverse_of: :builds
|
||||
|
||||
serialize :options # rubocop:disable Cop/ActiveRecordSerialize
|
||||
validates :ref, presence: true
|
||||
|
||||
before_save :ensure_token
|
||||
|
||||
add_authentication_token_field :token, encrypted: true
|
||||
|
||||
def self.retry(bridge, current_user)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def tags
|
||||
[:bridge]
|
||||
end
|
||||
|
||||
def detailed_status(current_user)
|
||||
Gitlab::Ci::Status::Bridge::Factory
|
||||
.new(self, current_user)
|
||||
.fabricate!
|
||||
end
|
||||
|
||||
def predefined_variables
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def execute_hooks
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
end
|
27
lib/gitlab/ci/status/bridge/common.rb
Normal file
27
lib/gitlab/ci/status/bridge/common.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Gitlab
|
||||
module Ci
|
||||
module Status
|
||||
module Bridge
|
||||
module Common
|
||||
def label
|
||||
subject.description
|
||||
end
|
||||
|
||||
def has_details?
|
||||
false
|
||||
end
|
||||
|
||||
def has_action?
|
||||
false
|
||||
end
|
||||
|
||||
def details_path
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
lib/gitlab/ci/status/bridge/factory.rb
Normal file
15
lib/gitlab/ci/status/bridge/factory.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Gitlab
|
||||
module Ci
|
||||
module Status
|
||||
module Bridge
|
||||
class Factory < Status::Factory
|
||||
def self.common_helpers
|
||||
Status::Bridge::Common
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
spec/factories/ci/bridge.rb
Normal file
17
spec/factories/ci/bridge.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
FactoryBot.define do
|
||||
factory :ci_bridge, class: Ci::Bridge do
|
||||
name ' bridge'
|
||||
stage 'test'
|
||||
stage_idx 0
|
||||
ref 'master'
|
||||
tag false
|
||||
created_at 'Di 29. Okt 09:50:00 CET 2013'
|
||||
status :success
|
||||
|
||||
pipeline factory: :ci_pipeline
|
||||
|
||||
after(:build) do |bridge, evaluator|
|
||||
bridge.project ||= bridge.pipeline.project
|
||||
end
|
||||
end
|
||||
end
|
25
spec/models/ci/bridge_spec.rb
Normal file
25
spec/models/ci/bridge_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Ci::Bridge do
|
||||
set(:project) { create(:project) }
|
||||
set(:pipeline) { create(:ci_pipeline, project: project) }
|
||||
|
||||
let(:bridge) do
|
||||
create(:ci_bridge, pipeline: pipeline)
|
||||
end
|
||||
|
||||
describe '#tags' do
|
||||
it 'only has a bridge tag' do
|
||||
expect(bridge.tags).to eq [:bridge]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#detailed_status' do
|
||||
let(:user) { create(:user) }
|
||||
let(:status) { bridge.detailed_status(user) }
|
||||
|
||||
it 'returns detailed status object' do
|
||||
expect(status).to be_a Gitlab::Ci::Status::Success
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue