diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-02-24 17:14:35 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-02-24 17:14:35 +0800 |
commit | 83418ad846d07658303a9e79f14c51cebbb66cfa (patch) | |
tree | f0f06ed3f3654fc6337ad3a5ec0c6397a3871a95 /app/models/ci | |
parent | 91965cefebfa6b2199b9b48e79752bf62cd67305 (diff) | |
parent | c5b29ed6f36779dbb96f4cdc7b1b0bce8bb8dc5e (diff) | |
download | gitlab-ce-83418ad846d07658303a9e79f14c51cebbb66cfa.tar.gz |
Merge remote-tracking branch 'upstream/master' into 27762-add-default-artifacts-expiration
* upstream/master: (247 commits)
Switched CONTRIBUTING.md style guide recommendation for method chaining
Fix new offenses
Stylistic tweaks
Fix OAuth/SAML user blocking behavior
Revert "Enable Style/DotPosition"
Revert "Prefer leading style for Style/DotPosition"
Revert "Enable Style/BarePercentLiterals"
Manually correct autocorrect
Move up delegate calls
Exclude migrations from Style/MutableConstant
ActiveSupport delegation is preferred over Forwardable
Update haml_lint to work with newest rubocop
Add explanations to cops
Update rubocop and rubocop-rspec and regenerate .rubocop_todo.yml
Update rubocop and rubocop-rspec and regenerate .rubocop_todo.yml
Order cops alphabetically
Don’t exclude some file in lib from rubocop
Fix new offenses
Enable Rails/Delegate
Enable Style/WordArray
...
Diffstat (limited to 'app/models/ci')
-rw-r--r-- | app/models/ci/build.rb | 10 | ||||
-rw-r--r-- | app/models/ci/pipeline.rb | 19 | ||||
-rw-r--r-- | app/models/ci/runner.rb | 4 | ||||
-rw-r--r-- | app/models/ci/runner_project.rb | 2 | ||||
-rw-r--r-- | app/models/ci/trigger.rb | 4 |
5 files changed, 19 insertions, 20 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index bfba6425bfe..77aba91f65c 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -22,8 +22,10 @@ module Ci serialize :options serialize :yaml_variables, Gitlab::Serializer::Ci::Variables + delegate :name, to: :project, prefix: true + validates :coverage, numericality: true, allow_blank: true - validates_presence_of :ref + validates :ref, presence: true scope :unstarted, ->() { where(runner_id: nil) } scope :ignore_failures, ->() { where(allow_failure: false) } @@ -233,10 +235,6 @@ module Ci gl_project_id end - def project_name - project.name - end - def repo_url auth = "gitlab-ci-token:#{ensure_token!}@" project.http_url_to_repo.sub(/^https?:\/\//) do |prefix| @@ -257,7 +255,7 @@ module Ci return unless regex matches = text.scan(Regexp.new(regex)).last - matches = matches.last if matches.kind_of?(Array) + matches = matches.last if matches.is_a?(Array) coverage = matches.gsub(/\d+(\.\d+)?/).first if coverage.present? diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index dc4590a9923..80e11a5b58f 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -14,9 +14,11 @@ module Ci has_many :builds, foreign_key: :commit_id has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id - validates_presence_of :sha, unless: :importing? - validates_presence_of :ref, unless: :importing? - validates_presence_of :status, unless: :importing? + delegate :id, to: :project, prefix: true + + validates :sha, presence: { unless: :importing? } + validates :ref, presence: { unless: :importing? } + validates :status, presence: { unless: :importing? } validate :valid_commit_sha, unless: :importing? after_create :keep_around_commits, unless: :importing? @@ -93,8 +95,11 @@ module Ci .select("max(#{quoted_table_name}.id)") .group(:ref, :sha) - relation = ref ? where(ref: ref) : self - relation.where(id: max_id) + if ref + where(ref: ref, id: max_id.where(ref: ref)) + else + where(id: max_id) + end end def self.latest_status(ref = nil) @@ -150,10 +155,6 @@ module Ci builds.latest.with_artifacts_not_expired.includes(project: [:namespace]) end - def project_id - project.id - end - # For now the only user who participates is the user who triggered def participants(_current_user = nil) Array(user) diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 07a086b0aca..4863c34a6a6 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -4,8 +4,8 @@ module Ci RUNNER_QUEUE_EXPIRY_TIME = 60.minutes LAST_CONTACT_TIME = 1.hour.ago - AVAILABLE_SCOPES = %w[specific shared active paused online] - FORM_EDITABLE = %i[description tag_list active run_untagged locked] + AVAILABLE_SCOPES = %w[specific shared active paused online].freeze + FORM_EDITABLE = %i[description tag_list active run_untagged locked].freeze has_many :builds has_many :runner_projects, dependent: :destroy diff --git a/app/models/ci/runner_project.rb b/app/models/ci/runner_project.rb index 1f9baeca5b1..234376a7e4c 100644 --- a/app/models/ci/runner_project.rb +++ b/app/models/ci/runner_project.rb @@ -5,6 +5,6 @@ module Ci belongs_to :runner belongs_to :project, foreign_key: :gl_project_id - validates_uniqueness_of :runner_id, scope: :gl_project_id + validates :runner_id, uniqueness: { scope: :gl_project_id } end end diff --git a/app/models/ci/trigger.rb b/app/models/ci/trigger.rb index 62889fe80d8..39a1dd86241 100644 --- a/app/models/ci/trigger.rb +++ b/app/models/ci/trigger.rb @@ -7,8 +7,8 @@ module Ci belongs_to :project, foreign_key: :gl_project_id has_many :trigger_requests, dependent: :destroy - validates_presence_of :token - validates_uniqueness_of :token + validates :token, presence: true + validates :token, uniqueness: true before_validation :set_default_values |