diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-06-09 16:26:50 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-06-09 17:53:42 +0300 |
commit | 8fd43216598bc74b3dea2188ff7262081999de33 (patch) | |
tree | 38bb4b4464e4a9dea40af30af869151ef63e4029 | |
parent | dedabbc0243cc7aa401c49f35b4e100ff2d95fa3 (diff) | |
download | gitlab-ci-8fd43216598bc74b3dea2188ff7262081999de33.tar.gz |
Lint implementation
-rw-r--r-- | app/assets/stylesheets/sections/lint.scss | 8 | ||||
-rw-r--r-- | app/controllers/lints_controller.rb | 20 | ||||
-rw-r--r-- | app/views/lints/_create.html.haml | 53 | ||||
-rw-r--r-- | app/views/lints/create.js.haml | 2 | ||||
-rw-r--r-- | app/views/lints/show.html.haml | 26 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | lib/gitlab_ci_yaml_processor.rb | 6 |
7 files changed, 114 insertions, 3 deletions
diff --git a/app/assets/stylesheets/sections/lint.scss b/app/assets/stylesheets/sections/lint.scss new file mode 100644 index 0000000..7191b5d --- /dev/null +++ b/app/assets/stylesheets/sections/lint.scss @@ -0,0 +1,8 @@ +.incorrect-syntax{ + font-size: 19px; + color: red; +} +.correct-syntax{ + font-size: 19px; + color: #47a447; +}
\ No newline at end of file diff --git a/app/controllers/lints_controller.rb b/app/controllers/lints_controller.rb new file mode 100644 index 0000000..1a9cd92 --- /dev/null +++ b/app/controllers/lints_controller.rb @@ -0,0 +1,20 @@ +class LintsController < ApplicationController + def show + end + + def create + if params[:content].blank? + @status = false + @error = "Please provide content of your file" + else + @config_processor = GitlabCiYamlProcessor.new params[:content] + @status = true + end + rescue Psych::SyntaxError => e + @error = e.message + @status = false + rescue Exception => e + @error = "Undefined error" + @status = false + end +end
\ No newline at end of file diff --git a/app/views/lints/_create.html.haml b/app/views/lints/_create.html.haml new file mode 100644 index 0000000..64a7d65 --- /dev/null +++ b/app/views/lints/_create.html.haml @@ -0,0 +1,53 @@ +- if @status + %p + %b Status: + syntax is correct + %i.icon-ok.correct-syntax + + %table.table.table-bordered + %thead + %tr + %th Parameter + %th Value + %tbody + - @config_processor.builds.each do |build| + %tr + %td Job - #{build[:name]} + %td + %pre + = simple_format build[:commands] + + %b Tag list: + #{build[:tag_list]} + %br + %b Build for branches: + #{build[:branches] ? "true": "false"} + %br + %b Build for tags: + #{build[:tags] ? "true": "false"} + + - @config_processor.deploy_builds.each do |build| + %tr + %td Deploy Job - #{build[:name]} + %td + %pre + = simple_format build[:commands] + + %b Tag list: + #{build[:tag_list]} + %br + %b Refs: + #{build[:refs]} + + %tr + %td Skip Refs + %td= @config_processor.skip_refs + +-else + %p + %b Status: + syntax is incorrect + %i.icon-remove.incorrect-syntax + Error: #{@error} + +
\ No newline at end of file diff --git a/app/views/lints/create.js.haml b/app/views/lints/create.js.haml new file mode 100644 index 0000000..a96c0b1 --- /dev/null +++ b/app/views/lints/create.js.haml @@ -0,0 +1,2 @@ +:plain + $(".results").html("#{escape_javascript(render "create")}")
\ No newline at end of file diff --git a/app/views/lints/show.html.haml b/app/views/lints/show.html.haml new file mode 100644 index 0000000..0fc22aa --- /dev/null +++ b/app/views/lints/show.html.haml @@ -0,0 +1,26 @@ +%h2 Check your .gitlab-ci.yml +%hr + += form_tag '/lint', method: :post, remote: true do + .control-group + = label_tag "Content of .gitlab-ci.yml", nil, class: 'control-label' + .controls + = text_area_tag :content, nil, class: 'form-control span1', rows: 7, require: true + + .control-group.clearfix + .controls.pull-left.prepend-top-10 + = submit_tag "Validate", class: 'btn btn-success submit-yml' + + +%p.text-center.loading + %i.icon-refresh.icon-spin + +.results.prepend-top-20 + +:coffeescript + $(".loading").hide() + $('form').bind 'ajax:beforeSend', -> + $(".loading").show() + $('form').bind 'ajax:complete', -> + $(".loading").hide() + $(".submit-yml").reset() diff --git a/config/routes.rb b/config/routes.rb index 7ad8220..bc77ee8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,8 @@ Rails.application.routes.draw do API::API.logger Rails.logger mount API::API => '/api' + resource :lint, only: [:show, :create] + resource :help do get :oauth2 end diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb index 3368232..216fb90 100644 --- a/lib/gitlab_ci_yaml_processor.rb +++ b/lib/gitlab_ci_yaml_processor.rb @@ -41,7 +41,7 @@ class GitlabCiYamlProcessor def deploy_builds_for_ref(ref) deploy_builds.select do |build_attrs| refs = build_attrs.delete(:refs) - refs.empty? || refs_matches?(refs, ref) + refs.blank? || refs_matches?(refs.split(",").map(&:strip), ref) end end @@ -84,11 +84,11 @@ class GitlabCiYamlProcessor def normalized_deploy_jobs @deploy_jobs.map do |job| if job.is_a?(String) - { script: job, runner: "", refs: [], name: job[0..10].strip } + { script: job, runner: "", refs: "", name: job[0..10].strip } else { script: normalized_script(job[:script]), - refs: (job[:refs] || "").split(",").map(&:strip), + refs: job[:refs] || "", name: job[:name] || job[:script][0..10].strip, runner: job[:runner] || "", } |