Commit 90bc51c3 authored by Miguel Rincon's avatar Miguel Rincon

Keep track of last commit in pipeline editor

This change is a technical iteration to keep track of
the last committed sha by the user after any commit is submitted
successfully.

No UI changes are expected, and the actual alert will be added in a
follow up MR.
parent c38c150c
...@@ -19,7 +19,7 @@ mutation commitCIFileMutation( ...@@ -19,7 +19,7 @@ mutation commitCIFileMutation(
} }
) { ) {
commit { commit {
id sha
} }
errors errors
} }
......
...@@ -14,7 +14,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -14,7 +14,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
return null; return null;
} }
const { ciConfigPath, commitId, defaultBranch, newMergeRequestPath, projectPath } = el?.dataset; const { ciConfigPath, commitSha, defaultBranch, newMergeRequestPath, projectPath } = el?.dataset;
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -29,7 +29,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -29,7 +29,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
return h(PipelineEditorApp, { return h(PipelineEditorApp, {
props: { props: {
ciConfigPath, ciConfigPath,
commitId, commitSha,
defaultBranch, defaultBranch,
newMergeRequestPath, newMergeRequestPath,
projectPath, projectPath,
......
...@@ -43,7 +43,7 @@ export default { ...@@ -43,7 +43,7 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
commitId: { commitSha: {
type: String, type: String,
required: false, required: false,
default: null, default: null,
...@@ -62,6 +62,7 @@ export default { ...@@ -62,6 +62,7 @@ export default {
ciConfigData: {}, ciConfigData: {},
content: '', content: '',
contentModel: '', contentModel: '',
lastCommitSha: this.commitSha,
currentTabIndex: 0, currentTabIndex: 0,
editorIsReady: false, editorIsReady: false,
failureType: null, failureType: null,
...@@ -209,7 +210,7 @@ export default { ...@@ -209,7 +210,7 @@ export default {
try { try {
const { const {
data: { data: {
commitCreate: { errors }, commitCreate: { errors, commit },
}, },
} = await this.$apollo.mutate({ } = await this.$apollo.mutate({
mutation: commitCiFileMutation, mutation: commitCiFileMutation,
...@@ -220,7 +221,7 @@ export default { ...@@ -220,7 +221,7 @@ export default {
message, message,
filePath: this.ciConfigPath, filePath: this.ciConfigPath,
content: this.contentModel, content: this.contentModel,
lastCommitId: this.commitId, lastCommitId: this.lastCommitSha,
}, },
}); });
...@@ -232,7 +233,12 @@ export default { ...@@ -232,7 +233,12 @@ export default {
if (openMergeRequest) { if (openMergeRequest) {
this.redirectToNewMergeRequest(branch); this.redirectToNewMergeRequest(branch);
} else { } else {
// Refresh the page to ensure commit is updated this.lastCommitSha = commit.sha;
// Note: The page should not be refreshed, and we
// would display an alert to notify users the
// commit was succesful. See:
// https://gitlab.com/gitlab-org/gitlab/-/issues/292229
refreshCurrentPage(); refreshCurrentPage();
} }
} catch (error) { } catch (error) {
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
#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.full_path,
"default-branch" => @project.default_branch, "default-branch" => @project.default_branch,
"commit-id" => @project.commit ? @project.commit.id : '', "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,
} } } }
export const mockProjectPath = 'user1/project1'; export const mockProjectPath = 'user1/project1';
export const mockDefaultBranch = 'master'; export const mockDefaultBranch = 'master';
export const mockNewMergeRequestPath = '/-/merge_requests/new'; export const mockNewMergeRequestPath = '/-/merge_requests/new';
export const mockCommitId = 'aabbccdd'; export const mockCommitSha = 'aabbccdd';
export const mockCommitNextSha = 'eeffgghh';
export const mockCommitMessage = 'My commit message'; export const mockCommitMessage = 'My commit message';
export const mockCiConfigPath = '.gitlab-ci.yml'; export const mockCiConfigPath = '.gitlab-ci.yml';
......
...@@ -18,7 +18,8 @@ import { ...@@ -18,7 +18,8 @@ import {
mockCiConfigPath, mockCiConfigPath,
mockCiConfigQueryResponse, mockCiConfigQueryResponse,
mockCiYml, mockCiYml,
mockCommitId, mockCommitSha,
mockCommitNextSha,
mockCommitMessage, mockCommitMessage,
mockDefaultBranch, mockDefaultBranch,
mockProjectPath, mockProjectPath,
...@@ -65,7 +66,9 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -65,7 +66,9 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
data: { data: {
commitCreate: { commitCreate: {
errors: [], errors: [],
commit: {}, commit: {
sha: mockCommitNextSha,
},
}, },
}, },
}); });
...@@ -73,7 +76,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -73,7 +76,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
wrapper = mountFn(PipelineEditorApp, { wrapper = mountFn(PipelineEditorApp, {
propsData: { propsData: {
ciConfigPath: mockCiConfigPath, ciConfigPath: mockCiConfigPath,
commitId: mockCommitId, commitSha: mockCommitSha,
defaultBranch: mockDefaultBranch, defaultBranch: mockDefaultBranch,
projectPath: mockProjectPath, projectPath: mockProjectPath,
newMergeRequestPath: mockNewMergeRequestPath, newMergeRequestPath: mockNewMergeRequestPath,
...@@ -239,7 +242,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => { ...@@ -239,7 +242,7 @@ describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
const mockVariables = { const mockVariables = {
content: mockCiYml, content: mockCiYml,
filePath: mockCiConfigPath, filePath: mockCiConfigPath,
lastCommitId: mockCommitId, lastCommitId: mockCommitSha,
message: mockCommitMessage, message: mockCommitMessage,
projectPath: mockProjectPath, projectPath: mockProjectPath,
startBranch: mockDefaultBranch, startBranch: mockDefaultBranch,
......
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