Commit e616766e authored by Miguel Rincon's avatar Miguel Rincon

Use project path and project namespace separately

This change fixes an issue when loading CI schemas in project that
belong to subgroups by obtaining the namespace from the project path
separately and providing it to each different components independently.
parent c73f606c
...@@ -7,6 +7,7 @@ export default { ...@@ -7,6 +7,7 @@ export default {
EditorLite, EditorLite,
}, },
inheritAttrs: false, inheritAttrs: false,
inject: ['projectPath', 'projectNamespace'],
props: { props: {
ciConfigPath: { ciConfigPath: {
type: String, type: String,
...@@ -17,20 +18,15 @@ export default { ...@@ -17,20 +18,15 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
projectPath: {
type: String,
required: true,
},
}, },
methods: { methods: {
onEditorReady() { onEditorReady() {
const editorInstance = this.$refs.editor.getEditor(); const editorInstance = this.$refs.editor.getEditor();
const [projectNamespace, projectPath] = this.projectPath.split('/');
editorInstance.use(new CiSchemaExtension()); editorInstance.use(new CiSchemaExtension());
editorInstance.registerCiSchema({ editorInstance.registerCiSchema({
projectPath, projectPath: this.projectPath,
projectNamespace, projectNamespace: this.projectNamespace,
ref: this.commitSha, ref: this.commitSha,
}); });
}, },
......
...@@ -15,12 +15,17 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -15,12 +15,17 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
} }
const { const {
// props
ciConfigPath, ciConfigPath,
commitSha, commitSha,
defaultBranch, defaultBranch,
newMergeRequestPath, newMergeRequestPath,
// `provide/inject` data
lintHelpPagePath, lintHelpPagePath,
projectFullPath,
projectPath, projectPath,
projectNamespace,
ymlHelpPagePath, ymlHelpPagePath,
} = el?.dataset; } = el?.dataset;
...@@ -35,6 +40,9 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -35,6 +40,9 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
apolloProvider, apolloProvider,
provide: { provide: {
lintHelpPagePath, lintHelpPagePath,
projectFullPath,
projectPath,
projectNamespace,
ymlHelpPagePath, ymlHelpPagePath,
}, },
render(h) { render(h) {
...@@ -44,7 +52,6 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -44,7 +52,6 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
commitSha, commitSha,
defaultBranch, defaultBranch,
newMergeRequestPath, newMergeRequestPath,
projectPath,
}, },
}); });
}, },
......
...@@ -39,11 +39,8 @@ export default { ...@@ -39,11 +39,8 @@ export default {
ValidationSegment, ValidationSegment,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
inject: ['projectFullPath'],
props: { props: {
projectPath: {
type: String,
required: true,
},
defaultBranch: { defaultBranch: {
type: String, type: String,
required: false, required: false,
...@@ -84,7 +81,7 @@ export default { ...@@ -84,7 +81,7 @@ export default {
query: getBlobContent, query: getBlobContent,
variables() { variables() {
return { return {
projectPath: this.projectPath, projectPath: this.projectFullPath,
path: this.ciConfigPath, path: this.ciConfigPath,
ref: this.defaultBranch, ref: this.defaultBranch,
}; };
...@@ -107,7 +104,7 @@ export default { ...@@ -107,7 +104,7 @@ export default {
}, },
variables() { variables() {
return { return {
projectPath: this.projectPath, projectPath: this.projectFullPath,
content: this.contentModel, content: this.contentModel,
}; };
}, },
...@@ -244,7 +241,7 @@ export default { ...@@ -244,7 +241,7 @@ export default {
} = await this.$apollo.mutate({ } = await this.$apollo.mutate({
mutation: commitCiFileMutation, mutation: commitCiFileMutation,
variables: { variables: {
projectPath: this.projectPath, projectPath: this.projectFullPath,
branch, branch,
startBranch: this.defaultBranch, startBranch: this.defaultBranch,
message, message,
...@@ -318,7 +315,6 @@ export default { ...@@ -318,7 +315,6 @@ export default {
v-model="contentModel" v-model="contentModel"
:ci-config-path="ciConfigPath" :ci-config-path="ciConfigPath"
:commit-sha="lastCommitSha" :commit-sha="lastCommitSha"
:project-path="projectPath"
/> />
</editor-tab> </editor-tab>
<editor-tab <editor-tab
......
- page_title s_('Pipelines|Pipeline Editor') - page_title s_('Pipelines|Pipeline Editor')
#js-pipeline-editor{ data: { "ci-config-path": @project.ci_config_path_or_default, #js-pipeline-editor{ data: { "ci-config-path": @project.ci_config_path_or_default,
"project-path" => @project.full_path, "project-path" => @project.path,
"project-full-path" => @project.full_path,
"project-namespace" => @project.namespace.full_path,
"default-branch" => @project.default_branch, "default-branch" => @project.default_branch,
"commit-sha" => @project.commit ? @project.commit.sha : '', "commit-sha" => @project.commit ? @project.commit.sha : '',
"new-merge-request-path" => namespace_project_new_merge_request_path, "new-merge-request-path" => namespace_project_new_merge_request_path,
......
...@@ -4,8 +4,7 @@ import { ...@@ -4,8 +4,7 @@ import {
mockCiYml, mockCiYml,
mockCommitSha, mockCommitSha,
mockProjectPath, mockProjectPath,
mockNamespace, mockProjectNamespace,
mockProjectName,
} from '../mock_data'; } from '../mock_data';
import TextEditor from '~/pipeline_editor/components/text_editor.vue'; import TextEditor from '~/pipeline_editor/components/text_editor.vue';
...@@ -33,10 +32,13 @@ describe('~/pipeline_editor/components/text_editor.vue', () => { ...@@ -33,10 +32,13 @@ describe('~/pipeline_editor/components/text_editor.vue', () => {
const createComponent = (opts = {}, mountFn = shallowMount) => { const createComponent = (opts = {}, mountFn = shallowMount) => {
wrapper = mountFn(TextEditor, { wrapper = mountFn(TextEditor, {
provide: {
projectPath: mockProjectPath,
projectNamespace: mockProjectNamespace,
},
propsData: { propsData: {
ciConfigPath: mockCiConfigPath, ciConfigPath: mockCiConfigPath,
commitSha: mockCommitSha, commitSha: mockCommitSha,
projectPath: mockProjectPath,
}, },
attrs: { attrs: {
value: mockCiYml, value: mockCiYml,
...@@ -77,8 +79,8 @@ describe('~/pipeline_editor/components/text_editor.vue', () => { ...@@ -77,8 +79,8 @@ describe('~/pipeline_editor/components/text_editor.vue', () => {
expect(mockUse).toHaveBeenCalledTimes(1); expect(mockUse).toHaveBeenCalledTimes(1);
expect(mockRegisterCiSchema).toHaveBeenCalledTimes(1); expect(mockRegisterCiSchema).toHaveBeenCalledTimes(1);
expect(mockRegisterCiSchema).toHaveBeenCalledWith({ expect(mockRegisterCiSchema).toHaveBeenCalledWith({
projectNamespace: mockNamespace, projectNamespace: mockProjectNamespace,
projectPath: mockProjectName, projectPath: mockProjectPath,
ref: mockCommitSha, ref: mockCommitSha,
}); });
}); });
......
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
mockCiYml, mockCiYml,
mockDefaultBranch, mockDefaultBranch,
mockLintResponse, mockLintResponse,
mockProjectPath, mockProjectFullPath,
} from '../mock_data'; } from '../mock_data';
import httpStatus from '~/lib/utils/http_status'; import httpStatus from '~/lib/utils/http_status';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -32,12 +32,12 @@ describe('~/pipeline_editor/graphql/resolvers', () => { ...@@ -32,12 +32,12 @@ describe('~/pipeline_editor/graphql/resolvers', () => {
it('resolves lint data with type names', async () => { it('resolves lint data with type names', async () => {
const result = resolvers.Query.blobContent(null, { const result = resolvers.Query.blobContent(null, {
projectPath: mockProjectPath, projectPath: mockProjectFullPath,
path: mockCiConfigPath, path: mockCiConfigPath,
ref: mockDefaultBranch, ref: mockDefaultBranch,
}); });
expect(Api.getRawFile).toHaveBeenCalledWith(mockProjectPath, mockCiConfigPath, { expect(Api.getRawFile).toHaveBeenCalledWith(mockProjectFullPath, mockCiConfigPath, {
ref: mockDefaultBranch, ref: mockDefaultBranch,
}); });
......
import { CI_CONFIG_STATUS_VALID } from '~/pipeline_editor/constants'; import { CI_CONFIG_STATUS_VALID } from '~/pipeline_editor/constants';
import { unwrapStagesWithNeeds } from '~/pipelines/components/unwrapping_utils'; import { unwrapStagesWithNeeds } from '~/pipelines/components/unwrapping_utils';
export const mockNamespace = 'user1'; export const mockProjectNamespace = 'user1';
export const mockProjectName = 'project1'; export const mockProjectPath = 'project1';
export const mockProjectPath = `${mockNamespace}/${mockProjectName}`; export const mockProjectFullPath = `${mockProjectNamespace}/${mockProjectPath}`;
export const mockDefaultBranch = 'master'; export const mockDefaultBranch = 'master';
export const mockNewMergeRequestPath = '/-/merge_requests/new'; export const mockNewMergeRequestPath = '/-/merge_requests/new';
export const mockCommitSha = 'aabbccdd'; export const mockCommitSha = 'aabbccdd';
......
...@@ -15,6 +15,8 @@ import { ...@@ -15,6 +15,8 @@ import {
mockCommitMessage, mockCommitMessage,
mockDefaultBranch, mockDefaultBranch,
mockProjectPath, mockProjectPath,
mockProjectFullPath,
mockProjectNamespace,
mockNewMergeRequestPath, mockNewMergeRequestPath,
} from './mock_data'; } from './mock_data';
...@@ -39,6 +41,15 @@ const MockEditorLite = { ...@@ -39,6 +41,15 @@ const MockEditorLite = {
template: '<div/>', template: '<div/>',
}; };
const mockProvide = {
projectFullPath: mockProjectFullPath,
projectPath: mockProjectPath,
projectNamespace: mockProjectNamespace,
glFeatures: {
ciConfigVisualizationTab: true,
},
};
describe('~/pipeline_editor/pipeline_editor_app.vue', () => { describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
let wrapper; let wrapper;
...@@ -53,11 +64,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -53,11 +64,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
lintLoading = false, lintLoading = false,
options = {}, options = {},
mountFn = shallowMount, mountFn = shallowMount,
provide = { provide = mockProvide,
glFeatures: {
ciConfigVisualizationTab: true,
},
},
} = {}) => { } = {}) => {
mockMutate = jest.fn().mockResolvedValue({ mockMutate = jest.fn().mockResolvedValue({
data: { data: {
...@@ -75,7 +82,6 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -75,7 +82,6 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
ciConfigPath: mockCiConfigPath, ciConfigPath: mockCiConfigPath,
commitSha: mockCommitSha, commitSha: mockCommitSha,
defaultBranch: mockDefaultBranch, defaultBranch: mockDefaultBranch,
projectPath: mockProjectPath,
newMergeRequestPath: mockNewMergeRequestPath, newMergeRequestPath: mockNewMergeRequestPath,
...props, ...props,
}, },
...@@ -211,7 +217,12 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -211,7 +217,12 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
describe('with feature flag off', () => { describe('with feature flag off', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ provide: { glFeatures: { ciConfigVisualizationTab: false } } }); createComponent({
provide: {
...mockProvide,
glFeatures: { ciConfigVisualizationTab: false },
},
});
}); });
it('does not display the tab', () => { it('does not display the tab', () => {
...@@ -242,7 +253,6 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -242,7 +253,6 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
it('configures text editor', () => { it('configures text editor', () => {
expect(findTextEditor().props('commitSha')).toBe(mockCommitSha); expect(findTextEditor().props('commitSha')).toBe(mockCommitSha);
expect(findTextEditor().props('projectPath')).toBe(mockProjectPath);
}); });
describe('commit form', () => { describe('commit form', () => {
...@@ -251,7 +261,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -251,7 +261,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
filePath: mockCiConfigPath, filePath: mockCiConfigPath,
lastCommitId: mockCommitSha, lastCommitId: mockCommitSha,
message: mockCommitMessage, message: mockCommitMessage,
projectPath: mockProjectPath, projectPath: mockProjectFullPath,
startBranch: mockDefaultBranch, startBranch: mockDefaultBranch,
}; };
...@@ -435,7 +445,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -435,7 +445,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
expect(mockCiConfigData).toHaveBeenCalledWith({ expect(mockCiConfigData).toHaveBeenCalledWith({
content: mockCiYml, content: mockCiYml,
projectPath: mockProjectPath, projectPath: mockProjectFullPath,
}); });
}); });
......
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