diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-09-24 17:09:33 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-09-29 10:47:03 +0200 |
commit | 1530f68c9876bc8376bf4aa199c8abda570f5214 (patch) | |
tree | 025a0ff29e9c886a866d0e5c3362947257f75480 /app | |
parent | e1b7fcedfb24353c857a160cd0c981f02fb2542a (diff) | |
download | gitlab-ce-1530f68c9876bc8376bf4aa199c8abda570f5214.tar.gz |
WIP
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/build.rb | 3 | ||||
-rw-r--r-- | app/models/ci/commit.rb | 8 | ||||
-rw-r--r-- | app/models/ci/project.rb | 4 | ||||
-rw-r--r-- | app/models/project.rb | 2 |
4 files changed, 11 insertions, 6 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 8096d4fa5ae..16ff6e38630 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -30,7 +30,6 @@ module Ci LAZY_ATTRIBUTES = ['trace'] belongs_to :commit, class_name: 'Ci::Commit' - belongs_to :project, class_name: 'Ci::Project' belongs_to :runner, class_name: 'Ci::Runner' belongs_to :trigger_request, class_name: 'Ci::TriggerRequest' @@ -137,7 +136,7 @@ module Ci state :canceled, value: 'canceled' end - delegate :sha, :short_sha, :before_sha, :ref, + delegate :sha, :short_sha, :before_sha, :ref, :project, to: :commit, prefix: false def trace_html diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb index f102d0a7679..31638c7e1dc 100644 --- a/app/models/ci/commit.rb +++ b/app/models/ci/commit.rb @@ -18,8 +18,8 @@ module Ci class Commit < ActiveRecord::Base extend Ci::Model - - belongs_to :project, class_name: 'Ci::Project' + + belongs_to :gl_project, class_name: '::Project', foreign_key: :gl_project_id has_many :builds, dependent: :destroy, class_name: 'Ci::Build' has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest' @@ -32,6 +32,10 @@ module Ci sha[0...8] end + def project + @project ||= gl_project.gitlab_ci_project + end + def to_param sha end diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb index 8fb54b90d61..ea7547f5d43 100644 --- a/app/models/ci/project.rb +++ b/app/models/ci/project.rb @@ -33,7 +33,7 @@ module Ci belongs_to :gl_project, class_name: '::Project', foreign_key: :gitlab_id - has_many :commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit' + has_many :commits, through: :gl_project, class_name: 'Ci::Commit', foreign_key: :gl_project_id has_many :builds, through: :commits, dependent: :destroy, class_name: 'Ci::Build' has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject' has_many :runners, through: :runner_projects, class_name: 'Ci::Runner' @@ -41,7 +41,7 @@ module Ci has_many :events, dependent: :destroy, class_name: 'Ci::Event' has_many :variables, dependent: :destroy, class_name: 'Ci::Variable' has_many :triggers, dependent: :destroy, class_name: 'Ci::Trigger' - has_one :last_commit, -> { order 'ci_commits.created_at DESC' }, class_name: 'Ci::Commit' + has_one :last_commit, through: :gl_project, class_name: 'Ci::Commit' # Project services has_many :services, dependent: :destroy, class_name: 'Ci::Service' diff --git a/app/models/project.rb b/app/models/project.rb index e912c48467d..efa573c82b9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -118,6 +118,8 @@ class Project < ActiveRecord::Base has_many :deploy_keys, through: :deploy_keys_projects has_many :users_star_projects, dependent: :destroy has_many :starrers, through: :users_star_projects, source: :user + has_many :commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit', foreign_key: :gl_project_id + has_one :last_commit, -> { order 'ci_commits.created_at DESC' }, class_name: 'Ci::Commit', foreign_key: :gl_project_id has_one :import_data, dependent: :destroy, class_name: "ProjectImportData" has_one :gitlab_ci_project, dependent: :destroy, class_name: "Ci::Project", foreign_key: :gitlab_id |