Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2024-04-03 06:09:05 +00:00
parent 3910238c45
commit 694fdbb132
12 changed files with 203 additions and 16 deletions

View File

@ -82,7 +82,7 @@ export const initGitlabWebIDE = async (el) => {
signIn: el.dataset.signInPath,
},
featureFlags: {
settingsSync: gon.features.webIdeSettingsSync || false,
settingsSync: true,
},
editorFont,
codeSuggestionsEnabled,

View File

@ -12,7 +12,6 @@ class IdeController < ApplicationController
before_action do
push_frontend_feature_flag(:build_service_proxy)
push_frontend_feature_flag(:reject_unsigned_commits_by_gitlab)
push_frontend_feature_flag(:web_ide_settings_sync, current_user)
end
feature_category :web_ide

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
module RemoteMirrors
class SyncService < BaseService
def execute(remote_mirror)
return ServiceResponse.error(message: _('Access Denied')) unless allowed?
return ServiceResponse.error(message: _('Mirror does not exist')) unless remote_mirror
if remote_mirror.disabled?
return ServiceResponse.error(
message: _('Cannot proceed with the push mirroring. Please verify your mirror configuration.')
)
end
remote_mirror.sync unless remote_mirror.update_in_progress?
ServiceResponse.success
end
private
def allowed?
Ability.allowed?(current_user, :admin_remote_mirror, project)
end
end
end

View File

@ -1,9 +0,0 @@
---
name: web_ide_settings_sync
feature_issue_url: https://gitlab.com/gitlab-org/gitlab-web-ide/-/issues/282
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/146061
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/443652
milestone: '16.10'
group: group::ide
type: gitlab_com_derisk
default_enabled: false

View File

