diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-10-10 09:05:53 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-10-10 09:05:53 +0100 |
commit | abdfe58503d26137ee0cb3cc17dcbdedcb93d57c (patch) | |
tree | 4f1132f9aa61d5ecb53ebe7fe16b531e5968b232 /app/models/project.rb | |
parent | 058381b6a5a331a85389d12e032117621bab19cc (diff) | |
parent | 43b692cb4b43a476862fb6e7bf4c09edd6035077 (diff) | |
download | gitlab-ce-38869-ci-global.tar.gz |
Merge branch 'master' into 38869-ci-global38869-ci-global
* master: (116 commits)
Fix bad type checking to prevent 0 count badge to be shown
fix incorrect description for advanced settings section of project settings
Introduce new hook data builders for Issue and MergeRequest
Don't create todos for old issue assignees
Start adding Gitlab::HookData::IssuableBuilder
Include the changes in issuable webhook payloads
Rename the `codeclimate` job to `codequality`
Don't show an "Unsubscribe" link in snippet comment notifications
Add QA::Scenario::Gitlab::Group::Create
Removes CommitsList from global namespace
Fix wiki empty page translation namespace not being removed
Fixes mini graph in commit view
Fix link to new i18n index page
Update i18n docs
Move i18n/introduction to i18n/index
Resolve "Simple documentation update - backup to restore in restore section"
Remove AjaxLoadingSpinner and CreateLabelDropdown from global namespace
Move cycle analytics banner into a vue file
Updated Icons + Fix for Collapsed Groups Angle
Don't create fork networks for root projects that are deleted
...
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index e51e70f01b7..57e91ab3b88 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -118,11 +118,20 @@ class Project < ActiveRecord::Base has_one :mock_monitoring_service has_one :microsoft_teams_service + # TODO: replace these relations with the fork network versions has_one :forked_project_link, foreign_key: "forked_to_project_id" has_one :forked_from_project, through: :forked_project_link has_many :forked_project_links, foreign_key: "forked_from_project_id" has_many :forks, through: :forked_project_links, source: :forked_to_project + # TODO: replace these relations with the fork network versions + + has_one :root_of_fork_network, + foreign_key: 'root_project_id', + inverse_of: :root_project, + class_name: 'ForkNetwork' + has_one :fork_network_member + has_one :fork_network, through: :fork_network_member # Merge Requests for target project should be removed with it has_many :merge_requests, foreign_key: 'target_project_id' @@ -180,6 +189,7 @@ class Project < ActiveRecord::Base # bulk that doesn't involve loading the rows into memory. As a result we're # still using `dependent: :destroy` here. has_many :builds, class_name: 'Ci::Build', dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent + has_many :build_trace_section_names, class_name: 'Ci::BuildTraceSectionName' has_many :runner_projects, class_name: 'Ci::RunnerProject' has_many :runners, through: :runner_projects, source: :runner, class_name: 'Ci::Runner' has_many :variables, class_name: 'Ci::Variable' @@ -814,7 +824,7 @@ class Project < ActiveRecord::Base end def cache_has_external_issue_tracker - update_column(:has_external_issue_tracker, services.external_issue_trackers.any?) + update_column(:has_external_issue_tracker, services.external_issue_trackers.any?) if Gitlab::Database.read_write? end def has_wiki? @@ -834,7 +844,7 @@ class Project < ActiveRecord::Base end def cache_has_external_wiki - update_column(:has_external_wiki, services.external_wikis.any?) + update_column(:has_external_wiki, services.external_wikis.any?) if Gitlab::Database.read_write? end def find_or_initialize_services(exceptions: []) @@ -999,6 +1009,11 @@ class Project < ActiveRecord::Base end def forked? + return true if fork_network && fork_network.root_project != self + + # TODO: Use only the above conditional using the `fork_network` + # This is the old conditional that looks at the `forked_project_link`, we + # fall back to this while we're migrating the new models !(forked_project_link.nil? || forked_project_link.forked_from_project.nil?) end @@ -1118,8 +1133,19 @@ class Project < ActiveRecord::Base end end - def forked_from?(project) - forked? && project == forked_from_project + def forked_from?(other_project) + forked? && forked_from_project == other_project + end + + def in_fork_network_of?(other_project) + # TODO: Remove this in a next release when all fork_networks are populated + # This makes sure all MergeRequests remain valid while the projects don't + # have a fork_network yet. + return true if forked_from?(other_project) + + return false if fork_network.nil? || other_project.fork_network.nil? + + fork_network == other_project.fork_network end def origin_merge_requests |