summaryrefslogtreecommitdiff
path: root/app/models/project_auto_devops.rb
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-06-07 20:27:30 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2018-06-07 20:27:30 +0200
commitb780efab26b83124bd42abf276d0fc388ae68309 (patch)
treefdd5e88008aa897e68df61cffedf61a617a7aeee /app/models/project_auto_devops.rb
parent2bc1835597446a1240cfb364d1943feb4080e675 (diff)
parentba4dc01ea83c261c4054c32482b021a1005a1968 (diff)
downloadgitlab-ce-b780efab26b83124bd42abf276d0fc388ae68309.tar.gz
Merge remote-tracking branch 'origin/master' into 38542-application-control-panel-in-settings-page
Diffstat (limited to 'app/models/project_auto_devops.rb')
-rw-r--r--app/models/project_auto_devops.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/project_auto_devops.rb b/app/models/project_auto_devops.rb
index a6f728e478e..d7d6aaceb27 100644
--- a/app/models/project_auto_devops.rb
+++ b/app/models/project_auto_devops.rb
@@ -11,6 +11,8 @@ class ProjectAutoDevops < ActiveRecord::Base
validates :domain, allow_blank: true, hostname: { allow_numeric_hostname: true }
+ after_save :create_gitlab_deploy_token, if: :needs_to_create_deploy_token?
+
def instance_domain
Gitlab::CurrentSettings.auto_devops_domain
end
@@ -32,4 +34,23 @@ class ProjectAutoDevops < ActiveRecord::Base
end
end
end
+
+ private
+
+ def create_gitlab_deploy_token
+ project.deploy_tokens.create!(
+ name: DeployToken::GITLAB_DEPLOY_TOKEN_NAME,
+ read_registry: true
+ )
+ end
+
+ def needs_to_create_deploy_token?
+ auto_devops_enabled? &&
+ !project.public? &&
+ !project.deploy_tokens.find_by(name: DeployToken::GITLAB_DEPLOY_TOKEN_NAME).present?
+ end
+
+ def auto_devops_enabled?
+ Gitlab::CurrentSettings.auto_devops_enabled? || enabled?
+ end
end