diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index af7730351750f19e802aee495e4ebef7bbb1b052..85ef4aeb6060cdf30e21b6ab6c3dab9727f40136 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -71,6 +71,9 @@ def self.kroki_formats_attributes }, excalidraw: { label: 'Excalidraw' + }, + mermaid: { + label: 'Mermaid' } } end @@ -1264,6 +1267,8 @@ def kroki_format_supported?(diagram_type) return kroki_formats_excalidraw when 'bpmn' return kroki_formats_bpmn + when 'mermaid' + return kroki_formats_mermaid end return kroki_formats_blockdiag if ::Gitlab::Kroki::BLOCKDIAG_FORMATS.include?(diagram_type) diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb index c1c2cce0043bd88c7271aa083e62205debb3da08..f574c4033d9abcae4009b57d9de08f230e7d1eeb 100644 --- a/app/models/application_setting_implementation.rb +++ b/app/models/application_setting_implementation.rb @@ -284,7 +284,7 @@ def defaults # rubocop:disable Metrics/AbcSize container_registry_expiration_policies_caching: true, kroki_enabled: false, kroki_url: nil, - kroki_formats: { blockdiag: false, bpmn: false, excalidraw: false }, + kroki_formats: { blockdiag: false, bpmn: false, excalidraw: false, mermaid: false }, rate_limiting_response_text: nil, whats_new_variant: 0, user_deactivation_emails_enabled: true, diff --git a/app/validators/json_schemas/application_setting_kroki_formats.json b/app/validators/json_schemas/application_setting_kroki_formats.json index 4dfa710abeadc6ea6461e4f70d600007acf03a4a..056d48ecdd9f2b555e9f8e178a61621bc304e32d 100644 --- a/app/validators/json_schemas/application_setting_kroki_formats.json +++ b/app/validators/json_schemas/application_setting_kroki_formats.json @@ -3,9 +3,18 @@ "description": "Kroki formats", "type": "object", "properties": { - "bpmn": { "type": "boolean" }, - "excalidraw": { "type": "boolean" }, - "blockdiag": { "type": "boolean" } + "bpmn": { + "type": "boolean" + }, + "excalidraw": { + "type": "boolean" + }, + "blockdiag": { + "type": "boolean" + }, + "mermaid": { + "type": "boolean" + } }, "additionalProperties": false } diff --git a/config/application_setting_columns/kroki_formats.yml b/config/application_setting_columns/kroki_formats.yml index 942de3b5f2866c127c5bd3f5d880c540f29dc527..22efcb38be771b3d73b5c27249ad6afac13a3cd7 100644 --- a/config/application_setting_columns/kroki_formats.yml +++ b/config/application_setting_columns/kroki_formats.yml @@ -6,8 +6,8 @@ column: kroki_formats db_type: jsonb default: "'{}'::jsonb" description: 'Additional formats supported by the Kroki instance. Possible values - are `true` or `false` for formats `bpmn`, `blockdiag`, and `excalidraw` in the format - `: true` or `: false`.' + are `true` or `false` for formats `bpmn`, `blockdiag`, `excalidraw`, and `mermaid` + in the format `: true` or `: false`.' encrypted: false gitlab_com_different_than_default: false jihu: false diff --git a/doc/api/settings.md b/doc/api/settings.md index 94202803019be2dba6f964613c2369046c81fc13..7f25b302f01167d80308501d4a287a9be4d15f40 100644 --- a/doc/api/settings.md +++ b/doc/api/settings.md @@ -691,7 +691,7 @@ to configure other related settings. These requirements are | `inactive_resource_access_tokens_delete_after_days`| integer | no | Specifies retention period for inactive project and group access tokens. Default is `30`. | | `kroki_enabled` | boolean | no | (**If enabled, requires**: `kroki_url`) Enable [Kroki integration](../administration/integration/kroki.md). Default is `false`. | | `kroki_url` | string | required by: `kroki_enabled` | The Kroki instance URL for integration. | -| `kroki_formats` | object | no | Additional formats supported by the Kroki instance. Possible values are `true` or `false` for formats `bpmn`, `blockdiag`, and `excalidraw` in the format `: true` or `: false`. | +| `kroki_formats` | object | no | Additional formats supported by the Kroki instance. Possible values are `true` or `false` for formats `bpmn`, `blockdiag`, `excalidraw`, and `mermaid` in the format `: true` or `: false`. | | `plantuml_enabled` | boolean | no | (**If enabled, requires**: `plantuml_url`) Enable [PlantUML integration](../administration/integration/plantuml.md). Default is `false`. | | `plantuml_url` | string | required by: `plantuml_enabled` | The PlantUML instance URL for integration. | | `polling_interval_multiplier` | float | no | Interval multiplier used by endpoints that perform polling. Set to `0` to disable polling. | diff --git a/lib/gitlab/kroki.rb b/lib/gitlab/kroki.rb index 84dc081d9d7cae33e6ff92a4f950c4d9ccda329c..ed5418e6ab58cf57bb721616676b6ef1fb664e21 100644 --- a/lib/gitlab/kroki.rb +++ b/lib/gitlab/kroki.rb @@ -14,7 +14,12 @@ module Kroki packetdiag rackdiag ].freeze - DIAGRAMS_FORMATS = (::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES - %w[mermaid]).freeze + + # We used to explicitly remove 'mermaid' from this list, but now we allow Kroki + # to preferentially render them, *if* the administrator has explicitly enabled it + # --- Mermaid requires a companion server for Kroki. + # See https://gitlab.com/gitlab-org/gitlab/-/work_items/498764. + DIAGRAMS_FORMATS = ::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES.dup.freeze DIAGRAMS_FORMATS_WO_PLANTUML = (DIAGRAMS_FORMATS - %w[plantuml]).freeze # Get the list of diagram formats that are currently enabled diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index 9cc0d23449dfdb1f11e7bd700bc2108666a8861a..1bb0f041519d4ba1f4061b98e8c60f571809aca4 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -249,7 +249,8 @@ before do helper.instance_variable_set(:@application_setting, application_setting) - stub_application_setting(kroki_formats: { 'blockdiag' => true, 'bpmn' => false, 'excalidraw' => false }) + stub_application_setting(kroki_formats: { 'blockdiag' => true, 'bpmn' => false, 'excalidraw' => false, + 'mermaid' => true }) end it 'returns available formats correctly' do @@ -269,6 +270,11 @@ name: 'kroki_formats_excalidraw', label: 'Excalidraw', value: false + }, + { + name: 'kroki_formats_mermaid', + label: 'Mermaid', + value: true } ]) end diff --git a/spec/lib/gitlab/kroki_spec.rb b/spec/lib/gitlab/kroki_spec.rb index ab888c3b0155bbd884c77cd63c409966bfc62e14..333784db0238617458fb3368ab9a148558c8906f 100644 --- a/spec/lib/gitlab/kroki_spec.rb +++ b/spec/lib/gitlab/kroki_spec.rb @@ -17,6 +17,7 @@ def default_formats 'blockdiag' | (default_formats + %w[actdiag blockdiag nwdiag packetdiag rackdiag seqdiag]) 'bpmn' | (default_formats + %w[bpmn]) 'excalidraw' | (default_formats + %w[excalidraw]) + 'mermaid' | (default_formats + %w[mermaid]) end with_them do diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 33dd00c5deeba9995b8f2891fb853e336be3eb83..dd3a3874c5f235dc6af941ee7d070e7662b1e85e 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -159,7 +159,7 @@ invisible_captcha_enabled: false, issues_create_limit: 300, jira_connect_public_key_storage_enabled: false, - kroki_formats: { 'blockdiag' => false, 'bpmn' => false, 'excalidraw' => false }, + kroki_formats: { 'blockdiag' => false, 'bpmn' => false, 'excalidraw' => false, 'mermaid' => false }, local_markdown_version: 0, lock_maven_package_requests_forwarding: false, lock_npm_package_requests_forwarding: false, @@ -2388,6 +2388,7 @@ def expect_invalid it 'returns false when the diagram type is optional and not enabled' do expect(setting.kroki_format_supported?('bpmn')).to be(false) + expect(setting.kroki_format_supported?('mermaid')).to be(false) end it 'returns true when the diagram type is enabled by default' do @@ -2403,10 +2404,11 @@ def expect_invalid describe 'kroki_formats' do it 'returns the value for kroki_formats' do - setting.kroki_formats = { blockdiag: true, bpmn: false, excalidraw: true } + setting.kroki_formats = { blockdiag: true, bpmn: false, excalidraw: true, mermaid: true } expect(setting.kroki_formats_blockdiag).to be(true) expect(setting.kroki_formats_bpmn).to be(false) expect(setting.kroki_formats_excalidraw).to be(true) + expect(setting.kroki_formats_mermaid).to be(true) end end