[URL Import] Show error alert when re-importing to an existing project
This is a proposed enhancement that would fix what could be an oversight, observed in https://gitlab.com/gitlab-org/gitlab/-/work_items/582110. ### **Problem** When a project import by URL fails or is cancelled, a new project is created and users are redirected to the import form for existing projects, which was migrated to Vue in https://gitlab.com/gitlab-org/gitlab/-/work_items/582110.The original URL they attempted to import is displayed in the form, but it might not be clear to the user that they should not attempt to import that repo again. ### **Current Behavior** The `show` action redirects without passing any flash message or error information. Additionally, the `new.html.haml` view doesn't render any alerts for import failures. **Relevant code:** `app/controllers/projects/imports_controller.rb` lines 27-30 `elsif @project.import_failed? redirect_to new_project_import_path(@project) # No flash message passed` ### **Expected Behavior** When a user is directed to the import form after a blotched import, they should see: * A dismissible alert briefly explaining why the import failed in user-friendly language * Contextual guidance based on the failure type (URL/connection error, timeout, cancellation, etc.) ## **Acceptance Criteria** *  When an import fails and user is redirected to the form, an alert is displayed *  The alert matches the error message from `@project.import_state.last_error` *  The alert is appropriately styled (danger/warning level based on failure type) *  Different failure types are handled appropriately: *  URL/connection errors (exit status 128, cloning failures) *  Timeout errors (import took longer than X seconds) *  Cancellation (user cancelled the import) *  Other import-related failures *  Alert is dismissible *  Tests cover the redirect with error message scenario --- ## **Tentative Implementation Approach (Please verify)** ### **1. Controller Changes (`app/controllers/projects/imports_controller.rb`)** Modify the `show` action to pass the error message when redirecting: `elsif @project.import_failed? redirect_to new_project_import_path(@project), alert: @project.import_state.last_error` ### **2. View Changes** Option1: Add alert rendering before the form component in (app/views/projects/imports/new.html.haml) `- if alert.present?` `= render pajamas alert` Option2: render alert in Vue component Eg. passing import failure state to the Vue component: * Add `import_failed` boolean to component data attributes * Add `import_error` message to component data attributes ### 3. Possibly customize the error message Should we modify the error message depending on why the import failed? **Please consult with a UX team member** for guidance on this. In general, there are multiple errors that might be saved in project_mirror_data.last_error . Some examples observed in project_mirror_data | status | last_error | |--------|------------| | canceled | null | | failed | 52 54 0 2025-11-26 22:16:37.809465 2025-11-26 22:16:37.715948 NULL failed 4fef732dff8fd13a1b9b8558 Error importing repository \<repo-link\> into Commit451/project-to-fail - 13:creating repository: cloning repository: exit status 128. NULL NULL 01KB13TV6DZA3K242JPPY5FG9J {} | | failed | Import timed out. Import took longer than 86400 seconds | | failed | The default branch (master) has diverged from its upstream counterpart and could not be updated automatically. | Note that cancelled import doesn't have a last_error so we'd need a custom message ### **4. Testing** Add test cases for: * Redirect with error message when import fails * Alert displays on the form page * Different error message types are handled * Alert is dismissible ## **Notes** * The error message is already available in `@project.import_state.last_error` (sanitized via `Gitlab::UrlSanitizer.sanitize`) * The `unsafe_import_url` is already passed to the Vue component, so the form will be pre-populated <!--template sourced from https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/issue_templates/Default.md-->
issue