@ -185,6 +185,35 @@ Example response:
}
```
## Force push mirror update
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/388907) in GitLab 16.11.
[Force an update](../user/project/repository/mirror/index.md#force-an-update) to a push mirror.
```plaintext
POST /projects/:id/remote_mirrors/:mirror_id/sync
```
Supported attributes:
| Attribute | Type | Required | Description |
|-------------|-------------------|----------|--------------------------------------------------------------------------------------|
| `id` | integer or string | Yes | The ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding). |
| `mirror_id` | Integer | Yes | The remote mirror ID. |
If successful, returns [`204`](rest/index.md#status-codes).
Example request:
```shell
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486/sync"
```
Example response:
An empty response with a HTTP response code 204.
## Delete a remote mirror
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82778) in GitLab 14.10.

View File

@ -49,6 +49,30 @@ module API
present mirror, with: Entities::RemoteMirror
end
desc 'Triggers a push mirror operation' do
success code: 204
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags %w[remote_mirrors]
end
params do
requires :mirror_id, type: String, desc: 'The ID of a remote mirror'
end
post ':id/remote_mirrors/:mirror_id/sync' do
mirror = user_project.remote_mirrors.find(params[:mirror_id])
result = ::RemoteMirrors::SyncService.new(user_project, current_user).execute(mirror)
if result.success?
status :no_content
else
render_api_error!(result[:message], 400)
end
end
desc 'Create remote mirror for a project' do
success code: 201, model: Entities::RemoteMirror
failure [

View File

@ -10005,6 +10005,9 @@ msgstr ""
msgid "Cannot modify provider during creation"
msgstr ""
msgid "Cannot proceed with the push mirroring. Please verify your mirror configuration."
msgstr ""
msgid "Cannot promote issue because it does not belong to a group."
msgstr ""
@ -32221,6 +32224,9 @@ msgstr ""
msgid "Mirror direction"
msgstr ""
msgid "Mirror does not exist"
msgstr ""
msgid "Mirror only protected branches"
msgstr ""

View File

@ -2,7 +2,7 @@
source 'https://rubygems.org'
gem 'gitlab-qa', '~> 14', '>= 14.5.0', require: 'gitlab/qa'
gem 'gitlab-qa', '~> 14', '>= 14.6.0', require: 'gitlab/qa'
gem 'gitlab_quality-test_tooling', '~> 1.21.0', require: false
gem 'gitlab-utils', path: '../gems/gitlab-utils'
gem 'activesupport', '~> 7.0.8.1' # This should stay in sync with the root's Gemfile

View File

@ -119,7 +119,7 @@ GEM
gitlab (4.19.0)
httparty (~> 0.20)
terminal-table (>= 1.5.1)
gitlab-qa (14.5.0)
gitlab-qa (14.6.0)
activesupport (>= 6.1, < 7.2)
gitlab (~> 4.19)
http (~> 5.0)
@ -360,7 +360,7 @@ DEPENDENCIES
faraday-retry (~> 2.2)
fog-core (= 2.1.0)
fog-google (~> 1.19)
gitlab-qa (~> 14, >= 14.5.0)
gitlab-qa (~> 14, >= 14.6.0)
gitlab-utils!
gitlab_quality-test_tooling (~> 1.21.0)
influxdb-client (~> 3.1)

View File

@ -87,7 +87,6 @@ describe('ide/init_gitlab_web_ide', () => {
beforeEach(() => {
gon.current_username = TEST_USERNAME;
gon.features = { webIdeSettingsSync: true };
process.env.GITLAB_WEB_IDE_PUBLIC_PATH = TEST_GITLAB_WEB_IDE_PUBLIC_PATH;
confirmAction.mockImplementation(
@ -136,7 +135,7 @@ describe('ide/init_gitlab_web_ide', () => {
signIn: TEST_SIGN_IN_PATH,
},
featureFlags: {
settingsSync: gon.features.webIdeSettingsSync,
settingsSync: true,
},
editorFont: {
fallbackFontFamily: 'monospace',

View File

@ -46,6 +46,55 @@ RSpec.describe API::RemoteMirrors, feature_category: :source_code_management do
end
end
describe 'POST /projects/:id/remote_mirrors/:mirror_id/sync' do
let(:route) { "/projects/#{project.id}/remote_mirrors/#{mirror_id}/sync" }
let(:mirror) { project.remote_mirrors.first }
let(:mirror_id) { mirror.id }
context 'without enough permissions' do
it 'requires `admin_remote_mirror` permission' do
post api(route, developer)
expect(response).to have_gitlab_http_status(:unauthorized)
end
end
context 'with sufficient permissions' do
before do
project.add_maintainer(user)
end
it 'returns a successful response' do
post api(route, user)
expect(response).to have_gitlab_http_status(:no_content)
end
context 'when some error occurs' do
before do
mirror.update!(enabled: false)
end
it 'returns an error' do
post api(route, user)
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to match(/Cannot proceed with the push mirroring/)
end
end
context 'when mirror ID is missing' do
let(:mirror_id) { non_existing_record_id }
it 'returns a not found error' do
post api(route, user)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
end
describe 'POST /projects/:id/remote_mirrors' do
let(:route) { "/projects/#{project.id}/remote_mirrors" }

View File

@ -0,0 +1,64 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe RemoteMirrors::SyncService, feature_category: :source_code_management do
subject(:sync_service) { described_class.new(project, current_user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:maintainer) { create(:user, maintainer_projects: [project]) }
let_it_be_with_reload(:remote_mirror) { create(:remote_mirror, project: project, enabled: true) }
let(:current_user) { maintainer }
describe '#execute', :aggregate_failures do
subject(:execute) { sync_service.execute(remote_mirror) }
it 'triggers a mirror update worker' do
expect { execute }.to change { RepositoryUpdateRemoteMirrorWorker.jobs.count }.by(1)
is_expected.to be_success
end
context 'when user does not have permissions' do
let(:current_user) { nil }
it 'returns an error' do
is_expected.to be_error
expect(execute.message).to eq('Access Denied')
end
end
context 'when mirror is missing' do
let(:remote_mirror) { nil }
it 'returns an error' do
is_expected.to be_error
expect(execute.message).to eq('Mirror does not exist')
end
end
context 'when remote mirror is disabled' do
before do
remote_mirror.update!(enabled: false)
end
it 'returns an error' do
is_expected.to be_error
expect(execute.message).to match(/Cannot proceed with the push mirroring/)
end
end
context 'when remote mirror update has been already started' do
before do
remote_mirror.update_start!
end
it 'does not trigger a mirror update worker' do
expect { execute }.not_to change { RepositoryUpdateRemoteMirrorWorker.jobs.count }
is_expected.to be_success
end
end
end
end