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 { EXTENSION_CI_SCHEMA_FILE_NAME_MATCH } from '../constants';
import { SourceEditorExtension } from './source_editor_extension_base';
export class CiSchemaExtension extends SourceEditorExtension {
......@@ -16,12 +15,7 @@ export class CiSchemaExtension extends SourceEditorExtension {
* @param {String} opts.projectPath
* @param {String?} opts.ref - Current ref. Defaults to main
*/
registerCiSchema({ projectNamespace, projectPath, ref } = {}) {
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);
registerCiSchema() {
// In order for workers loaded from `data://` as the
// ones loaded by monaco editor, we use absolute URLs
// 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 {
SourceEditor,
},
mixins: [glFeatureFlagMixin()],
inject: ['ciConfigPath', 'projectPath', 'projectNamespace', 'defaultBranch'],
inject: ['ciConfigPath'],
inheritAttrs: false,
props: {
commitSha: {
type: String,
required: false,
default: '',
},
},
methods: {
onCiConfigUpdate(content) {
this.$emit('updateCiConfig', content);
......@@ -27,11 +20,7 @@ export default {
const editorInstance = this.$refs.editor.getEditor();
editorInstance.use(new CiSchemaExtension({ instance: editorInstance }));
editorInstance.registerCiSchema({
projectPath: this.projectPath,
projectNamespace: this.projectNamespace,
ref: this.commitSha || this.defaultBranch,
});
editorInstance.registerCiSchema();
}
},
},
......
......@@ -342,6 +342,14 @@ module.exports = {
esModule: false,
},
},
{
test: /editor\/schema\/.+\.json$/,
type: 'javascript/auto',
loader: 'file-loader',
options: {
name: '[name].[contenthash:8].[ext]',
},
},
],
},
......
import { languages } from 'monaco-editor';
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 ciSchemaPath from '~/editor/schema/ci.json';
import SourceEditor from '~/editor/source_editor';
const mockRef = 'AABBCCDD';
......@@ -84,7 +84,7 @@ describe('~/editor/editor_ci_config_ext', () => {
});
expect(getConfiguredYmlSchema()).toEqual({
uri: `${TEST_HOST}/${mockProjectNamespace}/${mockProjectPath}/-/schema/${mockRef}/${EXTENSION_CI_SCHEMA_FILE_NAME_MATCH}`,
uri: `${TEST_HOST}${ciSchemaPath}`,
fileMatch: [defaultBlobPath],
});
});
......@@ -99,7 +99,7 @@ describe('~/editor/editor_ci_config_ext', () => {
});
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'],
});
});
......
......@@ -112,11 +112,6 @@ describe('Pipeline Editor | Text editor component', () => {
it('configures editor with syntax highlight', () => {
expect(mockUse).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