Commit d43071ac authored by Mathieu Parent's avatar Mathieu Parent
Browse files

Add build_git_strategy attribute to project API

We map the boolean to the string 'fetch' or 'clone', to be more
explicit.
parent 7a364010b126
# frozen_string_literal: true
# Add methods used by the projects API
module ProjectAPICompatibility
extend ActiveSupport::Concern
def build_git_strategy=(value)
write_attribute(:build_allow_git_fetch, value == 'fetch')
end
end
......@@ -15,6 +15,7 @@ class Project < ApplicationRecord
include CaseSensitivity
include TokenAuthenticatable
include ValidAttribute
include ProjectAPICompatibility
include ProjectFeaturesCompatibility
include SelectForProjectAuthorization
include Presentable
......
......@@ -733,6 +733,7 @@ POST /projects
| `tag_list` | array | no | The list of tags for a project; put array of tags, that should be finally assigned to a project |
| `avatar` | mixed | no | Image file for avatar of the project |
| `printing_merge_request_link_enabled` | boolean | no | Show link to create/view merge request when pushing from the command line |
| `build_git_strategy` | string | no | The Git strategy. Defaults to `fetch` |
| `ci_config_path` | string | no | The path to CI config file |
| `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 |
......@@ -784,6 +785,7 @@ POST /projects/user/:user_id
| `tag_list` | array | no | The list of tags for a project; put array of tags, that should be finally assigned to a project |
| `avatar` | mixed | no | Image file for avatar of the project |
| `printing_merge_request_link_enabled` | boolean | no | Show link to create/view merge request when pushing from the command line |
| `build_git_strategy` | string | no | The Git strategy. Defaults to `fetch` |
| `ci_config_path` | string | no | The path to CI config file |
| `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 |
......@@ -834,6 +836,7 @@ PUT /projects/:id
| `request_access_enabled` | boolean | no | Allow users to request member access |
| `tag_list` | array | no | The list of tags for a project; put array of tags, that should be finally assigned to a project |
| `avatar` | mixed | no | Image file for avatar of the project |
| `build_git_strategy` | string | no | The Git strategy. Defaults to `fetch` |
| `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) |
| `repository_storage` | string | no | Which storage shard the repository is on. Available only to admins |
......
......@@ -275,6 +275,9 @@ class Project < BasicProjectDetails
expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
expose :ci_default_git_depth
expose :public_builds, as: :public_jobs
expose :build_git_strategy, if: lambda { |project, options| options[:user_can_admin_project] } do |project, options|
project.build_allow_git_fetch ? 'fetch' : 'clone'
end
expose :ci_config_path, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) }
expose :shared_with_groups do |project, options|
SharedGroup.represent(project.project_group_links, options)
......
......@@ -8,6 +8,7 @@ module ProjectsHelpers
params :optional_project_params_ce do
optional :description, type: String, desc: 'The description of the project'
optional :build_git_strategy, type: String, values: %w(fetch clone), desc: 'The Git strategy. Defaults to `fetch`'
optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`'
# TODO: remove in API v5, replaced by *_access_level
......@@ -58,6 +59,7 @@ module ProjectsHelpers
def self.update_params_at_least_one_of
[
:build_git_strategy,
:builds_access_level,
:ci_config_path,
:container_registry_enabled,
......
# frozen_string_literal: true
require 'spec_helper'
describe ProjectAPICompatibility do
let(:project) { create(:project) }
it "converts build_git_strategy=fetch to build_allow_git_fetch=true" do
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')
expect(project.build_allow_git_fetch).to eq(false)
end
end
......@@ -1929,6 +1929,24 @@
expect(json_response['builds_access_level']).to eq('private')
end
it 'updates build_git_strategy' do
project_param = { build_git_strategy: 'clone' }
put api("/projects/#{project3.id}", user), params: project_param
expect(response).to have_gitlab_http_status(200)
expect(json_response['build_git_strategy']).to eq('clone')
end
it 'rejects to update build_git_strategy when build_git_strategy is invalid' do
project_param = { build_git_strategy: 'invalid' }
put api("/projects/#{project3.id}", user), params: project_param
expect(response).to have_gitlab_http_status(400)
end
it 'updates merge_method' do
project_param = { merge_method: 'ff' }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment