From 8b3d59d5a60a99c87198e4483266bf1d5345ff79 Mon Sep 17 00:00:00 2001 From: Olaoluwa Oluro <olaoluro@gitlab.com> Date: Wed, 12 Feb 2025 14:40:32 +0000 Subject: [PATCH] Add `MALFORMED_ENTRY_OWNER` error for CODEOWNERS **Problem** We currently use Entries with spaces for some errors that are actually Malformed owners. We need to change this so we convey a clear message of what's actually happening in the error. **Solution** We should add a new error type `MALFORMED_ENTRY_OWNER: Malformed Owners` to be more specific about the error we are returning Changelog: added EE: true --- ee/app/assets/javascripts/blob/constants.js | 5 ++++- ee/lib/gitlab/code_owners/error.rb | 1 + .../frontend/blob/components/codeowners_validation_spec.js | 2 +- ee/spec/frontend/blob/mock_data.js | 5 +++++ locale/gitlab.pot | 3 +++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ee/app/assets/javascripts/blob/constants.js b/ee/app/assets/javascripts/blob/constants.js index 72522728e2f1..d93d0e16b78e 100644 --- a/ee/app/assets/javascripts/blob/constants.js +++ b/ee/app/assets/javascripts/blob/constants.js @@ -24,7 +24,7 @@ export const ERROR_MESSAGE = s__( 'CodeownersValidation|An error occurred while loading the validation errors. Please try again later.', ); -export const DOCS_URL = `${DOCS_URL_IN_EE_DIR}/user/project/codeowners/reference.html#error-handling-in-code-owners`; +export const DOCS_URL = `${DOCS_URL_IN_EE_DIR}/user/project/codeowners/advanced.html#error-handling`; export const CODEOWNERS_VALIDATION_I18N = { syntaxValid: SYNTAX_VALID, @@ -40,6 +40,8 @@ export const INVALID_SECTION_OWNER_FORMAT = s__('CodeownersValidation|Inaccessib export const MISSING_ENTRY_OWNER = s__('CodeownersValidation|Zero owners'); +export const MALFORMED_ENTRY_OWNER = s__('CodeownersValidation|Malformed owners'); + export const INVALID_ENTRY_OWNER_FORMAT = s__('CodeownersValidation|Entries with spaces'); export const MISSING_SECTION_NAME = s__('CodeownersValidation|Missing section name'); @@ -53,6 +55,7 @@ export const INVALID_SECTION_FORMAT = s__('CodeownersValidation|Unparsable secti export const CODE_TO_MESSAGE = { invalid_section_owner_format: INVALID_SECTION_OWNER_FORMAT, missing_entry_owner: MISSING_ENTRY_OWNER, + malformed_entry_owner: MALFORMED_ENTRY_OWNER, invalid_entry_owner_format: INVALID_ENTRY_OWNER_FORMAT, missing_section_name: MISSING_SECTION_NAME, invalid_approval_requirement: INVALID_APPROVAL_REQUIREMENT, diff --git a/ee/lib/gitlab/code_owners/error.rb b/ee/lib/gitlab/code_owners/error.rb index a2392ac57a2e..1ba7ed311e3c 100644 --- a/ee/lib/gitlab/code_owners/error.rb +++ b/ee/lib/gitlab/code_owners/error.rb @@ -5,6 +5,7 @@ module CodeOwners class Error INVALID_SECTION_OWNER_FORMAT = :invalid_section_owner_format MISSING_ENTRY_OWNER = :missing_entry_owner + MALFORMED_ENTRY_OWNER = :malformed_entry_owner INVALID_ENTRY_OWNER_FORMAT = :invalid_entry_owner_format MISSING_SECTION_NAME = :missing_section_name INVALID_APPROVAL_REQUIREMENT = :invalid_approval_requirement diff --git a/ee/spec/frontend/blob/components/codeowners_validation_spec.js b/ee/spec/frontend/blob/components/codeowners_validation_spec.js index e7e70e26bc4e..02600f087621 100644 --- a/ee/spec/frontend/blob/components/codeowners_validation_spec.js +++ b/ee/spec/frontend/blob/components/codeowners_validation_spec.js @@ -115,7 +115,7 @@ describe('codeowners validation', () => { it('renders links to line with error', () => { const firstErrorLink = linksToErrors().at(0); - expect(linksToErrors()).toHaveLength(6); + expect(linksToErrors()).toHaveLength(7); expect(firstErrorLink.text()).toBe('Line 2'); expect(firstErrorLink.attributes('href')).toBe('#L2'); }); diff --git a/ee/spec/frontend/blob/mock_data.js b/ee/spec/frontend/blob/mock_data.js index 5cfd1b2114dd..034f4e05d0fd 100644 --- a/ee/spec/frontend/blob/mock_data.js +++ b/ee/spec/frontend/blob/mock_data.js @@ -17,6 +17,11 @@ export const validateCodeownerFile = { lines: [5, 6], __typename: 'RepositoryCodeownerError', }, + { + code: 'malformed_entry_owner', + lines: [9], + __typename: 'RepositoryCodeownerError', + }, { code: 'invalid_section_format', lines: [36], diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 25a923410a93..2c5b535f0347 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -13954,6 +13954,9 @@ msgstr "" msgid "CodeownersValidation|Line" msgstr "" +msgid "CodeownersValidation|Malformed owners" +msgstr "" + msgid "CodeownersValidation|Missing section name" msgstr "" -- GitLab