summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-06-17 12:31:34 +0000
committerValery Sizov <valery@gitlab.com>2015-06-17 12:31:34 +0000
commit18f4faa0de065ffb8557563acebc46748d7a1bf7 (patch)
treeb8e60abe404df3a38e373f30b23ed03ba17a65b1
parent76f1f51d19576bff64c4a0f2e14a896a7663a205 (diff)
parent0f1ff722c8db48a5648c50838e07326c004d73f8 (diff)
downloadgitlab-ci-18f4faa0de065ffb8557563acebc46748d7a1bf7.tar.gz
Merge branch 'master_to_7.12-stable' into '7-12-stable'
Master to 7.12 stable See merge request !146
-rw-r--r--CHANGELOG3
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock52
-rw-r--r--app/helpers/gitlab_helper.rb10
-rw-r--r--app/models/commit.rb44
-rw-r--r--app/views/commits/show.html.haml8
-rw-r--r--app/views/projects/_form.html.haml3
-rw-r--r--db/migrate/20150528011012_move_job_name_to_build.rb (renamed from db/migrate/20150528011012_remove_unused_fields.rb)5
-rw-r--r--db/migrate/20150616001155_add_errors_to_commit.rb5
-rw-r--r--db/schema.rb6
-rw-r--r--lib/api/projects.rb4
-rw-r--r--lib/gitlab_ci_yaml_processor.rb46
-rw-r--r--spec/lib/gitlab_ci_yaml_processor_spec.rb10
-rw-r--r--spec/requests/api/projects_spec.rb2
14 files changed, 150 insertions, 50 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 437264f..f3d61d6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -11,6 +11,9 @@ v7.12.0
- Admin area: show amount of runners with last contact less than a minute ago
- Fix re-adding project with the same name but different gitlab_id
- Implementation of Lint (.gitlab-ci.yml validation tool)
+ - Updated rails to 4.1.11
+ - API fix: project create call
+ - Link to web-editor with .gitlab-ci.yml
v7.11.0
- Deploy Jobs API calls
diff --git a/Gemfile b/Gemfile
index c6a81bc..46384fc 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,7 +8,7 @@ def linux_only(require_as)
RUBY_PLATFORM.include?('linux') && require_as
end
-gem 'rails', '4.1.9'
+gem 'rails', '4.1.11'
gem 'activerecord-deprecated_finders'
gem 'activerecord-session_store'
gem "nested_form"
diff --git a/Gemfile.lock b/Gemfile.lock
index 06de7f1..cea1825 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -2,32 +2,32 @@ GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.1)
- actionmailer (4.1.9)
- actionpack (= 4.1.9)
- actionview (= 4.1.9)
+ actionmailer (4.1.11)
+ actionpack (= 4.1.11)
+ actionview (= 4.1.11)
mail (~> 2.5, >= 2.5.4)
- actionpack (4.1.9)
- actionview (= 4.1.9)
- activesupport (= 4.1.9)
+ actionpack (4.1.11)
+ actionview (= 4.1.11)
+ activesupport (= 4.1.11)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
- actionview (4.1.9)
- activesupport (= 4.1.9)
+ actionview (4.1.11)
+ activesupport (= 4.1.11)
builder (~> 3.1)
erubis (~> 2.7.0)
- activemodel (4.1.9)
- activesupport (= 4.1.9)
+ activemodel (4.1.11)
+ activesupport (= 4.1.11)
builder (~> 3.1)
- activerecord (4.1.9)
- activemodel (= 4.1.9)
- activesupport (= 4.1.9)
+ activerecord (4.1.11)
+ activemodel (= 4.1.11)
+ activesupport (= 4.1.11)
arel (~> 5.0.0)
activerecord-deprecated_finders (1.0.3)
activerecord-session_store (0.1.0)
actionpack (>= 4.0.0, < 5)
activerecord (>= 4.0.0, < 5)
railties (>= 4.0.0, < 5)
- activesupport (4.1.9)
+ activesupport (4.1.11)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
@@ -303,19 +303,19 @@ GEM
rack
rack-test (0.6.3)
rack (>= 1.0)
- rails (4.1.9)
- actionmailer (= 4.1.9)
- actionpack (= 4.1.9)
- actionview (= 4.1.9)
- activemodel (= 4.1.9)
- activerecord (= 4.1.9)
- activesupport (= 4.1.9)
+ rails (4.1.11)
+ actionmailer (= 4.1.11)
+ actionpack (= 4.1.11)
+ actionview (= 4.1.11)
+ activemodel (= 4.1.11)
+ activerecord (= 4.1.11)
+ activesupport (= 4.1.11)
bundler (>= 1.3.0, < 2.0)
- railties (= 4.1.9)
+ railties (= 4.1.11)
sprockets-rails (~> 2.0)
- railties (4.1.9)
- actionpack (= 4.1.9)
- activesupport (= 4.1.9)
+ railties (4.1.11)
+ actionpack (= 4.1.11)
+ activesupport (= 4.1.11)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
@@ -490,7 +490,7 @@ DEPENDENCIES
pry
quiet_assets
rack-mini-profiler
- rails (= 4.1.9)
+ rails (= 4.1.11)
rake
rb-fsevent
rb-inotify
diff --git a/app/helpers/gitlab_helper.rb b/app/helpers/gitlab_helper.rb
index 32e2be8..a912da5 100644
--- a/app/helpers/gitlab_helper.rb
+++ b/app/helpers/gitlab_helper.rb
@@ -21,4 +21,14 @@ module GitlabHelper
gitlab_url << "/commit/#{sha}"
link_to Commit.truncate_sha(sha), gitlab_url, no_turbolink
end
+
+ def yaml_web_editor_link(project)
+ commits = project.commits
+
+ if commits.any? && commits.last.push_data[:ci_yaml_file]
+ "#{@project.gitlab_url}/edit/master/.gitlab-ci.yml"
+ else
+ "#{@project.gitlab_url}/new/master"
+ end
+ end
end
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 1dc3e15..1d3f214 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -93,9 +93,19 @@ class Commit < ActiveRecord::Base
def create_builds
return if skip_ci?
- return unless config_processor.valid?
- config_processor.builds_for_ref(ref, tag).each do |build_attrs|
+ unless config_processor.valid?
+ save_yaml_error(config_processor.errors.join(",")) and return
+ end
+
+ begin
+ builds_for_ref = config_processor.builds_for_ref(ref, tag)
+ rescue Exception => e
+ logger.error e.message + "\n" + e.backtrace.join("\n")
+ save_yaml_error("Undefined yaml error") and return
+ end
+
+ builds_for_ref.each do |build_attrs|
builds.create!({
project: project,
name: build_attrs[:name],
@@ -121,9 +131,19 @@ class Commit < ActiveRecord::Base
def create_deploy_builds
return if skip_ci?
- return unless config_processor.valid?
- config_processor.deploy_builds_for_ref(ref, tag).each do |build_attrs|
+ unless config_processor.valid?
+ save_yaml_error(config_processor.errors.join(",")) and return
+ end
+
+ begin
+ deploy_builds_for_ref = config_processor.deploy_builds_for_ref(ref, tag)
+ rescue Exception => e
+ logger.error e.message + "\n" + e.backtrace.join("\n")
+ save_yaml_error("Undefined yaml error") and return
+ end
+
+ deploy_builds_for_ref.each do |build_attrs|
builds.create!({
project: project,
name: build_attrs[:name],
@@ -135,6 +155,10 @@ class Commit < ActiveRecord::Base
end
def status
+ if yaml_errors.present?
+ return 'failed'
+ end
+
if success?
'success'
elsif pending?
@@ -200,11 +224,13 @@ class Commit < ActiveRecord::Base
def skip_ci?
commits = push_data[:commits]
+ commits.present? && commits.last[:message] =~ /(\[ci skip\])/
+ end
- if commits.present? && commits.last[:message] =~ /(\[ci skip\])/
- true
- else
- false
- end
+ private
+
+ def save_yaml_error(error)
+ self.yaml_errors = error
+ save
end
end
diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml
index 3353f78..9ca6222 100644
--- a/app/views/commits/show.html.haml
+++ b/app/views/commits/show.html.haml
@@ -33,7 +33,13 @@
%span.attr-name Created at:
#{@commit.created_at.to_s(:short)}
-
+- if @commit.yaml_errors.present?
+ .bs-callout.bs-callout-danger
+ %h4 Found errors in your .gitlab-ci.yml:
+ %ul
+ - @commit.yaml_errors.split(",").each do |error|
+ %li= error
+
%h3 Status
.build.alert{class: commit_status_alert_class(@commit)}
diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml
index e7c1bad..fca61c6 100644
--- a/app/views/projects/_form.html.haml
+++ b/app/views/projects/_form.html.haml
@@ -1,6 +1,9 @@
.bs-callout.help-callout
%p
If you want to test your .gitlab-ci.yml, you can use special tool - #{link_to "Lint", lint_path}
+ %p
+ Edit your
+ #{link_to ".gitlab-ci.yml using web-editor", yaml_web_editor_link(@project)}
= nested_form_for @project, html: { class: 'form-horizontal' } do |f|
- if @project.errors.any?
diff --git a/db/migrate/20150528011012_remove_unused_fields.rb b/db/migrate/20150528011012_move_job_name_to_build.rb
index 2895169..512ad47 100644
--- a/db/migrate/20150528011012_remove_unused_fields.rb
+++ b/db/migrate/20150528011012_move_job_name_to_build.rb
@@ -1,13 +1,10 @@
-class RemoveUnusedFields < ActiveRecord::Migration
+class MoveJobNameToBuild < ActiveRecord::Migration
def up
select_all("SELECT id, name FROM jobs").each do |job|
execute("UPDATE builds SET name = '#{quote_string(job["name"])}' WHERE job_id = #{job["id"]}")
end
-
- remove_column :builds, :job_id, :integer
end
def down
- add_column :builds, :job_id, :integer
end
end
diff --git a/db/migrate/20150616001155_add_errors_to_commit.rb b/db/migrate/20150616001155_add_errors_to_commit.rb
new file mode 100644
index 0000000..fe9f7b9
--- /dev/null
+++ b/db/migrate/20150616001155_add_errors_to_commit.rb
@@ -0,0 +1,5 @@
+class AddErrorsToCommit < ActiveRecord::Migration
+ def change
+ add_column :commits, :yaml_errors, :text
+ end
+end \ No newline at end of file
diff --git a/db/schema.rb b/db/schema.rb
index 9e1a0df..b1eaef6 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150605002131) do
+ActiveRecord::Schema.define(version: 20150616001155) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -28,6 +28,7 @@ ActiveRecord::Schema.define(version: 20150605002131) do
t.integer "commit_id"
t.float "coverage"
t.text "commands"
+ t.integer "job_id"
t.string "name"
t.boolean "deploy", default: false
end
@@ -45,7 +46,8 @@ ActiveRecord::Schema.define(version: 20150605002131) do
t.text "push_data"
t.datetime "created_at"
t.datetime "updated_at"
- t.boolean "tag", default: false
+ t.boolean "tag", default: false
+ t.text "yaml_errors"
end
add_index "commits", ["project_id", "sha"], name: "index_commits_on_project_id_and_sha", using: :btree
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 3ca099a..0311c56 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -81,13 +81,13 @@ module API
# Example Request:
# POST /projects
post do
- required_attributes! [:name, :gitlab_id, :gitlab_url, :ssh_url_to_repo]
+ required_attributes! [:name, :gitlab_id, :ssh_url_to_repo]
filtered_params = {
name: params[:name],
gitlab_id: params[:gitlab_id],
# we accept gitlab_url for backward compatibility for a while (added to 7.11)
- path: params[:post] || params[:gitlab_url].sub(/.*\/(.*\/.*)$/, '\1'),
+ path: params[:path] || params[:gitlab_url].sub(/.*\/(.*\/.*)$/, '\1'),
default_ref: params[:default_ref] || 'master',
ssh_url_to_repo: params[:ssh_url_to_repo]
}
diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb
index 67903d5..51f412a 100644
--- a/lib/gitlab_ci_yaml_processor.rb
+++ b/lib/gitlab_ci_yaml_processor.rb
@@ -2,7 +2,7 @@ class GitlabCiYamlProcessor
attr_reader :before_script, :skip_refs, :errors
def initialize(config)
- @valid = true
+ @errors = []
@config = YAML.load(config).deep_symbolize_keys
@before_script = @config[:before_script] || []
@@ -14,11 +14,12 @@ class GitlabCiYamlProcessor
@deploy_jobs = @config.select{|key, value| value[:type] == "deploy"}
rescue Exception => e
- @valid = false
+ @errors << "Yaml file is invalid"
end
def valid?
- @valid
+ validate!
+ !@errors.any?
end
def deploy_builds_for_ref(ref, tag = false)
@@ -94,4 +95,43 @@ class GitlabCiYamlProcessor
script
end
end
+
+ def validate!
+ unless @config.is_a? Hash
+ @errors << "should be a hash"
+ return false
+ end
+
+ @jobs.each do |name, job|
+ if job[:tags] && !job[:tags].is_a?(Array)
+ @errors << "#{name} job: tags parameter should be an array"
+ end
+
+ if job[:only] && !job[:only].is_a?(Array)
+ @errors << "#{name} job: only parameter should be an array"
+ end
+
+ if job[:except] && !job[:except].is_a?(Array)
+ @errors << "#{name} job: except parameter should be an array"
+ end
+ end
+
+ @deploy_jobs.each do |name, job|
+ if job[:tags] && !job[:tags].is_a?(Array)
+ @errors << "#{name} deploy job: tags parameter should be an array"
+ end
+
+ if job[:only] && !job[:only].is_a?(Array)
+ @errors << "#{name} deploy job: only parameter should be an array"
+ end
+
+ if job[:except] && !job[:except].is_a?(Array)
+ @errors << "#{name} deploy job: except parameter should be an array"
+ end
+ end
+
+ true
+ rescue
+ @errors << "Undefined error"
+ end
end
diff --git a/spec/lib/gitlab_ci_yaml_processor_spec.rb b/spec/lib/gitlab_ci_yaml_processor_spec.rb
index 14d273a..b101e33 100644
--- a/spec/lib/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/gitlab_ci_yaml_processor_spec.rb
@@ -120,10 +120,18 @@ describe GitlabCiYamlProcessor do
end
describe "Error handling" do
- it "indicated that object is invalid" do
+ it "indicates that object is invalid" do
config_processor = GitlabCiYamlProcessor.new("invalid_yaml\n!ccdvlf%612334@@@@")
config_processor.valid?.should be_false
end
+
+ it "returns errors" do
+ config = YAML.dump({rspec: {tags: "mysql"}})
+ config_processor = GitlabCiYamlProcessor.new(config)
+
+ config_processor.valid?.should be_false
+ config_processor.errors.should == ["rspec job: tags parameter should be an array"]
+ end
end
end \ No newline at end of file
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 7cdd3f4..014a9ef 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -167,7 +167,7 @@ describe API::API do
{
name: "My project",
gitlab_id: 1,
- gitlab_url: "http://example.com/testing/testing",
+ path: "testing/testing",
ssh_url_to_repo: "ssh://example.com/testing/testing.git"
}
}