summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-06-19 14:58:49 +0000
committerValery Sizov <valery@gitlab.com>2015-06-19 14:58:49 +0000
commitebf09aad0f32a86650e080d6832b5b124b7de0e7 (patch)
treebc4c307fe361d0caa380a64bbfe4ede9c47f5a18 /app
parent274f5302edbb77be3034c56410bf3021ffe053cc (diff)
parentc61492a1f44abe3236ef0d43118b7e3da9fb4f4d (diff)
downloadgitlab-ci-ebf09aad0f32a86650e080d6832b5b124b7de0e7.tar.gz
Merge branch 'better_yaml_validation_step2' into 'master'
Yaml refactoring and fixes This refactoring also fixes some bugs with validation. https://dev.gitlab.org/gitlab/gitlab-ci/issues/281 See merge request !152
Diffstat (limited to 'app')
-rw-r--r--app/controllers/lints_controller.rb4
-rw-r--r--app/models/commit.rb12
-rw-r--r--app/services/create_commit_service.rb13
-rw-r--r--app/views/lints/_create.html.haml3
4 files changed, 9 insertions, 23 deletions
diff --git a/app/controllers/lints_controller.rb b/app/controllers/lints_controller.rb
index d1b42f6..33ee206 100644
--- a/app/controllers/lints_controller.rb
+++ b/app/controllers/lints_controller.rb
@@ -7,12 +7,12 @@ class LintsController < ApplicationController
def create
if params[:content].blank?
@status = false
- @error = "Please provide content of your file"
+ @error = "Please provide content of .gitlab-ci.yml"
else
@config_processor = GitlabCiYamlProcessor.new params[:content]
@status = true
end
- rescue Psych::SyntaxError => e
+ rescue GitlabCiYamlProcessor::ValidationError => e
@error = e.message
@status = false
rescue Exception => e
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 1d3f214..46900ab 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -94,12 +94,10 @@ class Commit < ActiveRecord::Base
def create_builds
return if skip_ci?
- 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 GitlabCiYamlProcessor::ValidationError => e
+ save_yaml_error(e.message) and return
rescue Exception => e
logger.error e.message + "\n" + e.backtrace.join("\n")
save_yaml_error("Undefined yaml error") and return
@@ -132,12 +130,10 @@ class Commit < ActiveRecord::Base
def create_deploy_builds
return if skip_ci?
- 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 GitlabCiYamlProcessor::ValidationError => e
+ save_yaml_error(e.message) and return
rescue Exception => e
logger.error e.message + "\n" + e.backtrace.join("\n")
save_yaml_error("Undefined yaml error") and return
diff --git a/app/services/create_commit_service.rb b/app/services/create_commit_service.rb
index de5ece3..df678d4 100644
--- a/app/services/create_commit_service.rb
+++ b/app/services/create_commit_service.rb
@@ -4,8 +4,7 @@ class CreateCommitService
sha = params[:checkout_sha] || params[:after]
origin_ref = params[:ref]
yaml_config = params[:ci_yaml_file] || project.generated_yaml_config
- config_processor = build_config_processor(yaml_config)
-
+
unless origin_ref && sha.present?
return false
end
@@ -17,10 +16,6 @@ class CreateCommitService
return false
end
- unless config_processor.any_jobs?(ref, origin_ref.start_with?('refs/tags/'))
- return false
- end
-
commit = project.commits.find_by_sha_and_ref(sha, ref)
# Create commit if not exists yet
@@ -54,10 +49,4 @@ class CreateCommitService
commit
end
-
- private
-
- def build_config_processor(config_data)
- @builds_config ||= GitlabCiYamlProcessor.new(config_data)
- end
end
diff --git a/app/views/lints/_create.html.haml b/app/views/lints/_create.html.haml
index 34920d7..454ca4b 100644
--- a/app/views/lints/_create.html.haml
+++ b/app/views/lints/_create.html.haml
@@ -47,6 +47,7 @@
%b Status:
syntax is incorrect
%i.icon-remove.incorrect-syntax
- Error: #{@error}
+ %b Error:
+ = @error
\ No newline at end of file