From b9ccc79cb5d67e356edce3778b6a17def985ed22 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Wed, 23 Sep 2015 12:47:29 +0200 Subject: Delegate ci_project parameters to projects - It delegates name, path, gitlab_url, ssh_url_to_repo - Remove ability to set this parameters using CI API This fixes GitLab project rename, namespace change, repository rename, etc. --- app/models/ci/project.rb | 40 +++++++++++------------- app/models/project_services/gitlab_ci_service.rb | 6 +--- 2 files changed, 19 insertions(+), 27 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb index 77cce261fc8..f0a8fc703b5 100644 --- a/app/models/ci/project.rb +++ b/app/models/ci/project.rb @@ -48,11 +48,12 @@ module Ci accepts_nested_attributes_for :variables, allow_destroy: true + delegate :name_with_namespace, :path_with_namespace, :web_url, :http_url_to_repo, :ssh_url_to_repo, to: :gl_project + # # Validations # - validates_presence_of :name, :timeout, :token, :default_ref, - :path, :ssh_url_to_repo, :gitlab_id + validates_presence_of :timeout, :token, :default_ref, :gitlab_id validates_uniqueness_of :gitlab_id @@ -60,8 +61,6 @@ module Ci presence: true, if: ->(project) { project.always_build.present? } - scope :public_only, ->() { where(public: true) } - before_validation :set_default_values class << self @@ -76,12 +75,9 @@ module Ci def parse(project) params = { - name: project.name_with_namespace, - gitlab_id: project.id, - path: project.path_with_namespace, - default_ref: project.default_branch || 'master', - ssh_url_to_repo: project.ssh_url_to_repo, - email_add_pusher: current_application_settings.add_pusher, + gitlab_id: project.id, + default_ref: project.default_branch || 'master', + email_add_pusher: current_application_settings.add_pusher, email_only_broken_builds: current_application_settings.all_broken_builds, } @@ -105,11 +101,18 @@ module Ci joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON #{Ci::Project.table_name}.gitlab_id = last_commit.gl_project_id"). order("CASE WHEN last_commit.committed_at IS NULL THEN 1 ELSE 0 END, last_commit.committed_at DESC") end + end - def search(query) - where("LOWER(#{Ci::Project.table_name}.name) LIKE :query", - query: "%#{query.try(:downcase)}%") - end + def name + name_with_namespace + end + + def path + path_with_namespace + end + + def gitlab_url + web_url end def any_runners? @@ -123,9 +126,6 @@ module Ci def set_default_values self.token = SecureRandom.hex(15) if self.token.blank? self.default_ref ||= 'master' - self.name ||= gl_project.name_with_namespace - self.path ||= gl_project.path_with_namespace - self.ssh_url_to_repo ||= gl_project.ssh_url_to_repo end def tracked_refs @@ -169,7 +169,7 @@ module Ci # using http and basic auth def repo_url_with_auth auth = "gitlab-ci-token:#{token}@" - url = gitlab_url + ".git" + url = http_url_to_repo + ".git" url.sub(/^https?:\/\//) do |prefix| prefix + auth end @@ -201,10 +201,6 @@ module Ci end end - def gitlab_url - File.join(Gitlab.config.gitlab.url, path) - end - def setup_finished? commits.any? end diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb index 23ab206efba..436d4cfed81 100644 --- a/app/models/project_services/gitlab_ci_service.rb +++ b/app/models/project_services/gitlab_ci_service.rb @@ -70,11 +70,7 @@ class GitlabCiService < CiService def fork_registration(new_project, current_user) params = OpenStruct.new({ id: new_project.id, - name_with_namespace: new_project.name_with_namespace, - path_with_namespace: new_project.path_with_namespace, - web_url: new_project.web_url, - default_branch: new_project.default_branch, - ssh_url_to_repo: new_project.ssh_url_to_repo + default_branch: new_project.default_branch }) ci_project = Ci::Project.find_by!(gitlab_id: project.id) -- cgit v1.2.3