From 8c6db54e1283348f64b46733875db7ffe08993a6 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 17 Nov 2015 13:08:42 +0100 Subject: Extract repository_push_email to separate class --- lib/gitlab/email/repository_push.rb | 116 ++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 lib/gitlab/email/repository_push.rb (limited to 'lib') diff --git a/lib/gitlab/email/repository_push.rb b/lib/gitlab/email/repository_push.rb new file mode 100644 index 00000000000..f484f3cb76d --- /dev/null +++ b/lib/gitlab/email/repository_push.rb @@ -0,0 +1,116 @@ +module Gitlab + module Email + class RepositoryPush + attr_reader :compare, :reverse_compare, :send_from_cmmitter_email, :disable_diffs, + :action, :ref, :author_id + + def initialize(project_id, recipient, opts = {}) + raise ArgumentError, 'Missing arguments: author_id, ref, action' unless + opts[:author_id] && opts[:ref] && opts[:action] + + @project_id = project_id + @recipient = recipient + + @author_id = opts[:author_id] + @ref = opts[:ref] + @action = opts[:action] + + @compare = opts[:compare] || nil + @reverse_compare = opts[:reverse_compare] || false + @send_from_committer_email = opts[:send_from_committer_email] || false + @disable_diffs = opts[:disable_diffs] || false + + @author = author + @project = project + @commits = commits + @diffs = diffs + @ref_name = ref_name + @ref_type = ref_type + @action_name = action_name + end + + def project + Project.find(@project_id) + end + + def author + User.find(@author_id) + end + + def commits + Commit.decorate(@compare.commits, @project) if @compare + end + + def diffs + @compare.diffs if @compare + end + + def action_name + case @action + when :create + 'pushed new' + when :delete + 'deleted' + else + 'pushed to' + end + end + + def subject + subject_text = '[Git]' + subject_text << "[#{@project.path_with_namespace}]" + subject_text << "[#{@ref_name}]" if @action == :push + subject_text << ' ' + + if @action == :push + if @commits.length > 1 + subject_text << "Deleted " if @reverse_compare + subject_text << "#{@commits.length} commits: #{@commits.first.title}" + else + subject_text << "Deleted 1 commit: " if @reverse_compare + subject_text << @commits.first.title + end + end + + subject_action = @action_name.dup + subject_action[0] = subject_action[0].capitalize + subject_text << "#{subject_action} #{@ref_type} #{@ref_name}" + end + + def ref_name + Gitlab::Git.ref_name(@ref) + end + + def ref_type + Gitlab::Git.tag_ref?(@ref) ? 'tag' : 'branch' + end + + def target_url + if action == :push + if @commits.length > 1 + namespace_project_compare_url(@project.namespace, + @project, + from: Commit.new(@compare.base, @project), + to: Commit.new(@compare.head, @project)) + else + namespace_project_commit_url(@project.namespace, + @project, @commits.first) + end + end + + if action != :delete && action != :push + namespace_project_tree_url(@project.namespace, + @project, @ref_name) + end + end + + def reply_to + if @send_from_committer_email && can_send_from_user_email?(@author) + @author.email + else + Gitlab.config.gitlab.email_reply_to + end + end + end + end +end -- cgit v1.2.1 From e2f937ce22e6b0eb458bbdb3fa93b06d80ecfd21 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 18 Nov 2015 10:13:34 +0100 Subject: Refactor RepositoryPush, move to Message namespace --- lib/gitlab/email/message/repository_push.rb | 120 ++++++++++++++++++++++++++++ lib/gitlab/email/repository_push.rb | 116 --------------------------- 2 files changed, 120 insertions(+), 116 deletions(-) create mode 100644 lib/gitlab/email/message/repository_push.rb delete mode 100644 lib/gitlab/email/repository_push.rb (limited to 'lib') diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb new file mode 100644 index 00000000000..bb92df9e1bb --- /dev/null +++ b/lib/gitlab/email/message/repository_push.rb @@ -0,0 +1,120 @@ +module Gitlab + module Email + module Message + class RepositoryPush + attr_reader :compare, :reverse_compare, :send_from_committer_email, + :disable_diffs, :action, :ref, :author_id + attr_accessor :recipient + + def initialize(notify, project_id, recipient, opts = {}) + raise ArgumentError, 'Missing arguments: author_id, ref, action' unless + opts[:author_id] && opts[:ref] && opts[:action] + + @notify = notify + @project_id = project_id + @recipient = recipient + + @author_id = opts[:author_id] + @ref = opts[:ref] + @action = opts[:action] + + @compare = opts[:compare] || nil + @reverse_compare = opts[:reverse_compare] || false + @send_from_committer_email = opts[:send_from_committer_email] || false + @disable_diffs = opts[:disable_diffs] || false + + @author = author + @project = project + @commits = commits + @diffs = diffs + @ref_name = ref_name + @ref_type = ref_type + @action_name = action_name + end + + def project + Project.find(@project_id) + end + + def author + User.find(@author_id) + end + + def commits + Commit.decorate(@compare.commits, @project) if @compare + end + + def diffs + @compare.diffs if @compare + end + + def action_name + case @action + when :create + 'pushed new' + when :delete + 'deleted' + else + 'pushed to' + end + end + + def subject + subject_text = '[Git]' + subject_text << "[#{@project.path_with_namespace}]" + subject_text << "[#{@ref_name}]" if @action == :push + subject_text << ' ' + + if @action == :push + if @commits.length > 1 + subject_text << "Deleted " if @reverse_compare + subject_text << "#{@commits.length} commits: #{@commits.first.title}" + else + subject_text << "Deleted 1 commit: " if @reverse_compare + subject_text << @commits.first.title + end + else + subject_action = @action_name.dup + subject_action[0] = subject_action[0].capitalize + subject_text << "#{subject_action} #{@ref_type} #{@ref_name}" + end + end + + def ref_name + Gitlab::Git.ref_name(@ref) + end + + def ref_type + Gitlab::Git.tag_ref?(@ref) ? 'tag' : 'branch' + end + + def target_url + if @action == :push + if @commits.length > 1 + @notify.namespace_project_compare_url(@project.namespace, + @project, + from: Commit.new(@compare.base, @project), + to: Commit.new(@compare.head, @project)) + else + @notify.namespace_project_commit_url(@project.namespace, + @project, @commits.first) + end + else + unless @action == :delete + @notify.namespace_project_tree_url(@project.namespace, + @project, @ref_name) + end + end + end + + def reply_to + if @send_from_committer_email && @notify.can_send_from_user_email?(@author) + @author.email + else + Gitlab.config.gitlab.email_reply_to + end + end + end + end + end +end diff --git a/lib/gitlab/email/repository_push.rb b/lib/gitlab/email/repository_push.rb deleted file mode 100644 index f484f3cb76d..00000000000 --- a/lib/gitlab/email/repository_push.rb +++ /dev/null @@ -1,116 +0,0 @@ -module Gitlab - module Email - class RepositoryPush - attr_reader :compare, :reverse_compare, :send_from_cmmitter_email, :disable_diffs, - :action, :ref, :author_id - - def initialize(project_id, recipient, opts = {}) - raise ArgumentError, 'Missing arguments: author_id, ref, action' unless - opts[:author_id] && opts[:ref] && opts[:action] - - @project_id = project_id - @recipient = recipient - - @author_id = opts[:author_id] - @ref = opts[:ref] - @action = opts[:action] - - @compare = opts[:compare] || nil - @reverse_compare = opts[:reverse_compare] || false - @send_from_committer_email = opts[:send_from_committer_email] || false - @disable_diffs = opts[:disable_diffs] || false - - @author = author - @project = project - @commits = commits - @diffs = diffs - @ref_name = ref_name - @ref_type = ref_type - @action_name = action_name - end - - def project - Project.find(@project_id) - end - - def author - User.find(@author_id) - end - - def commits - Commit.decorate(@compare.commits, @project) if @compare - end - - def diffs - @compare.diffs if @compare - end - - def action_name - case @action - when :create - 'pushed new' - when :delete - 'deleted' - else - 'pushed to' - end - end - - def subject - subject_text = '[Git]' - subject_text << "[#{@project.path_with_namespace}]" - subject_text << "[#{@ref_name}]" if @action == :push - subject_text << ' ' - - if @action == :push - if @commits.length > 1 - subject_text << "Deleted " if @reverse_compare - subject_text << "#{@commits.length} commits: #{@commits.first.title}" - else - subject_text << "Deleted 1 commit: " if @reverse_compare - subject_text << @commits.first.title - end - end - - subject_action = @action_name.dup - subject_action[0] = subject_action[0].capitalize - subject_text << "#{subject_action} #{@ref_type} #{@ref_name}" - end - - def ref_name - Gitlab::Git.ref_name(@ref) - end - - def ref_type - Gitlab::Git.tag_ref?(@ref) ? 'tag' : 'branch' - end - - def target_url - if action == :push - if @commits.length > 1 - namespace_project_compare_url(@project.namespace, - @project, - from: Commit.new(@compare.base, @project), - to: Commit.new(@compare.head, @project)) - else - namespace_project_commit_url(@project.namespace, - @project, @commits.first) - end - end - - if action != :delete && action != :push - namespace_project_tree_url(@project.namespace, - @project, @ref_name) - end - end - - def reply_to - if @send_from_committer_email && can_send_from_user_email?(@author) - @author.email - else - Gitlab.config.gitlab.email_reply_to - end - end - end - end -end -- cgit v1.2.1 From 4beba7494b096f2540b19017bb7c1c8e91679135 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 20 Nov 2015 15:29:47 +0100 Subject: Improve Messagee::RepositoryPush --- lib/gitlab/email/message/repository_push.rb | 126 ++++++++++++++-------------- 1 file changed, 65 insertions(+), 61 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb index bb92df9e1bb..61962abf822 100644 --- a/lib/gitlab/email/message/repository_push.rb +++ b/lib/gitlab/email/message/repository_push.rb @@ -2,118 +2,122 @@ module Gitlab module Email module Message class RepositoryPush - attr_reader :compare, :reverse_compare, :send_from_committer_email, - :disable_diffs, :action, :ref, :author_id attr_accessor :recipient + attr_reader :author_id, :ref, :action def initialize(notify, project_id, recipient, opts = {}) - raise ArgumentError, 'Missing arguments: author_id, ref, action' unless + raise ArgumentError, 'Missing options: author_id, ref, action' unless opts[:author_id] && opts[:ref] && opts[:action] @notify = notify @project_id = project_id @recipient = recipient + @opts = opts - @author_id = opts[:author_id] - @ref = opts[:ref] - @action = opts[:action] - - @compare = opts[:compare] || nil - @reverse_compare = opts[:reverse_compare] || false - @send_from_committer_email = opts[:send_from_committer_email] || false - @disable_diffs = opts[:disable_diffs] || false - - @author = author - @project = project - @commits = commits - @diffs = diffs - @ref_name = ref_name - @ref_type = ref_type - @action_name = action_name + @author_id = opts.delete(:author_id) + @ref = opts.delete(:ref) + @action = opts.delete(:action) end def project - Project.find(@project_id) + @project ||= Project.find(@project_id) end def author - User.find(@author_id) + @author ||= User.find(@author_id) end def commits - Commit.decorate(@compare.commits, @project) if @compare + @commits ||= (Commit.decorate(compare.commits, project) if compare) end def diffs - @compare.diffs if @compare + @diffs ||= (compare.diffs if compare) end - def action_name - case @action - when :create - 'pushed new' - when :delete - 'deleted' - else - 'pushed to' - end + def compare + @opts[:compare] end - def subject - subject_text = '[Git]' - subject_text << "[#{@project.path_with_namespace}]" - subject_text << "[#{@ref_name}]" if @action == :push - subject_text << ' ' + def reverse_compare? + @opts[:reverse_compare] || false + end - if @action == :push - if @commits.length > 1 - subject_text << "Deleted " if @reverse_compare - subject_text << "#{@commits.length} commits: #{@commits.first.title}" + def disable_diffs? + @opts[:disable_diffs] || false + end + + def send_from_committer_email? + @opts[:send_from_committer_email] || false + end + + def action_name + @action_name ||= + case @action + when :create + 'pushed new' + when :delete + 'deleted' else - subject_text << "Deleted 1 commit: " if @reverse_compare - subject_text << @commits.first.title + 'pushed to' end - else - subject_action = @action_name.dup - subject_action[0] = subject_action[0].capitalize - subject_text << "#{subject_action} #{@ref_type} #{@ref_name}" - end end def ref_name - Gitlab::Git.ref_name(@ref) + @ref_name ||= Gitlab::Git.ref_name(@ref) end def ref_type - Gitlab::Git.tag_ref?(@ref) ? 'tag' : 'branch' + @ref_type ||= Gitlab::Git.tag_ref?(@ref) ? 'tag' : 'branch' end def target_url if @action == :push - if @commits.length > 1 - @notify.namespace_project_compare_url(@project.namespace, - @project, - from: Commit.new(@compare.base, @project), - to: Commit.new(@compare.head, @project)) + if commits.length > 1 && compare + @notify.namespace_project_compare_url(project.namespace, + project, + from: Commit.new(compare.base, project), + to: Commit.new(compare.head, project)) else - @notify.namespace_project_commit_url(@project.namespace, - @project, @commits.first) + @notify.namespace_project_commit_url(project.namespace, + project, commits.first) end else unless @action == :delete - @notify.namespace_project_tree_url(@project.namespace, - @project, @ref_name) + @notify.namespace_project_tree_url(project.namespace, + project, ref_name) end end end def reply_to - if @send_from_committer_email && @notify.can_send_from_user_email?(@author) - @author.email + if send_from_committer_email? && @notify.can_send_from_user_email?(author) + author.email else Gitlab.config.gitlab.email_reply_to end end + + def subject + subject_text = '[Git]' + subject_text << "[#{project.path_with_namespace}]" + subject_text << "[#{ref_name}]" if @action == :push + subject_text << ' ' + + if @action == :push + if commits.length > 1 + subject_text << "Deleted " if reverse_compare? + subject_text << "#{commits.length} commits: #{commits.first.title}" + else + subject_text << "Deleted 1 commit: " if reverse_compare? + subject_text << commits.first.title + end + else + subject_action = action_name.dup + subject_action[0] = subject_action[0].capitalize + subject_text << "#{subject_action} #{ref_type} #{ref_name}" + end + end end end end -- cgit v1.2.1 From 9f2752e5dcc31dc4e9d91ee18caf1d36f1b7684e Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 21 Nov 2015 20:54:19 +0100 Subject: Remove obsolete variables in `repository_push_email` --- lib/gitlab/email/message/repository_push.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb index 61962abf822..b0af3feee9e 100644 --- a/lib/gitlab/email/message/repository_push.rb +++ b/lib/gitlab/email/message/repository_push.rb @@ -5,6 +5,9 @@ module Gitlab attr_accessor :recipient attr_reader :author_id, :ref, :action + delegate :namespace, :name_with_namespace, to: :project, prefix: :project + delegate :name, to: :author, prefix: :author + def initialize(notify, project_id, recipient, opts = {}) raise ArgumentError, 'Missing options: author_id, ref, action' unless opts[:author_id] && opts[:ref] && opts[:action] @@ -35,10 +38,18 @@ module Gitlab @diffs ||= (compare.diffs if compare) end + def diffs_count + diffs.count if diffs + end + def compare @opts[:compare] end + def compare_timeout + compare.timeout if compare + end + def reverse_compare? @opts[:reverse_compare] || false end @@ -74,17 +85,17 @@ module Gitlab def target_url if @action == :push if commits.length > 1 && compare - @notify.namespace_project_compare_url(project.namespace, + @notify.namespace_project_compare_url(project_namespace, project, from: Commit.new(compare.base, project), to: Commit.new(compare.head, project)) else - @notify.namespace_project_commit_url(project.namespace, + @notify.namespace_project_commit_url(project_namespace, project, commits.first) end else unless @action == :delete - @notify.namespace_project_tree_url(project.namespace, + @notify.namespace_project_tree_url(project_namespace, project, ref_name) end end -- cgit v1.2.1 From d835fbc79f6cd6f17fc7472af48074805622a573 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 22 Nov 2015 20:59:31 +0100 Subject: Fix url helpers in RepositoryPush --- lib/gitlab/email/message/repository_push.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb index b0af3feee9e..bc8aece733f 100644 --- a/lib/gitlab/email/message/repository_push.rb +++ b/lib/gitlab/email/message/repository_push.rb @@ -16,6 +16,7 @@ module Gitlab @project_id = project_id @recipient = recipient @opts = opts + @urls = Gitlab::Application.routes.url_helpers @author_id = opts.delete(:author_id) @ref = opts.delete(:ref) @@ -85,17 +86,17 @@ module Gitlab def target_url if @action == :push if commits.length > 1 && compare - @notify.namespace_project_compare_url(project_namespace, + @urls.namespace_project_compare_url(project_namespace, project, from: Commit.new(compare.base, project), to: Commit.new(compare.head, project)) else - @notify.namespace_project_commit_url(project_namespace, + @urls.namespace_project_commit_url(project_namespace, project, commits.first) end else unless @action == :delete - @notify.namespace_project_tree_url(project_namespace, + @urls.namespace_project_tree_url(project_namespace, project, ref_name) end end -- cgit v1.2.1 From 75c6b29f6b15e164717c27e6c3d7eecb84c923f8 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 3 Dec 2015 14:16:16 +0100 Subject: Add `RepositoryPush` specs --- lib/gitlab/email/message/repository_push.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb index bc8aece733f..3526eb2cad9 100644 --- a/lib/gitlab/email/message/repository_push.rb +++ b/lib/gitlab/email/message/repository_push.rb @@ -87,17 +87,17 @@ module Gitlab if @action == :push if commits.length > 1 && compare @urls.namespace_project_compare_url(project_namespace, - project, - from: Commit.new(compare.base, project), - to: Commit.new(compare.head, project)) + project, + from: Commit.new(compare.base, project), + to: Commit.new(compare.head, project)) else @urls.namespace_project_commit_url(project_namespace, - project, commits.first) + project, commits.first) end else unless @action == :delete @urls.namespace_project_tree_url(project_namespace, - project, ref_name) + project, ref_name) end end end -- cgit v1.2.1 From 591035968dc96acd27155ced4c0ae04649fcd113 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 4 Dec 2015 12:55:19 +0000 Subject: Duplicate options in `RepositoryPush` --- lib/gitlab/email/message/repository_push.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb index 3526eb2cad9..ca89b67e580 100644 --- a/lib/gitlab/email/message/repository_push.rb +++ b/lib/gitlab/email/message/repository_push.rb @@ -15,12 +15,12 @@ module Gitlab @notify = notify @project_id = project_id @recipient = recipient - @opts = opts + @opts = opts.dup @urls = Gitlab::Application.routes.url_helpers - @author_id = opts.delete(:author_id) - @ref = opts.delete(:ref) - @action = opts.delete(:action) + @author_id = @opts.delete(:author_id) + @ref = @opts.delete(:ref) + @action = @opts.delete(:action) end def project -- cgit v1.2.1 From 66f658a9b543b1493f625b2f44f3f845d64b749d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 4 Dec 2015 14:11:17 +0100 Subject: Check if commits are available in `RepositoryPush` --- lib/gitlab/email/message/repository_push.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb index ca89b67e580..c53148d2ed8 100644 --- a/lib/gitlab/email/message/repository_push.rb +++ b/lib/gitlab/email/message/repository_push.rb @@ -84,8 +84,8 @@ module Gitlab end def target_url - if @action == :push - if commits.length > 1 && compare + if @action == :push && commits + if commits.length > 1 @urls.namespace_project_compare_url(project_namespace, project, from: Commit.new(compare.base, project), @@ -116,7 +116,7 @@ module Gitlab subject_text << "[#{ref_name}]" if @action == :push subject_text << ' ' - if @action == :push + if @action == :push && commits if commits.length > 1 subject_text << "Deleted " if reverse_compare? subject_text << "#{commits.length} commits: #{commits.first.title}" -- cgit v1.2.1 From 652de0b820587983e0af76186db4570b536d7ce3 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 7 Dec 2015 10:43:07 +0100 Subject: Refactor CI YAML processor's validators --- lib/ci/gitlab_ci_yaml_processor.rb | 66 +++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index 3beafcad117..9c11fc3c81d 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -132,26 +132,36 @@ module Ci end def validate_job!(name, job) + validate_job_name!(name) + validate_job_keys!(name, job) + validate_job_types!(name, job) + + validate_job_stage!(name, job) if job[:stage] + validate_job_cache!(name, job) if job[:cache] + validate_job_artifacts!(name, job) if job[:artifacts] + end + + private + + def validate_job_name!(name) if name.blank? || !validate_string(name) raise ValidationError, "job name should be non-empty string" end + end + def validate_job_keys!(name, job) job.keys.each do |key| unless ALLOWED_JOB_KEYS.include? key raise ValidationError, "#{name} job: unknown parameter #{key}" end end + end + def validate_job_types!(name, job) if !validate_string(job[:script]) && !validate_array_of_strings(job[:script]) raise ValidationError, "#{name} job: script should be a string or an array of a strings" end - if job[:stage] - unless job[:stage].is_a?(String) && job[:stage].in?(stages) - raise ValidationError, "#{name} job: stage parameter should be #{stages.join(", ")}" - end - end - if job[:image] && !validate_string(job[:image]) raise ValidationError, "#{name} job: image should be a string" end @@ -172,36 +182,40 @@ module Ci raise ValidationError, "#{name} job: except parameter should be an array of strings" end - if job[:cache] - if job[:cache][:untracked] && !validate_boolean(job[:cache][:untracked]) - raise ValidationError, "#{name} job: cache:untracked parameter should be an boolean" - end - - if job[:cache][:paths] && !validate_array_of_strings(job[:cache][:paths]) - raise ValidationError, "#{name} job: cache:paths parameter should be an array of strings" - end + if job[:allow_failure] && !validate_boolean(job[:allow_failure]) + raise ValidationError, "#{name} job: allow_failure parameter should be an boolean" end - if job[:artifacts] - if job[:artifacts][:untracked] && !validate_boolean(job[:artifacts][:untracked]) - raise ValidationError, "#{name} job: artifacts:untracked parameter should be an boolean" - end + if job[:when] && !job[:when].in?(%w(on_success on_failure always)) + raise ValidationError, "#{name} job: when parameter should be on_success, on_failure or always" + end + end - if job[:artifacts][:paths] && !validate_array_of_strings(job[:artifacts][:paths]) - raise ValidationError, "#{name} job: artifacts:paths parameter should be an array of strings" - end + def validate_job_stage!(name, job) + unless job[:stage].is_a?(String) && job[:stage].in?(stages) + raise ValidationError, "#{name} job: stage parameter should be #{stages.join(", ")}" end + end - if job[:allow_failure] && !validate_boolean(job[:allow_failure]) - raise ValidationError, "#{name} job: allow_failure parameter should be an boolean" + def validate_job_cache!(name, job) + if job[:cache][:untracked] && !validate_boolean(job[:cache][:untracked]) + raise ValidationError, "#{name} job: cache:untracked parameter should be an boolean" end - if job[:when] && !job[:when].in?(%w(on_success on_failure always)) - raise ValidationError, "#{name} job: when parameter should be on_success, on_failure or always" + if job[:cache][:paths] && !validate_array_of_strings(job[:cache][:paths]) + raise ValidationError, "#{name} job: cache:paths parameter should be an array of strings" end end - private + def validate_job_artifacts!(name, job) + if job[:artifacts][:untracked] && !validate_boolean(job[:artifacts][:untracked]) + raise ValidationError, "#{name} job: artifacts:untracked parameter should be an boolean" + end + + if job[:artifacts][:paths] && !validate_array_of_strings(job[:artifacts][:paths]) + raise ValidationError, "#{name} job: artifacts:paths parameter should be an array of strings" + end + end def validate_array_of_strings(values) values.is_a?(Array) && values.all? { |value| validate_string(value) } -- cgit v1.2.1 From cbeb06eb420f294b3a406f869f11de554048e93d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 11 Dec 2015 13:00:24 +0000 Subject: Mix url helpers in into `RepositoryPush` --- lib/gitlab/email/message/repository_push.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email/message/repository_push.rb b/lib/gitlab/email/message/repository_push.rb index c53148d2ed8..a2eb7a70bd2 100644 --- a/lib/gitlab/email/message/repository_push.rb +++ b/lib/gitlab/email/message/repository_push.rb @@ -5,6 +5,8 @@ module Gitlab attr_accessor :recipient attr_reader :author_id, :ref, :action + include Gitlab::Application.routes.url_helpers + delegate :namespace, :name_with_namespace, to: :project, prefix: :project delegate :name, to: :author, prefix: :author @@ -16,7 +18,6 @@ module Gitlab @project_id = project_id @recipient = recipient @opts = opts.dup - @urls = Gitlab::Application.routes.url_helpers @author_id = @opts.delete(:author_id) @ref = @opts.delete(:ref) @@ -86,18 +87,18 @@ module Gitlab def target_url if @action == :push && commits if commits.length > 1 - @urls.namespace_project_compare_url(project_namespace, - project, - from: Commit.new(compare.base, project), - to: Commit.new(compare.head, project)) + namespace_project_compare_url(project_namespace, + project, + from: Commit.new(compare.base, project), + to: Commit.new(compare.head, project)) else - @urls.namespace_project_commit_url(project_namespace, - project, commits.first) + namespace_project_commit_url(project_namespace, + project, commits.first) end else unless @action == :delete - @urls.namespace_project_tree_url(project_namespace, - project, ref_name) + namespace_project_tree_url(project_namespace, + project, ref_name) end end end -- cgit v1.2.1