diff --git a/doc/api/projects.md b/doc/api/projects.md index 385c3eaf468a858fa88cd11fafc29a59f5c277b6..7ae9c599ce24e322cdb4d1ceea6002ebf1e98e52 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -3226,6 +3226,36 @@ with the API scope enabled. | `only_mirror_protected_branches`| boolean | No | Limits mirroring to only protected branches when set to `true`. | | `mirror_branch_regex` | String | No | Contains a regular expression. Only branches with names matching the regex are mirrored. Requires `only_mirror_protected_branches` to be disabled. | +Example creating a project with pull mirroring: + +```shell +curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \ + --header "Content-Type: application/json" \ + --data '{ + "name": "new_project", + "namespace_id": "1", + "mirror": true, + "import_url": "https://username:token@gitlab.example.com/group/project.git" + }' \ + --url "https://gitlab.example.com/api/v4/projects/" +``` + +Example adding pull mirroring: + +```shell +curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" \ + --url "https://gitlab.example.com/api/v4/projects/:id" \ + --data "mirror=true&import_url=https://username:token@gitlab.example.com/group/project.git" +``` + +Example removing pull mirroring: + +```shell +curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" \ + --url "https://gitlab.example.com/api/v4/projects/:id" \ + --data "mirror=false" +``` + ## Start the pull mirroring process for a Project **(PREMIUM ALL)** > Moved to GitLab Premium in 13.9. diff --git a/ee/lib/ee/api/helpers/projects_helpers.rb b/ee/lib/ee/api/helpers/projects_helpers.rb index eb4e53550ed127b2cf852b9c0f5f67e28d209269..99ad272eda1ae24cad89b16511aff255bf6fff71 100644 --- a/ee/lib/ee/api/helpers/projects_helpers.rb +++ b/ee/lib/ee/api/helpers/projects_helpers.rb @@ -62,6 +62,7 @@ def update_params_at_least_one_of :fallback_approvals_required, :import_url, :issues_template, + :mirror, :merge_requests_template, :merge_pipelines_enabled, :merge_trains_enabled, diff --git a/ee/spec/requests/api/projects_spec.rb b/ee/spec/requests/api/projects_spec.rb index c7a9a2ac0c1d53371904fa8445d93c99a43aed91..b785c50c1594a42904c61331b27fe27d78c42a9c 100644 --- a/ee/spec/requests/api/projects_spec.rb +++ b/ee/spec/requests/api/projects_spec.rb @@ -1310,6 +1310,18 @@ ) end + context 'when only disabling pull mirror' do + let(:project) { create(:project, mirror: true, import_url: import_url, mirror_user: user, namespace: user.namespace) } + let(:project_params) do + { mirror: false } + end + + it 'updates mirror to false' do + expect { subject }.to change { project.reload.mirror }.from(true).to(false) + expect(response).to have_gitlab_http_status(:ok) + end + end + it 'updates project without mirror attributes when the project is unable to set up repository mirroring' do stub_licensed_features(repository_mirrors: false)