diff --git a/app/models/concerns/project_api_compatibility.rb b/app/models/concerns/project_api_compatibility.rb index 9a0202c211c691a5c6b45772c87ace228954467a..cb00efb06df3490cee98cbf952ce2204f5453c64 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 02b3faf2d0ce6476f332b8a5c32d2906460630eb..c3e9fc69dd229415d20ab004c6420b39084a1a2f 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 c6c7023042f9b47e6ae6230bb46cf0051c13ffd1..7bf66589616072d50c7bb4955ff22ca679114481 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 390c694e21bee4f2bc868ab2d9e2a852e095991a..0e21a7a66fd31e7b09d68253cedd1b6caf83f66b 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 a999f60a1f3803f81b85105b7875f73a7e12b359..8cecd4fe7bc09c31cdcac077dff46980dca1c0fc 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 2fc257a1a060277c870ce028c085fb32323f4796..df4758f362bb53c4ae9993e11cf2791fb2e36e6a 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