Commit 8b6ebb54 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'editor/export-json-schema' into 'master'

Export CI schema via webpack

See merge request gitlab-org/gitlab!69737
parents 8ff86729 ab875500
import Api from '~/api'; import ciSchemaPath from '~/editor/schema/ci.json';
import { registerSchema } from '~/ide/utils'; import { registerSchema } from '~/ide/utils';
import { EXTENSION_CI_SCHEMA_FILE_NAME_MATCH } from '../constants';
import { SourceEditorExtension } from './source_editor_extension_base'; import { SourceEditorExtension } from './source_editor_extension_base';
export class CiSchemaExtension extends SourceEditorExtension { export class CiSchemaExtension extends SourceEditorExtension {
...@@ -16,12 +15,7 @@ export class CiSchemaExtension extends SourceEditorExtension { ...@@ -16,12 +15,7 @@ export class CiSchemaExtension extends SourceEditorExtension {
* @param {String} opts.projectPath * @param {String} opts.projectPath
* @param {String?} opts.ref - Current ref. Defaults to main * @param {String?} opts.ref - Current ref. Defaults to main
*/ */
registerCiSchema({ projectNamespace, projectPath, ref } = {}) { registerCiSchema() {
const ciSchemaPath = Api.buildUrl(Api.projectFileSchemaPath)
.replace(':namespace_path', projectNamespace)
.replace(':project_path', projectPath)
.replace(':ref', ref)
.replace(':filename', EXTENSION_CI_SCHEMA_FILE_NAME_MATCH);
// In order for workers loaded from `data://` as the // In order for workers loaded from `data://` as the
// ones loaded by monaco editor, we use absolute URLs // ones loaded by monaco editor, we use absolute URLs
// to fetch schema files, hence the `gon.gitlab_url` // to fetch schema files, hence the `gon.gitlab_url`
......
Copyright (c) 2015-present Mads Kristensen
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
This diff is collapsed.
...@@ -9,15 +9,8 @@ export default { ...@@ -9,15 +9,8 @@ export default {
SourceEditor, SourceEditor,
}, },
mixins: [glFeatureFlagMixin()], mixins: [glFeatureFlagMixin()],
inject: ['ciConfigPath', 'projectPath', 'projectNamespace', 'defaultBranch'], inject: ['ciConfigPath'],
inheritAttrs: false, inheritAttrs: false,
props: {
commitSha: {
type: String,
required: false,
default: '',
},
},
methods: { methods: {
onCiConfigUpdate(content) { onCiConfigUpdate(content) {
this.$emit('updateCiConfig', content); this.$emit('updateCiConfig', content);
...@@ -27,11 +20,7 @@ export default { ...@@ -27,11 +20,7 @@ export default {
const editorInstance = this.$refs.editor.getEditor(); const editorInstance = this.$refs.editor.getEditor();
editorInstance.use(new CiSchemaExtension({ instance: editorInstance })); editorInstance.use(new CiSchemaExtension({ instance: editorInstance }));
editorInstance.registerCiSchema({ editorInstance.registerCiSchema();
projectPath: this.projectPath,
projectNamespace: this.projectNamespace,
ref: this.commitSha || this.defaultBranch,
});
} }
}, },
}, },
......
...@@ -342,6 +342,14 @@ module.exports = { ...@@ -342,6 +342,14 @@ module.exports = {
esModule: false, esModule: false,
}, },
}, },
{
test: /editor\/schema\/.+\.json$/,
type: 'javascript/auto',
loader: 'file-loader',
options: {
name: '[name].[contenthash:8].[ext]',
},
},
], ],
}, },
......
import { languages } from 'monaco-editor'; import { languages } from 'monaco-editor';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { EXTENSION_CI_SCHEMA_FILE_NAME_MATCH } from '~/editor/constants';
import { CiSchemaExtension } from '~/editor/extensions/source_editor_ci_schema_ext'; import { CiSchemaExtension } from '~/editor/extensions/source_editor_ci_schema_ext';
import ciSchemaPath from '~/editor/schema/ci.json';
import SourceEditor from '~/editor/source_editor'; import SourceEditor from '~/editor/source_editor';
const mockRef = 'AABBCCDD'; const mockRef = 'AABBCCDD';
...@@ -84,7 +84,7 @@ describe('~/editor/editor_ci_config_ext', () => { ...@@ -84,7 +84,7 @@ describe('~/editor/editor_ci_config_ext', () => {
}); });
expect(getConfiguredYmlSchema()).toEqual({ expect(getConfiguredYmlSchema()).toEqual({
uri: `${TEST_HOST}/${mockProjectNamespace}/${mockProjectPath}/-/schema/${mockRef}/${EXTENSION_CI_SCHEMA_FILE_NAME_MATCH}`, uri: `${TEST_HOST}${ciSchemaPath}`,
fileMatch: [defaultBlobPath], fileMatch: [defaultBlobPath],
}); });
}); });
...@@ -99,7 +99,7 @@ describe('~/editor/editor_ci_config_ext', () => { ...@@ -99,7 +99,7 @@ describe('~/editor/editor_ci_config_ext', () => {
}); });
expect(getConfiguredYmlSchema()).toEqual({ expect(getConfiguredYmlSchema()).toEqual({
uri: `${TEST_HOST}/${mockProjectNamespace}/${mockProjectPath}/-/schema/${mockRef}/${EXTENSION_CI_SCHEMA_FILE_NAME_MATCH}`, uri: `${TEST_HOST}${ciSchemaPath}`,
fileMatch: ['another-ci-filename.yml'], fileMatch: ['another-ci-filename.yml'],
}); });
}); });
......
...@@ -112,11 +112,6 @@ describe('Pipeline Editor | Text editor component', () => { ...@@ -112,11 +112,6 @@ describe('Pipeline Editor | Text editor component', () => {
it('configures editor with syntax highlight', () => { it('configures editor with syntax highlight', () => {
expect(mockUse).toHaveBeenCalledTimes(1); expect(mockUse).toHaveBeenCalledTimes(1);
expect(mockRegisterCiSchema).toHaveBeenCalledTimes(1); expect(mockRegisterCiSchema).toHaveBeenCalledTimes(1);
expect(mockRegisterCiSchema).toHaveBeenCalledWith({
projectNamespace: mockProjectNamespace,
projectPath: mockProjectPath,
ref: mockCommitSha,
});
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment