Commit 79aeaec9 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Rename all occurrences of type to stage

parent 09e2d0dd
......@@ -93,17 +93,17 @@ class Commit < ActiveRecord::Base
recipients.uniq
end
def job_type
def stage
return unless config_processor
job_types = builds_without_retry.select(&:active?).map(&:job_type)
config_processor.types.find { |job_type| job_types.include? job_type }
stages = builds_without_retry.select(&:active?).map(&:stage)
config_processor.stages.find { |stage| stages.include? stage }
end
def create_builds_for_type(job_type)
def create_builds_for_type(stage)
return if skip_ci?
return unless config_processor
builds_attrs = config_processor.builds_for_type_and_ref(job_type, ref, tag)
builds_attrs = config_processor.builds_for_stage_and_ref(stage, ref, tag)
builds_attrs.map do |build_attrs|
builds.create!({
project: project,
......@@ -112,7 +112,7 @@ class Commit < ActiveRecord::Base
tag_list: build_attrs[:tags],
options: build_attrs[:options],
allow_failure: build_attrs[:allow_failure],
job_type: build_attrs[:type]
stage: build_attrs[:stage]
})
end
end
......@@ -121,10 +121,10 @@ class Commit < ActiveRecord::Base
return if skip_ci?
return unless config_processor
build_types = builds.group_by(&:job_type)
stages = builds.group_by(&:stage)
config_processor.types.any? do |job_type|
!build_types.include?(job_type) && create_builds_for_type(job_type).present?
config_processor.stages.any? do |stage|
!stages.include?(stage) && create_builds_for_type(stage).present?
end
end
......@@ -132,8 +132,8 @@ class Commit < ActiveRecord::Base
return if skip_ci?
return unless config_processor
config_processor.types.any? do |job_type|
create_builds_for_type(job_type).present?
config_processor.stages.any? do |stage|
create_builds_for_type(stage).present?
end
end
......@@ -150,9 +150,9 @@ class Commit < ActiveRecord::Base
def builds_without_retry_sorted
return builds_without_retry unless config_processor
job_types = config_processor.types
stages = config_processor.stages
builds_without_retry.sort_by do |build|
[job_types.index(build.job_type) || -1, build.name || ""]
[stages.index(build.stage) || -1, build.name || ""]
end
end
......
......@@ -7,7 +7,7 @@
%strong Build ##{build.id}
%td
= build.job_type
= build.stage
%td
= build.name
......
......@@ -3,7 +3,7 @@
= commit.status
- if commit.running?
&middot;
= commit.job_type
= commit.stage
%td.build-link
......
......@@ -49,7 +49,7 @@
- unless @commit.push_data[:ci_yaml_file]
.bs-callout.bs-callout-warning
\.gitlab-ci.yml not found in this commit
%h3 Status
.build.alert{class: commit_status_alert_class(@commit)}
......@@ -68,7 +68,7 @@
%tr
%th Status
%th Build ID
%th Type
%th Stage
%th Name
%th Duration
%th Finished at
......@@ -86,7 +86,7 @@
%tr
%th Status
%th Build ID
%th Type
%th Stage
%th Name
%th Duration
%th Finished at
......
......@@ -10,10 +10,10 @@
%th Parameter
%th Value
%tbody
- @types.each do |type|
- @builds.select { |build| build[:type] == type }.each do |build|
- @stages.each do |stage|
- @builds.select { |build| build[:stage] == stage }.each do |build|
%tr
%td #{type.capitalize} Job - #{build[:name]}
%td #{stage.capitalize} Job - #{build[:name]}
%td
%pre
= simple_format build[:script]
......
class RenameJobTypeToStageBuilds < ActiveRecord::Migration
def up
rename_column :builds, :job_type, :stage
end
def down
rename_column :builds, :stage, :job_type
end
end
class GitlabCiYamlProcessor
class ValidationError < StandardError;end
DEFAULT_TYPES = %w(build test deploy)
DEFAULT_TYPE = 'test'
DEFAULT_STAGES = %w(build test deploy)
DEFAULT_STAGE = 'test'
ALLOWED_JOB_KEYS = [:tags, :script, :only, :except, :type, :image, :services, :allow_failure, :type, :stage]
attr_reader :before_script, :image, :services
......@@ -21,8 +21,8 @@ class GitlabCiYamlProcessor
validate!
end
def builds_for_type_and_ref(type, ref, tag = false)
builds.select{|build| build[:type] == type && process?(build[:only], build[:except], ref, tag)}
def builds_for_stage_and_ref(stage, ref, tag = false)
builds.select{|build| build[:stage] == stage && process?(build[:only], build[:except], ref, tag)}
end
def builds
......@@ -31,8 +31,8 @@ class GitlabCiYamlProcessor
end
end
def types
@types || DEFAULT_TYPES
def stages
@stages || DEFAULT_STAGES
end
private
......@@ -41,7 +41,7 @@ class GitlabCiYamlProcessor
@before_script = @config[:before_script] || []
@image = @config[:image]
@services = @config[:services]
@types = @config[:stages] || @config[:types]
@stages = @config[:stages] || @config[:types]
@config.except!(:before_script, :image, :services, :types, :stages)
@config.each do |name, param|
......@@ -52,7 +52,11 @@ class GitlabCiYamlProcessor
raise ValidationError, "Please define at least one job"
end
@jobs = @config
@jobs = {}
@config.each do |key, job|
stage = job[:stage] || job[:type] || DEFAULT_STAGE
@jobs[key] = { stage: stage }.merge(job)
end
end
def process?(only_params, except_params, ref, tag)
......@@ -77,7 +81,7 @@ class GitlabCiYamlProcessor
def build_job(name, job)
{
type: job[:stage] || job[:type] || DEFAULT_TYPE,
stage: job[:stage],
script: "#{@before_script.join("\n")}\n#{normalize_script(job[:script])}",
tags: job[:tags] || [],
name: name,
......@@ -120,8 +124,8 @@ class GitlabCiYamlProcessor
raise ValidationError, "services should be an array of strings"
end
unless @types.nil? || validate_array_of_strings(@types)
raise ValidationError, "types should be an array of strings"
unless @stages.nil? || validate_array_of_strings(@stages)
raise ValidationError, "stages should be an array of strings"
end
@jobs.each do |name, job|
......@@ -139,14 +143,8 @@ class GitlabCiYamlProcessor
end
if job[:stage]
unless job[:stage].is_a?(String) && job[:stage].in?(types)
raise ValidationError, "#{name}: stage parameter should be #{types.join(", ")}"
end
end
if job[:type]
unless job[:type].is_a?(String) && job[:type].in?(types)
raise ValidationError, "#{name}: type parameter should be #{types.join(", ")}"
unless job[:stage].is_a?(String) && job[:stage].in?(stages)
raise ValidationError, "#{name}: stage parameter should be #{stages.join(", ")}"
end
end
......
......@@ -13,8 +13,8 @@ describe GitlabCiYamlProcessor do
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_type_and_ref(type, "master").size.should == 1
config_processor.builds_for_type_and_ref(type, "master").first.should == {
config_processor.builds_for_stage_and_ref(type, "master").size.should == 1
config_processor.builds_for_stage_and_ref(type, "master").first.should == {
type: "test",
except: nil,
name: :rspec,
......@@ -34,7 +34,7 @@ describe GitlabCiYamlProcessor do
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_type_and_ref(type, "master").size.should == 0
config_processor.builds_for_stage_and_ref(type, "master").size.should == 0
end
it "does not return builds if only has regexp with another branch" do
......@@ -45,7 +45,7 @@ describe GitlabCiYamlProcessor do
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_type_and_ref(type, "master").size.should == 0
config_processor.builds_for_stage_and_ref(type, "master").size.should == 0
end
it "returns builds if only has specified this branch" do
......@@ -56,7 +56,7 @@ describe GitlabCiYamlProcessor do
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_type_and_ref(type, "master").size.should == 1
config_processor.builds_for_stage_and_ref(type, "master").size.should == 1
end
it "does not build tags" do
......@@ -67,7 +67,7 @@ describe GitlabCiYamlProcessor do
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_type_and_ref(type, "0-1", true).size.should == 0
config_processor.builds_for_stage_and_ref(type, "0-1", true).size.should == 0
end
it "returns builds if only has a list of branches including specified" do
......@@ -78,7 +78,7 @@ describe GitlabCiYamlProcessor do
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_type_and_ref(type, "deploy").size.should == 1
config_processor.builds_for_stage_and_ref(type, "deploy").size.should == 1
end
it "returns build only for specified type" do
......@@ -93,9 +93,9 @@ describe GitlabCiYamlProcessor do
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_type_and_ref("production", "deploy").size.should == 0
config_processor.builds_for_type_and_ref(type, "deploy").size.should == 1
config_processor.builds_for_type_and_ref("deploy", "deploy").size.should == 2
config_processor.builds_for_stage_and_ref("production", "deploy").size.should == 0
config_processor.builds_for_stage_and_ref(type, "deploy").size.should == 1
config_processor.builds_for_stage_and_ref("deploy", "deploy").size.should == 2
end
end
......@@ -110,8 +110,8 @@ describe GitlabCiYamlProcessor do
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_type_and_ref("test", "master").size.should == 1
config_processor.builds_for_type_and_ref("test", "master").first.should == {
config_processor.builds_for_stage_and_ref("test", "master").size.should == 1
config_processor.builds_for_stage_and_ref("test", "master").first.should == {
except: nil,
type: "test",
name: :rspec,
......@@ -136,8 +136,8 @@ describe GitlabCiYamlProcessor do
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.builds_for_type_and_ref("test", "master").size.should == 1
config_processor.builds_for_type_and_ref("test", "master").first.should == {
config_processor.builds_for_stage_and_ref("test", "master").size.should == 1
config_processor.builds_for_stage_and_ref("test", "master").first.should == {
except: nil,
type: "test",
name: :rspec,
......
Supports Markdown
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