diff options
-rw-r--r-- | .gitlab/issue_templates/Broken Master - Flaky.md | 3 | ||||
-rw-r--r-- | app/assets/javascripts/ide/init_gitlab_web_ide.js | 23 | ||||
-rw-r--r-- | app/helpers/ide_helper.rb | 8 | ||||
-rw-r--r-- | app/services/issues/close_service.rb | 2 | ||||
-rw-r--r-- | app/views/groups/_import_group_from_another_instance_panel.html.haml | 38 | ||||
-rw-r--r-- | app/views/profiles/preferences/show.html.haml | 6 | ||||
-rw-r--r-- | doc/development/testing_guide/flaky_tests.md | 2 | ||||
-rw-r--r-- | doc/user/profile/preferences.md | 6 | ||||
-rw-r--r-- | doc/user/project/releases/index.md | 4 | ||||
-rw-r--r-- | locale/gitlab.pot | 35 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | qa/qa/specs/features/api/1_manage/user_inherited_access_spec.rb | 8 | ||||
-rw-r--r-- | qa/qa/specs/features/shared_contexts/import/gitlab_group_migration_common.rb | 2 | ||||
-rw-r--r-- | spec/features/groups/import_export/connect_instance_spec.rb | 106 | ||||
-rw-r--r-- | spec/frontend/ide/init_gitlab_web_ide_spec.js | 147 | ||||
-rw-r--r-- | spec/helpers/ide_helper_spec.rb | 7 | ||||
-rw-r--r-- | spec/services/issues/close_service_spec.rb | 14 | ||||
-rw-r--r-- | yarn.lock | 8 |
18 files changed, 273 insertions, 148 deletions
diff --git a/.gitlab/issue_templates/Broken Master - Flaky.md b/.gitlab/issue_templates/Broken Master - Flaky.md index d90abe2cc33..bea12615e41 100644 --- a/.gitlab/issue_templates/Broken Master - Flaky.md +++ b/.gitlab/issue_templates/Broken Master - Flaky.md @@ -16,6 +16,9 @@ Please read the below documentations for a workflow of triaging and resolving br <!-- If the pipeline failure is reproducible, provide steps to recreate the issue locally. Please use an ordered list. --> +Please refer to [Flaky tests documentation](https://docs.gitlab.com/ee/development/testing_guide/flaky_tests.html) to +learn more about how to reproduce them. + ### Proposed Resolution <!-- Describe the proposed change to restore master stability. --> diff --git a/app/assets/javascripts/ide/init_gitlab_web_ide.js b/app/assets/javascripts/ide/init_gitlab_web_ide.js index 5e25aa6de21..d3c64754e8a 100644 --- a/app/assets/javascripts/ide/init_gitlab_web_ide.js +++ b/app/assets/javascripts/ide/init_gitlab_web_ide.js @@ -22,11 +22,26 @@ const buildRemoteIdeURL = (ideRemotePath, remoteHost, remotePathArg) => { }); }; +const getMRTargetProject = () => { + const url = new URL(window.location.href); + + return url.searchParams.get('target_project') || ''; +}; + export const initGitlabWebIDE = async (el) => { // what: Pull what we need from the element. We will replace it soon. - const { cspNonce: nonce, branchName: ref, projectPath, ideRemotePath } = el.dataset; + const { + cspNonce: nonce, + branchName: ref, + projectPath, + ideRemotePath, + filePath, + mergeRequest: mrId, + forkInfo: forkInfoJSON, + } = el.dataset; const rootEl = setupRootElement(el); + const forkInfo = forkInfoJSON ? JSON.parse(forkInfoJSON) : null; // See ClientOnlyConfig https://gitlab.com/gitlab-org/gitlab-web-ide/-/blob/main/packages/web-ide-types/src/config.ts#L17 start(rootEl, { @@ -39,6 +54,12 @@ export const initGitlabWebIDE = async (el) => { }, projectPath, ref, + filePath, + mrId, + mrTargetProject: getMRTargetProject(), + // note: At the time of writing this, forkInfo isn't expected by `@gitlab/web-ide`, + // but it will be soon. + forkInfo, links: { feedbackIssue: GITLAB_WEB_IDE_FEEDBACK_ISSUE, userPreferences: el.dataset.userPreferencesPath, diff --git a/app/helpers/ide_helper.rb b/app/helpers/ide_helper.rb index aa2c8ad3719..0e81cea8ac7 100644 --- a/app/helpers/ide_helper.rb +++ b/app/helpers/ide_helper.rb @@ -7,7 +7,10 @@ module IdeHelper 'use-new-web-ide' => use_new_web_ide?.to_s, 'new-web-ide-help-page-path' => help_page_path('user/project/web_ide/index.md', anchor: 'vscode-reimplementation'), 'user-preferences-path' => profile_preferences_path, - 'branch-name' => @branch + 'branch-name' => @branch, + 'file-path' => @path, + 'fork-info' => @fork_info&.to_json, + 'merge-request' => @merge_request }.merge(use_new_web_ide? ? new_ide_data : legacy_ide_data) end @@ -44,9 +47,6 @@ module IdeHelper 'render-whitespace-in-code': current_user.render_whitespace_in_code.to_s, 'codesandbox-bundler-url': Gitlab::CurrentSettings.web_ide_clientside_preview_bundler_url, 'default-branch' => @project && @project.default_branch, - 'file-path' => @path, - 'merge-request' => @merge_request, - 'fork-info' => @fork_info&.to_json, 'project' => convert_to_project_entity_json(@project), 'enable-environments-guidance' => enable_environments_guidance?.to_s, 'preview-markdown-path' => @project && preview_markdown_path(@project), diff --git a/app/services/issues/close_service.rb b/app/services/issues/close_service.rb index 9f7da012c5c..4f6a859e20e 100644 --- a/app/services/issues/close_service.rb +++ b/app/services/issues/close_service.rb @@ -81,7 +81,7 @@ module Issues issue = alert.issue if alert.resolve - SystemNoteService.change_alert_status(alert, current_user, " by closing incident #{issue.to_reference(project)}") + SystemNoteService.change_alert_status(alert, User.alert_bot, " because #{current_user.to_reference} closed incident #{issue.to_reference(project)}") else Gitlab::AppLogger.warn( message: 'Cannot resolve an associated Alert Management alert', diff --git a/app/views/groups/_import_group_from_another_instance_panel.html.haml b/app/views/groups/_import_group_from_another_instance_panel.html.haml index 19c11d110b7..4a4bdfc6714 100644 --- a/app/views/groups/_import_group_from_another_instance_panel.html.haml +++ b/app/views/groups/_import_group_from_another_instance_panel.html.haml @@ -1,20 +1,39 @@ +- bulk_imports_disabled = !Gitlab::CurrentSettings.bulk_import_enabled? + = gitlab_ui_form_with url: configure_import_bulk_imports_path(namespace_id: params[:parent_id]), class: 'gl-show-field-errors' do |f| .gl-border-l-solid.gl-border-r-solid.gl-border-t-solid.gl-border-gray-100.gl-border-1.gl-p-5.gl-mt-4 .gl-display-flex.gl-align-items-center %h4.gl-display-flex = s_('GroupsNew|Import groups from another instance of GitLab') = link_to _('History'), history_import_bulk_imports_path, class: 'gl-link gl-ml-auto' - = render Pajamas::AlertComponent.new(dismissible: false, - variant: :warning) do |c| - = c.body do - - docs_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('user/group/import/index.md') } - - docs_link_end = '</a>'.html_safe - = s_('GroupsNew|Not all related objects are migrated. %{docs_link_start}More info%{docs_link_end}.').html_safe % { docs_link_start: docs_link_start, docs_link_end: docs_link_end } + + - if bulk_imports_disabled + = render Pajamas::AlertComponent.new(dismissible: false, variant: :tip) do |c| + = c.body do + = s_('GroupsNew|Importing groups by direct transfer is currently disabled.') + + - if current_user.admin? + - admin_link_start = '<a href="%{url}">'.html_safe % { url: general_admin_application_settings_path(anchor: 'js-visibility-settings') } + - admin_link_end = '</a>'.html_safe + + = s_('GroupsNew|Please %{admin_link_start}enable it in the Admin settings%{admin_link_end}.').html_safe % { admin_link_start: admin_link_start, admin_link_end: admin_link_end } + - else + = s_('GroupsNew|Please ask your Administrator to enable it in the Admin settings.') + + = s_('GroupsNew|Remember to enable it also on the instance you are migrating from.') + - else + = render Pajamas::AlertComponent.new(dismissible: false, + variant: :warning) do |c| + = c.body do + - docs_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('user/group/import/index.md') } + - docs_link_end = '</a>'.html_safe + = s_('GroupsNew|Not all related objects are migrated. %{docs_link_start}More info%{docs_link_end}.').html_safe % { docs_link_start: docs_link_start, docs_link_end: docs_link_end } + %p.gl-mt-3 - = s_('GroupsNew|Provide credentials for another instance of GitLab to import your groups directly.') + = s_('GroupsNew|Provide credentials for another instance of GitLab to import your groups directly.') .form-group.gl-display-flex.gl-flex-direction-column = f.label :bulk_import_gitlab_url, s_('GroupsNew|GitLab source URL'), for: 'import_gitlab_url' - = f.text_field :bulk_import_gitlab_url, placeholder: 'https://gitlab.example.com', class: 'gl-form-input col-xs-12 col-sm-8', + = f.text_field :bulk_import_gitlab_url, disabled: bulk_imports_disabled, placeholder: 'https://gitlab.example.com', class: 'gl-form-input col-xs-12 col-sm-8', required: true, title: s_('GroupsNew|Please fill in GitLab source URL.'), id: 'import_gitlab_url', @@ -27,9 +46,10 @@ = s_('GroupsNew|Create a token with %{code_start}api%{code_end} and %{code_start}read_repository%{code_end} scopes in the %{pat_link_start}user settings%{pat_link_end} of the source GitLab instance. For %{short_living_link_start}security reasons%{short_living_link_end}, set a short expiration date for the token. Keep in mind that large migrations take more time.').html_safe % { code_start: '<code>'.html_safe, code_end: '</code>'.html_safe, pat_link_start: pat_link_start, pat_link_end: '</a>'.html_safe, short_living_link_start: short_living_link_start, short_living_link_end: '</a>'.html_safe } = f.text_field :bulk_import_gitlab_access_token, placeholder: s_('GroupsNew|e.g. h8d3f016698e...'), class: 'gl-form-input gl-mt-3 col-xs-12 col-sm-8', required: true, + disabled: bulk_imports_disabled, autocomplete: 'off', title: s_('GroupsNew|Please fill in your personal access token.'), id: 'import_gitlab_token', data: { qa_selector: 'import_gitlab_token' } .gl-border-gray-100.gl-border-solid.gl-border-1.gl-bg-gray-10.gl-p-5 - = f.submit s_('GroupsNew|Connect instance'), pajamas_button: true, data: { qa_selector: 'connect_instance_button' } + = f.submit s_('GroupsNew|Connect instance'), disabled: bulk_imports_disabled, pajamas_button: true, data: { qa_selector: 'connect_instance_button' } diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml index 8ef2819fb9b..b2e5650ac3c 100644 --- a/app/views/profiles/preferences/show.html.haml +++ b/app/views/profiles/preferences/show.html.haml @@ -153,13 +153,13 @@ %h4.gl-mt-0 = s_('Preferences|Web IDE') %p - = s_('Preferences|Choose which Web IDE version you want to use.') + = s_('Preferences|The Web IDE Beta is the default Web IDE experience.') = link_to _('Learn more'), help_page_path('user/profile/preferences', anchor: 'web-ide'), target: '_blank', rel: 'noopener noreferrer' .col-lg-8 .form-group = f.gitlab_ui_checkbox_component :use_legacy_web_ide, - s_('Preferences|Use legacy Web IDE'), - help_text: s_('Preferences|The legacy Web IDE remains available while the new Web IDE is in Beta.') + s_('Preferences|Opt out of the Web IDE Beta'), + help_text: s_('Preferences|The Web IDE remains available alongside the Beta.') .col-sm-12 %hr .row.js-preferences-form.js-search-settings-section diff --git a/doc/development/testing_guide/flaky_tests.md b/doc/development/testing_guide/flaky_tests.md index f18278825b4..ef5b75d166f 100644 --- a/doc/development/testing_guide/flaky_tests.md +++ b/doc/development/testing_guide/flaky_tests.md @@ -56,6 +56,7 @@ the problem. - [Example 1](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/10148/diffs): Without specifying `ORDER BY`, database will not give deterministic ordering, or data race happening in the tests. +- [Example 2](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/106936/diffs). ### Dataset-specific @@ -104,6 +105,7 @@ or the app. **Description:** The DOM selector used in the test is unreliable. **Difficulty to reproduce:** Moderate to difficult. Depending on whether the DOM selector is duplicated, or appears after a delay etc. +Adding a delay in API or controller could help reproducing the issue. **Resolution:** It really depends on the problem here. It could be to wait for requests to finish, to scroll down the page etc. diff --git a/doc/user/profile/preferences.md b/doc/user/profile/preferences.md index 7b79ffad630..018a441af6b 100644 --- a/doc/user/profile/preferences.md +++ b/doc/user/profile/preferences.md @@ -210,14 +210,14 @@ Open an issue if you notice that using absolute times breaks a layout. FLAG: On self-managed GitLab, by default this feature is not available. To make it available, ask an administrator to [enable the feature flag](../../administration/feature_flags.md) named `vscode_web_ide`. On GitLab.com, this feature is not available. The feature is not ready for production use. -The [VS Code-based Web IDE](../project/web_ide/index.md#vs-code-reimplementation) is +The [Web IDE Beta](../project/web_ide/index.md#vs-code-reimplementation) is the default editing environment when the `vscode_web_ide` feature flag is enabled. -To use the legacy Web IDE: +To stop using the Web IDE Beta: 1. On the **Preferences** page, go to **Web IDE**. -1. Select the **Use legacy Web IDE** checkbox. +1. Select the **Opt out of the Web IDE Beta** checkbox. 1. Select **Save changes**. ## Integrations diff --git a/doc/user/project/releases/index.md b/doc/user/project/releases/index.md index 34cb8e9e092..6d5378bddb7 100644 --- a/doc/user/project/releases/index.md +++ b/doc/user/project/releases/index.md @@ -453,11 +453,11 @@ In the API: ## Release permissions -> [The permission model for create, update and delete actions was fixed](https://gitlab.com/gitlab-org/gitlab/-/issues/327505) in GitLab 14.1. +> Fixes to the permission model for create, update and delete actions [were introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/327505) in GitLab 14.1. ### View a release and download assets -> [Changes were made to the Guest role access](https://gitlab.com/gitlab-org/gitlab/-/issues/335209) in GitLab 14.5. +> Changes to the Guest role [were introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/335209) in GitLab 14.5. - Users with at least the Reporter role have read and download access to the project releases. diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 5c91b399eec..c95a0958334 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -13318,11 +13318,10 @@ msgstr "" msgid "DeletionSettings|Keep deleted" msgstr "" -msgid "DeletionSettings|Keep deleted projects for %{number} days" -msgstr "" - -msgid "DeletionSettings|Keep deleted projects for 1 day" -msgstr "" +msgid "DeletionSettings|Keep deleted projects for %{number} day" +msgid_plural "DeletionSettings|Keep deleted projects for %{number} days" +msgstr[0] "" +msgstr[1] "" msgid "DeletionSettings|None, delete immediately" msgstr "" @@ -19964,6 +19963,9 @@ msgstr "" msgid "GroupsNew|Import groups from another instance of GitLab" msgstr "" +msgid "GroupsNew|Importing groups by direct transfer is currently disabled." +msgstr "" + msgid "GroupsNew|No import options available" msgstr "" @@ -19973,6 +19975,12 @@ msgstr "" msgid "GroupsNew|Personal access token" msgstr "" +msgid "GroupsNew|Please %{admin_link_start}enable it in the Admin settings%{admin_link_end}." +msgstr "" + +msgid "GroupsNew|Please ask your Administrator to enable it in the Admin settings." +msgstr "" + msgid "GroupsNew|Please fill in GitLab source URL." msgstr "" @@ -19982,6 +19990,9 @@ msgstr "" msgid "GroupsNew|Provide credentials for another instance of GitLab to import your groups directly." msgstr "" +msgid "GroupsNew|Remember to enable it also on the instance you are migrating from." +msgstr "" + msgid "GroupsNew|This feature is deprecated and replaced by %{docs_link_start}group migration%{docs_link_end}." msgstr "" @@ -31342,9 +31353,6 @@ msgstr "" msgid "Preferences|Choose what content you want to see on a project’s overview page." msgstr "" -msgid "Preferences|Choose which Web IDE version you want to use." -msgstr "" - msgid "Preferences|Color for added lines" msgstr "" @@ -31402,6 +31410,9 @@ msgstr "" msgid "Preferences|Must be a number between %{min} and %{max}" msgstr "" +msgid "Preferences|Opt out of the Web IDE Beta" +msgstr "" + msgid "Preferences|Preview" msgstr "" @@ -31429,7 +31440,10 @@ msgstr "" msgid "Preferences|Tab width" msgstr "" -msgid "Preferences|The legacy Web IDE remains available while the new Web IDE is in Beta." +msgid "Preferences|The Web IDE Beta is the default Web IDE experience." +msgstr "" + +msgid "Preferences|The Web IDE remains available alongside the Beta." msgstr "" msgid "Preferences|This feature is experimental and translations are not yet complete." @@ -31444,9 +31458,6 @@ msgstr "" msgid "Preferences|Time preferences" msgstr "" -msgid "Preferences|Use legacy Web IDE" -msgstr "" - msgid "Preferences|Use relative times" msgstr "" diff --git a/package.json b/package.json index 21976a66dfa..5cae779ac08 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "@gitlab/svgs": "3.13.0", "@gitlab/ui": "52.3.0", "@gitlab/visual-review-tools": "1.7.3", - "@gitlab/web-ide": "0.0.1-dev-20221214231216", + "@gitlab/web-ide": "0.0.1-dev-20221216140656", "@rails/actioncable": "6.1.4-7", "@rails/ujs": "6.1.4-7", "@sourcegraph/code-host-integration": "0.0.84", diff --git a/qa/qa/specs/features/api/1_manage/user_inherited_access_spec.rb b/qa/qa/specs/features/api/1_manage/user_inherited_access_spec.rb index 0a55ec5e017..3df6e988bfa 100644 --- a/qa/qa/specs/features/api/1_manage/user_inherited_access_spec.rb +++ b/qa/qa/specs/features/api/1_manage/user_inherited_access_spec.rb @@ -70,13 +70,7 @@ module QA it( 'is allowed to commit to sub-group project via the API', - :reliable, - testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/363349', - quarantine: { - only: { subdomain: %i[staging staging-ref] }, - type: :investigating, - issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/370282' - } + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/363349' ) do expect do Resource::Repository::Commit.fabricate_via_api! do |commit| diff --git a/qa/qa/specs/features/shared_contexts/import/gitlab_group_migration_common.rb b/qa/qa/specs/features/shared_contexts/import/gitlab_group_migration_common.rb index 8437974feea..e1d762f41cb 100644 --- a/qa/qa/specs/features/shared_contexts/import/gitlab_group_migration_common.rb +++ b/qa/qa/specs/features/shared_contexts/import/gitlab_group_migration_common.rb @@ -87,6 +87,8 @@ module QA end before do + Runtime::ApplicationSettings.set_application_settings(bulk_import_enabled: true) + target_sandbox.add_member(user, Resource::Members::AccessLevel::OWNER) end diff --git a/spec/features/groups/import_export/connect_instance_spec.rb b/spec/features/groups/import_export/connect_instance_spec.rb index 3b461739b4c..11cc4bb9b37 100644 --- a/spec/features/groups/import_export/connect_instance_spec.rb +++ b/spec/features/groups/import_export/connect_instance_spec.rb @@ -10,74 +10,96 @@ RSpec.describe 'Import/Export - Connect to another instance', :js, feature_categ group.add_owner(user) end - before do - gitlab_sign_in(user) + context 'when importing group by direct transfer is enabled' do + before do + stub_application_setting(bulk_import_enabled: true) - visit new_group_path + open_import_group + end - click_link 'Import group' - end + context 'when the user provides valid credentials' do + source_url = 'https://gitlab.com' - context 'when the user provides valid credentials' do - source_url = 'https://gitlab.com' + include_context 'bulk imports requests context', source_url - include_context 'bulk imports requests context', source_url + it 'successfully connects to remote instance' do + pat = 'demo-pat' - it 'successfully connects to remote instance' do - pat = 'demo-pat' + expect(page).to have_content 'Import groups from another instance of GitLab' + expect(page).to have_content 'Not all related objects are migrated' - expect(page).to have_content 'Import groups from another instance of GitLab' - expect(page).to have_content 'Not all related objects are migrated' + fill_in :bulk_import_gitlab_url, with: source_url + fill_in :bulk_import_gitlab_access_token, with: pat - fill_in :bulk_import_gitlab_url, with: source_url - fill_in :bulk_import_gitlab_access_token, with: pat + click_on 'Connect instance' - click_on 'Connect instance' + expect(page).to have_content 'Showing 1-1 of 42 groups that you own from %{url}' % { url: source_url } + expect(page).to have_content 'stub-group' - expect(page).to have_content 'Showing 1-1 of 42 groups that you own from %{url}' % { url: source_url } - expect(page).to have_content 'stub-group' + visit '/' - visit '/' + wait_for_all_requests + end + end + + context 'when the user provides invalid url' do + it 'reports an error' do + source_url = 'invalid-url' + pat = 'demo-pat' + + fill_in :bulk_import_gitlab_url, with: source_url + fill_in :bulk_import_gitlab_access_token, with: pat - wait_for_all_requests + click_on 'Connect instance' + + expect(page).to have_content 'Specified URL cannot be used' + end end - end - context 'when the user provides invalid url' do - it 'reports an error' do - source_url = 'invalid-url' - pat = 'demo-pat' + context 'when the user does not fill in source URL' do + it 'reports an error' do + pat = 'demo-pat' - fill_in :bulk_import_gitlab_url, with: source_url - fill_in :bulk_import_gitlab_access_token, with: pat + fill_in :bulk_import_gitlab_access_token, with: pat - click_on 'Connect instance' + click_on 'Connect instance' - expect(page).to have_content 'Specified URL cannot be used' + expect(page).to have_content 'Please fill in GitLab source URL' + end end - end - context 'when the user does not fill in source URL' do - it 'reports an error' do - pat = 'demo-pat' + context 'when the user does not fill in access token' do + it 'reports an error' do + source_url = 'https://gitlab.com' - fill_in :bulk_import_gitlab_access_token, with: pat + fill_in :bulk_import_gitlab_url, with: source_url - click_on 'Connect instance' + click_on 'Connect instance' - expect(page).to have_content 'Please fill in GitLab source URL' + expect(page).to have_content 'Please fill in your personal access token' + end end end - context 'when the user does not fill in access token' do - it 'reports an error' do - source_url = 'https://gitlab.com' - - fill_in :bulk_import_gitlab_url, with: source_url + context 'when importing group by direct transfer is disabled' do + before do + stub_application_setting(bulk_import_enabled: false) - click_on 'Connect instance' + open_import_group + end - expect(page).to have_content 'Please fill in your personal access token' + it 'renders fields and button disabled' do + expect(page).to have_field('GitLab source URL', disabled: true) + expect(page).to have_field('Personal access token', disabled: true) + expect(page).to have_button('Connect instance', disabled: true) end end + + def open_import_group + gitlab_sign_in(user) + + visit new_group_path + + click_link 'Import group' + end end diff --git a/spec/frontend/ide/init_gitlab_web_ide_spec.js b/spec/frontend/ide/init_gitlab_web_ide_spec.js index 36c7c54d080..97254ab680b 100644 --- a/spec/frontend/ide/init_gitlab_web_ide_spec.js +++ b/spec/frontend/ide/init_gitlab_web_ide_spec.js @@ -4,6 +4,7 @@ import { initGitlabWebIDE } from '~/ide/init_gitlab_web_ide'; import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_action'; import { createAndSubmitForm } from '~/lib/utils/create_and_submit_form'; import { TEST_HOST } from 'helpers/test_constants'; +import setWindowLocation from 'helpers/set_window_location_helper'; import waitForPromises from 'helpers/wait_for_promises'; jest.mock('@gitlab/web-ide'); @@ -21,6 +22,10 @@ const TEST_BRANCH_NAME = '12345-foo-patch'; const TEST_GITLAB_URL = 'https://test-gitlab/'; const TEST_USER_PREFERENCES_PATH = '/user/preferences'; const TEST_GITLAB_WEB_IDE_PUBLIC_PATH = 'test/webpack/assets/gitlab-web-ide/public/path'; +const TEST_FILE_PATH = 'foo/README.md'; +const TEST_MR_ID = '7'; +const TEST_MR_TARGET_PROJECT = 'gitlab-org/the-real-gitlab'; +const TEST_FORK_INFO = { fork_path: '/forky' }; const TEST_IDE_REMOTE_PATH = '/-/ide/remote/:remote_host/:remote_path'; const TEST_START_REMOTE_PARAMS = { remoteHost: 'dev.example.gitlab.com/test', @@ -42,6 +47,8 @@ describe('ide/init_gitlab_web_ide', () => { el.dataset.branchName = TEST_BRANCH_NAME; el.dataset.ideRemotePath = TEST_IDE_REMOTE_PATH; el.dataset.userPreferencesPath = TEST_USER_PREFERENCES_PATH; + el.dataset.mergeRequest = TEST_MR_ID; + el.dataset.filePath = TEST_FILE_PATH; document.body.append(el); }; @@ -65,75 +72,119 @@ describe('ide/init_gitlab_web_ide', () => { ); createRootElement(); - - createSubject(); }); afterEach(() => { document.body.innerHTML = ''; }); - it('calls start with element', () => { - expect(start).toHaveBeenCalledTimes(1); - expect(start).toHaveBeenCalledWith(findRootElement(), { - baseUrl: `${TEST_HOST}/${TEST_GITLAB_WEB_IDE_PUBLIC_PATH}`, - projectPath: TEST_PROJECT_PATH, - ref: TEST_BRANCH_NAME, - gitlabUrl: TEST_GITLAB_URL, - nonce: TEST_NONCE, - httpHeaders: { - 'mock-csrf-header': 'mock-csrf-token', - 'X-Requested-With': 'XMLHttpRequest', - }, - links: { - userPreferences: TEST_USER_PREFERENCES_PATH, - feedbackIssue: GITLAB_WEB_IDE_FEEDBACK_ISSUE, - }, - handleStartRemote: expect.any(Function), + describe('default', () => { + beforeEach(() => { + createSubject(); }); - }); - it('clears classes and data from root element', () => { - const rootEl = findRootElement(); + it('calls start with element', () => { + expect(start).toHaveBeenCalledTimes(1); + expect(start).toHaveBeenCalledWith(findRootElement(), { + baseUrl: `${TEST_HOST}/${TEST_GITLAB_WEB_IDE_PUBLIC_PATH}`, + projectPath: TEST_PROJECT_PATH, + ref: TEST_BRANCH_NAME, + filePath: TEST_FILE_PATH, + mrId: TEST_MR_ID, + mrTargetProject: '', + forkInfo: null, + gitlabUrl: TEST_GITLAB_URL, + nonce: TEST_NONCE, + httpHeaders: { + 'mock-csrf-header': 'mock-csrf-token', + 'X-Requested-With': 'XMLHttpRequest', + }, + links: { + userPreferences: TEST_USER_PREFERENCES_PATH, + feedbackIssue: GITLAB_WEB_IDE_FEEDBACK_ISSUE, + }, + handleStartRemote: expect.any(Function), + }); + }); - // why: Snapshot to test that the element was cleaned including `test-class` - expect(rootEl.outerHTML).toBe( - '<div id="ide" class="gl--flex-center gl-relative gl-h-full"></div>', - ); - }); + it('clears classes and data from root element', () => { + const rootEl = findRootElement(); - describe('when handleStartRemote is triggered', () => { - beforeEach(() => { - triggerHandleStartRemote(TEST_START_REMOTE_PARAMS); + // why: Snapshot to test that the element was cleaned including `test-class` + expect(rootEl.outerHTML).toBe( + '<div id="ide" class="gl--flex-center gl-relative gl-h-full"></div>', + ); }); - it('promts for confirm', () => { - expect(confirmAction).toHaveBeenCalledWith(expect.any(String), { - primaryBtnText: expect.any(String), - cancelBtnText: expect.any(String), + describe('when handleStartRemote is triggered', () => { + beforeEach(() => { + triggerHandleStartRemote(TEST_START_REMOTE_PARAMS); + }); + + it('promts for confirm', () => { + expect(confirmAction).toHaveBeenCalledWith(expect.any(String), { + primaryBtnText: expect.any(String), + cancelBtnText: expect.any(String), + }); + }); + + it('does not submit, when not confirmed', async () => { + resolveConfirm(false); + + await waitForPromises(); + + expect(createAndSubmitForm).not.toHaveBeenCalled(); + }); + + it('submits, when confirmed', async () => { + resolveConfirm(true); + + await waitForPromises(); + + expect(createAndSubmitForm).toHaveBeenCalledWith({ + url: '/-/ide/remote/dev.example.gitlab.com%2Ftest/test/projects/f%20oo', + data: { + connection_token: TEST_START_REMOTE_PARAMS.connectionToken, + return_url: window.location.href, + }, + }); }); }); + }); - it('does not submit, when not confirmed', async () => { - resolveConfirm(false); + describe('when URL has target_project in query params', () => { + beforeEach(() => { + setWindowLocation( + `https://example.com/-/ide?target_project=${encodeURIComponent(TEST_MR_TARGET_PROJECT)}`, + ); - await waitForPromises(); + createSubject(); + }); - expect(createAndSubmitForm).not.toHaveBeenCalled(); + it('includes mrTargetProject', () => { + expect(start).toHaveBeenCalledWith( + findRootElement(), + expect.objectContaining({ + mrTargetProject: TEST_MR_TARGET_PROJECT, + }), + ); }); + }); - it('submits, when confirmed', async () => { - resolveConfirm(true); + describe('when forkInfo is in dataset', () => { + beforeEach(() => { + findRootElement().dataset.forkInfo = JSON.stringify(TEST_FORK_INFO); - await waitForPromises(); + createSubject(); + }); - expect(createAndSubmitForm).toHaveBeenCalledWith({ - url: '/-/ide/remote/dev.example.gitlab.com%2Ftest/test/projects/f%20oo', - data: { - connection_token: TEST_START_REMOTE_PARAMS.connectionToken, - return_url: window.location.href, - }, - }); + it('includes forkInfo', () => { + expect(start).toHaveBeenCalledWith( + findRootElement(), + expect.objectContaining({ + forkInfo: TEST_FORK_INFO, + }), + ); }); }); }); diff --git a/spec/helpers/ide_helper_spec.rb b/spec/helpers/ide_helper_spec.rb index 06ea1f40eab..29b2784412e 100644 --- a/spec/helpers/ide_helper_spec.rb +++ b/spec/helpers/ide_helper_spec.rb @@ -18,6 +18,8 @@ RSpec.describe IdeHelper, feature_category: :web_ide do self.instance_variable_set(:@branch, 'master') self.instance_variable_set(:@project, project) + self.instance_variable_set(:@path, 'foo/README.md') + self.instance_variable_set(:@merge_request, '7') end it 'returns hash' do @@ -31,7 +33,10 @@ RSpec.describe IdeHelper, feature_category: :web_ide do 'branch-name' => 'master', 'project-path' => project.path_with_namespace, 'csp-nonce' => 'test-csp-nonce', - 'ide-remote-path' => ide_remote_path(remote_host: ':remote_host', remote_path: ':remote_path') + 'ide-remote-path' => ide_remote_path(remote_host: ':remote_host', remote_path: ':remote_path'), + 'file-path' => 'foo/README.md', + 'merge-request' => '7', + 'fork-info' => nil ) end diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb index 8e5717090b4..e6ad755f911 100644 --- a/spec/services/issues/close_service_spec.rb +++ b/spec/services/issues/close_service_spec.rb @@ -357,11 +357,8 @@ RSpec.describe Issues::CloseService do it 'resolves an alert and sends a system note' do alert = create(:alert_management_alert, issue: issue, project: project) - expect_any_instance_of(SystemNoteService) do |notes_service| - expect(notes_service).to receive(:change_alert_status).with( - alert, current_user, " by closing issue #{issue.to_reference(project)}" - ) - end + expect(SystemNoteService).to receive(:change_alert_status) + .with(alert, User.alert_bot, " because #{user.to_reference} closed incident #{issue.to_reference(project)}") close_issue @@ -395,11 +392,8 @@ RSpec.describe Issues::CloseService do alerts = create_list(:alert_management_alert, 2, issue: issue, project: project) alerts.each do |alert| - expect_any_instance_of(SystemNoteService) do |notes_service| - expect(notes_service).to receive(:change_alert_status).with( - alert, current_user, " by closing issue #{issue.to_reference(project)}" - ) - end + expect(SystemNoteService).to receive(:change_alert_status) + .with(alert, User.alert_bot, " because #{user.to_reference} closed incident #{issue.to_reference(project)}") end close_issue diff --git a/yarn.lock b/yarn.lock index e963b385caf..afb3ae42a29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1155,10 +1155,10 @@ resolved "https://registry.yarnpkg.com/@gitlab/visual-review-tools/-/visual-review-tools-1.7.3.tgz#9ea641146436da388ffbad25d7f2abe0df52c235" integrity sha512-NMV++7Ew1FSBDN1xiZaauU9tfeSfgDHcOLpn+8bGpP+O5orUPm2Eu66R5eC5gkjBPaXosNAxNWtriee+aFk4+g== -"@gitlab/web-ide@0.0.1-dev-20221214231216": - version "0.0.1-dev-20221214231216" - resolved "https://registry.yarnpkg.com/@gitlab/web-ide/-/web-ide-0.0.1-dev-20221214231216.tgz#d48c7c8b49d1e4a2f711b8a7b159ded92bac31df" - integrity sha512-PtaBlsc60hIrWXWBkyX0OUsg7b1PN74DrtzyG2d7qH55rG9wqfuRw71ieAObv1ApSDqZ+kcf66YkYrd9l8/u5g== +"@gitlab/web-ide@0.0.1-dev-20221216140656": + version "0.0.1-dev-20221216140656" + resolved "https://registry.yarnpkg.com/@gitlab/web-ide/-/web-ide-0.0.1-dev-20221216140656.tgz#ec8c55f6307431eb6180d0bbd5117d7aee176647" + integrity sha512-rPit2S80UZw0UH/xIrnBuhG8JLQ8hqk0dFlaKRbunVb3B5kR4xzP8E+MYasP9UFEGpd/dzwdinoFxKLgCZeWig== "@graphql-eslint/eslint-plugin@3.12.0": version "3.12.0" |