diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-08-03 16:25:16 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-08-03 16:25:16 +0200 |
commit | 79aeaec98b55ef68bae9bf0a5cb61fbe4e649279 (patch) | |
tree | 12f124b08711f4ebf899031294745015c0df9119 | |
parent | 09e2d0dd59d74c2ae58150d8a3b633b9a6a45986 (diff) | |
download | gitlab-ci-79aeaec98b55ef68bae9bf0a5cb61fbe4e649279.tar.gz |
Rename all occurrences of type to stage
-rw-r--r-- | app/models/commit.rb | 26 | ||||
-rw-r--r-- | app/views/builds/_build.html.haml | 2 | ||||
-rw-r--r-- | app/views/commits/_commit.html.haml | 2 | ||||
-rw-r--r-- | app/views/commits/show.html.haml | 6 | ||||
-rw-r--r-- | app/views/lints/_create.html.haml | 6 | ||||
-rw-r--r-- | db/migrate/20150803142346_rename_job_type_to_stage_builds.rb | 9 | ||||
-rw-r--r-- | lib/gitlab_ci_yaml_processor.rb | 36 | ||||
-rw-r--r-- | spec/lib/gitlab_ci_yaml_processor_spec.rb | 28 |
8 files changed, 61 insertions, 54 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index eea3653..7c1a015 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -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 diff --git a/app/views/builds/_build.html.haml b/app/views/builds/_build.html.haml index 598f734..4fa90c1 100644 --- a/app/views/builds/_build.html.haml +++ b/app/views/builds/_build.html.haml @@ -7,7 +7,7 @@ %strong Build ##{build.id} %td - = build.job_type + = build.stage %td = build.name diff --git a/app/views/commits/_commit.html.haml b/app/views/commits/_commit.html.haml index a273f09..59e116a 100644 --- a/app/views/commits/_commit.html.haml +++ b/app/views/commits/_commit.html.haml @@ -3,7 +3,7 @@ = commit.status - if commit.running? · - = commit.job_type + = commit.stage %td.build-link diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index d335754..2c1f40c 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -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 diff --git a/app/views/lints/_create.html.haml b/app/views/lints/_create.html.haml index f82b406..458af71 100644 --- a/app/views/lints/_create.html.haml +++ b/app/views/lints/_create.html.haml @@ -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] diff --git a/db/migrate/20150803142346_rename_job_type_to_stage_builds.rb b/db/migrate/20150803142346_rename_job_type_to_stage_builds.rb new file mode 100644 index 0000000..816df0d --- /dev/null +++ b/db/migrate/20150803142346_rename_job_type_to_stage_builds.rb @@ -0,0 +1,9 @@ +class RenameJobTypeToStageBuilds < ActiveRecord::Migration + def up + rename_column :builds, :job_type, :stage + end + + def down + rename_column :builds, :stage, :job_type + end +end diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb index 20b9d7f..b88b682 100644 --- a/lib/gitlab_ci_yaml_processor.rb +++ b/lib/gitlab_ci_yaml_processor.rb @@ -1,8 +1,8 @@ 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 diff --git a/spec/lib/gitlab_ci_yaml_processor_spec.rb b/spec/lib/gitlab_ci_yaml_processor_spec.rb index c6d6832..db2348a 100644 --- a/spec/lib/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/gitlab_ci_yaml_processor_spec.rb @@ -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, |