summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Parent <math.parent@gmail.com>2019-05-15 16:27:54 +0200
committerMathieu Parent <math.parent@gmail.com>2019-07-03 16:18:05 +0200
commite44167004dd44cf727829d0fc9df59fe3404bb49 (patch)
treecdc94639756dc8cfbb996bd84c26540205a75ae9
parent5028f5d73d8fa69f72ac8d2b1cc493d82cf6f3e4 (diff)
downloadgitlab-ce-e44167004dd44cf727829d0fc9df59fe3404bb49.tar.gz
Add auto_devops_* to project API
The auto_devops object sometimes doesn't exists. We may need to create it.
-rw-r--r--app/models/concerns/project_api_compatibility.rb10
-rw-r--r--doc/api/projects.md6
-rw-r--r--lib/api/entities.rb4
-rw-r--r--lib/api/helpers/projects_helpers.rb4
-rw-r--r--spec/models/concerns/project_api_compatibility_spec.rb25
-rw-r--r--spec/requests/api/projects_spec.rb20
6 files changed, 67 insertions, 2 deletions
diff --git a/app/models/concerns/project_api_compatibility.rb b/app/models/concerns/project_api_compatibility.rb
index 9a0202c211c..cb00efb06df 100644
--- a/app/models/concerns/project_api_compatibility.rb
+++ b/app/models/concerns/project_api_compatibility.rb
@@ -7,4 +7,14 @@ module ProjectAPICompatibility
def build_git_strategy=(value)
write_attribute(:build_allow_git_fetch, value == 'fetch')
end
+
+ def auto_devops_enabled=(value)
+ self.build_auto_devops if self.auto_devops&.enabled.nil?
+ self.auto_devops.update! enabled: value
+ end
+
+ def auto_devops_deploy_strategy=(value)
+ self.build_auto_devops if self.auto_devops&.enabled.nil?
+ self.auto_devops.update! deploy_strategy: value
+ end
end
diff --git a/doc/api/projects.md b/doc/api/projects.md
index 02b3faf2d0c..c3e9fc69dd2 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -738,6 +738,8 @@ POST /projects
| `auto_cancel_pending_pipelines` | string | no | Auto-cancel pending pipelines (Note: this is not a boolean, but enabled/disabled |
| `build_coverage_regex` | string | no | Test coverage parsing |
| `ci_config_path` | string | no | The path to CI config file |
+| `auto_devops_enabled` | boolean | no | Enable Auto DevOps for this project |
+| `auto_devops_deploy_strategy` | string | no | Auto Deploy strategy (`continuous`, `manual` or `timed_incremental`) |
| `repository_storage` | string | no | Which storage shard the repository is on. Available only to admins |
| `approvals_before_merge` | integer | no | **[STARTER]** How many approvers should approve merge requests by default |
| `mirror` | boolean | no | **[STARTER]** Enables pull mirroring in a project |
@@ -793,6 +795,8 @@ POST /projects/user/:user_id
| `auto_cancel_pending_pipelines` | string | no | Auto-cancel pending pipelines (Note: this is not a boolean, but enabled/disabled |
| `build_coverage_regex` | string | no | Test coverage parsing |
| `ci_config_path` | string | no | The path to CI config file |
+| `auto_devops_enabled` | boolean | no | Enable Auto DevOps for this project |
+| `auto_devops_deploy_strategy` | string | no | Auto Deploy strategy (`continuous`, `manual` or `timed_incremental`) |
| `repository_storage` | string | no | Which storage shard the repository is on. Available only to admins |
| `approvals_before_merge` | integer | no | **[STARTER]** How many approvers should approve merge requests by default |
| `external_authorization_classification_label` | string | no | **[CORE ONLY]** The classification label for the project |
@@ -848,6 +852,8 @@ PUT /projects/:id
| `build_coverage_regex` | string | no | Test coverage parsing |
| `ci_config_path` | string | no | The path to CI config file |
| `ci_default_git_depth` | integer | no | Default number of revisions for [shallow cloning](../user/project/pipelines/settings.md#git-shallow-clone) |
+| `auto_devops_enabled` | boolean | no | Enable Auto DevOps for this project |
+| `auto_devops_deploy_strategy` | string | no | Auto Deploy strategy (`continuous`, `manual` or `timed_incremental`) |
| `repository_storage` | string | no | Which storage shard the repository is on. Available only to admins |
| `approvals_before_merge` | integer | no | **[STARTER]** How many approvers should approve merge request by default |
| `external_authorization_classification_label` | string | no | **[CORE ONLY]** The classification label for the project |
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index c6c7023042f..7bf66589616 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -294,6 +294,10 @@ module API
options[:statistics] && Ability.allowed?(options[:current_user], :read_statistics, project)
}
expose :external_authorization_classification_label
+ expose :auto_devops_enabled?, as: :auto_devops_enabled
+ expose :auto_devops_deploy_strategy do |project, options|
+ project.auto_devops.nil? ? 'continuous' : project.auto_devops.deploy_strategy
+ end
# rubocop: disable CodeReuse/ActiveRecord
def self.preload_relation(projects_relation, options = {})
diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb
index 390c694e21b..0e21a7a66fd 100644
--- a/lib/api/helpers/projects_helpers.rb
+++ b/lib/api/helpers/projects_helpers.rb
@@ -44,6 +44,8 @@ module API
optional :initialize_with_readme, type: Boolean, desc: "Initialize a project with a README.md"
optional :external_authorization_classification_label, type: String, desc: 'The classification label for the project'
optional :ci_default_git_depth, type: Integer, desc: 'Default number of revisions for shallow cloning'
+ optional :auto_devops_enabled, type: Boolean, desc: 'Flag indication if Auto DevOps is enabled'
+ optional :auto_devops_deploy_strategy, type: String, values: %w(continuous manual timed_incremental), desc: 'Auto Deploy strategy'
end
params :optional_project_params_ee do
@@ -62,6 +64,8 @@ module API
def self.update_params_at_least_one_of
[
+ :auto_devops_enabled,
+ :auto_devops_deploy_strategy,
:auto_cancel_pending_pipelines,
:build_coverage_regex,
:build_git_strategy,
diff --git a/spec/models/concerns/project_api_compatibility_spec.rb b/spec/models/concerns/project_api_compatibility_spec.rb
index a999f60a1f3..8cecd4fe7bc 100644
--- a/spec/models/concerns/project_api_compatibility_spec.rb
+++ b/spec/models/concerns/project_api_compatibility_spec.rb
@@ -5,13 +5,34 @@ require 'spec_helper'
describe ProjectAPICompatibility do
let(:project) { create(:project) }
+ # git_strategy
it "converts build_git_strategy=fetch to build_allow_git_fetch=true" do
- project.update!(:build_git_strategy, 'fetch')
+ project.update!(build_git_strategy: 'fetch')
expect(project.build_allow_git_fetch).to eq(true)
end
it "converts build_git_strategy=clone to build_allow_git_fetch=false" do
- project.update!(:build_git_strategy, 'clone')
+ project.update!(build_git_strategy: 'clone')
expect(project.build_allow_git_fetch).to eq(false)
end
+
+ # auto_devops_enabled
+ it "converts auto_devops_enabled=false to auto_devops_enabled?=false" do
+ expect(project.auto_devops_enabled?).to eq(true)
+ project.update!(auto_devops_enabled: false)
+ expect(project.auto_devops_enabled?).to eq(false)
+ end
+
+ it "converts auto_devops_enabled=true to auto_devops_enabled?=true" do
+ expect(project.auto_devops_enabled?).to eq(true)
+ project.update!(auto_devops_enabled: true)
+ expect(project.auto_devops_enabled?).to eq(true)
+ end
+
+ # auto_devops_deploy_strategy
+ it "converts auto_devops_deploy_strategy=timed_incremental to auto_devops.deploy_strategy=timed_incremental" do
+ expect(project.auto_devops).to be_nil
+ project.update!(auto_devops_deploy_strategy: 'timed_incremental')
+ expect(project.auto_devops.deploy_strategy).to eq('timed_incremental')
+ end
end
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 2fc257a1a06..df4758f362b 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -1980,6 +1980,26 @@ describe API::Projects do
'-/system/project/avatar/'\
"#{project3.id}/banana_sample.gif")
end
+
+ it 'updates auto_devops_deploy_strategy' do
+ project_param = { auto_devops_deploy_strategy: 'timed_incremental' }
+
+ put api("/projects/#{project3.id}", user), params: project_param
+
+ expect(response).to have_gitlab_http_status(200)
+
+ expect(json_response['auto_devops_deploy_strategy']).to eq('timed_incremental')
+ end
+
+ it 'updates auto_devops_enabled' do
+ project_param = { auto_devops_enabled: false }
+
+ put api("/projects/#{project3.id}", user), params: project_param
+
+ expect(response).to have_gitlab_http_status(200)
+
+ expect(json_response['auto_devops_enabled']).to eq(false)
+ end
end
context 'when authenticated as project maintainer' do