Commit 23ddfb5b authored by Sarah Groff Hennigh-Palermo's avatar Sarah Groff Hennigh-Palermo

Merge branch 'pipeline-editor-branch-param' into 'master'

Allow users to work on non-default branch in pipeline editor

See merge request gitlab-org/gitlab!55413
parents 10edb14f d69f1899
...@@ -21,7 +21,7 @@ export default { ...@@ -21,7 +21,7 @@ export default {
GlSprintf, GlSprintf,
}, },
props: { props: {
defaultBranch: { currentBranch: {
type: String, type: String,
required: false, required: false,
default: '', default: '',
...@@ -40,23 +40,23 @@ export default { ...@@ -40,23 +40,23 @@ export default {
data() { data() {
return { return {
message: this.defaultMessage, message: this.defaultMessage,
branch: this.defaultBranch,
openMergeRequest: false, openMergeRequest: false,
targetBranch: this.currentBranch,
}; };
}, },
computed: { computed: {
isDefaultBranch() { isCurrentBranchTarget() {
return this.branch === this.defaultBranch; return this.targetBranch === this.currentBranch;
}, },
submitDisabled() { submitDisabled() {
return !(this.message && this.branch); return !(this.message && this.targetBranch);
}, },
}, },
methods: { methods: {
onSubmit() { onSubmit() {
this.$emit('submit', { this.$emit('submit', {
message: this.message, message: this.message,
branch: this.branch, targetBranch: this.targetBranch,
openMergeRequest: this.openMergeRequest, openMergeRequest: this.openMergeRequest,
}); });
}, },
...@@ -100,12 +100,12 @@ export default { ...@@ -100,12 +100,12 @@ export default {
> >
<gl-form-input <gl-form-input
id="target-branch-field" id="target-branch-field"
v-model="branch" v-model="targetBranch"
class="gl-font-monospace!" class="gl-font-monospace!"
required required
/> />
<gl-form-checkbox <gl-form-checkbox
v-if="!isDefaultBranch" v-if="!isCurrentBranchTarget"
v-model="openMergeRequest" v-model="openMergeRequest"
data-testid="new-mr-checkbox" data-testid="new-mr-checkbox"
class="gl-mt-3" class="gl-mt-3"
......
...@@ -4,6 +4,7 @@ import { __, s__, sprintf } from '~/locale'; ...@@ -4,6 +4,7 @@ import { __, s__, sprintf } from '~/locale';
import { COMMIT_FAILURE, COMMIT_SUCCESS } from '../../constants'; import { COMMIT_FAILURE, COMMIT_SUCCESS } from '../../constants';
import commitCIFile from '../../graphql/mutations/commit_ci_file.mutation.graphql'; import commitCIFile from '../../graphql/mutations/commit_ci_file.mutation.graphql';
import getCommitSha from '../../graphql/queries/client/commit_sha.graphql'; import getCommitSha from '../../graphql/queries/client/commit_sha.graphql';
import getCurrentBranch from '../../graphql/queries/client/current_branch.graphql';
import CommitForm from './commit_form.vue'; import CommitForm from './commit_form.vue';
...@@ -21,7 +22,7 @@ export default { ...@@ -21,7 +22,7 @@ export default {
components: { components: {
CommitForm, CommitForm,
}, },
inject: ['projectFullPath', 'ciConfigPath', 'defaultBranch', 'newMergeRequestPath'], inject: ['projectFullPath', 'ciConfigPath', 'newMergeRequestPath'],
props: { props: {
ciFileContent: { ciFileContent: {
type: String, type: String,
...@@ -38,6 +39,9 @@ export default { ...@@ -38,6 +39,9 @@ export default {
commitSha: { commitSha: {
query: getCommitSha, query: getCommitSha,
}, },
currentBranch: {
query: getCurrentBranch,
},
}, },
computed: { computed: {
defaultCommitMessage() { defaultCommitMessage() {
...@@ -49,13 +53,13 @@ export default { ...@@ -49,13 +53,13 @@ export default {
const url = mergeUrlParams( const url = mergeUrlParams(
{ {
[MR_SOURCE_BRANCH]: sourceBranch, [MR_SOURCE_BRANCH]: sourceBranch,
[MR_TARGET_BRANCH]: this.defaultBranch, [MR_TARGET_BRANCH]: this.currentBranch,
}, },
this.newMergeRequestPath, this.newMergeRequestPath,
); );
redirectTo(url); redirectTo(url);
}, },
async onCommitSubmit({ message, branch, openMergeRequest }) { async onCommitSubmit({ message, targetBranch, openMergeRequest }) {
this.isSaving = true; this.isSaving = true;
try { try {
...@@ -67,8 +71,8 @@ export default { ...@@ -67,8 +71,8 @@ export default {
mutation: commitCIFile, mutation: commitCIFile,
variables: { variables: {
projectPath: this.projectFullPath, projectPath: this.projectFullPath,
branch, branch: targetBranch,
startBranch: this.defaultBranch, startBranch: this.currentBranch,
message, message,
filePath: this.ciConfigPath, filePath: this.ciConfigPath,
content: this.ciFileContent, content: this.ciFileContent,
...@@ -86,7 +90,7 @@ export default { ...@@ -86,7 +90,7 @@ export default {
if (errors?.length) { if (errors?.length) {
this.$emit('showError', { type: COMMIT_FAILURE, reasons: errors }); this.$emit('showError', { type: COMMIT_FAILURE, reasons: errors });
} else if (openMergeRequest) { } else if (openMergeRequest) {
this.redirectToNewMergeRequest(branch); this.redirectToNewMergeRequest(targetBranch);
} else { } else {
this.$emit('commit', { type: COMMIT_SUCCESS }); this.$emit('commit', { type: COMMIT_SUCCESS });
} }
...@@ -105,7 +109,7 @@ export default { ...@@ -105,7 +109,7 @@ export default {
<template> <template>
<commit-form <commit-form
:default-branch="defaultBranch" :current-branch="currentBranch"
:default-message="defaultCommitMessage" :default-message="defaultCommitMessage"
:is-saving="isSaving" :is-saving="isSaving"
@cancel="onCommitCancel" @cancel="onCommitCancel"
......
...@@ -22,6 +22,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -22,6 +22,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
const { const {
// Add to apollo cache as it can be updated by future queries // Add to apollo cache as it can be updated by future queries
commitSha, commitSha,
initialBranchName,
// Add to provide/inject API for static values // Add to provide/inject API for static values
ciConfigPath, ciConfigPath,
defaultBranch, defaultBranch,
...@@ -42,6 +43,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -42,6 +43,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
apolloProvider.clients.defaultClient.cache.writeData({ apolloProvider.clients.defaultClient.cache.writeData({
data: { data: {
currentBranch: initialBranchName || defaultBranch,
commitSha, commitSha,
}, },
}); });
......
...@@ -9,6 +9,7 @@ import PipelineEditorEmptyState from './components/ui/pipeline_editor_empty_stat ...@@ -9,6 +9,7 @@ import PipelineEditorEmptyState from './components/ui/pipeline_editor_empty_stat
import { COMMIT_FAILURE, COMMIT_SUCCESS, DEFAULT_FAILURE, LOAD_FAILURE_UNKNOWN } from './constants'; import { COMMIT_FAILURE, COMMIT_SUCCESS, DEFAULT_FAILURE, LOAD_FAILURE_UNKNOWN } from './constants';
import getBlobContent from './graphql/queries/blob_content.graphql'; import getBlobContent from './graphql/queries/blob_content.graphql';
import getCiConfigData from './graphql/queries/ci_config.graphql'; import getCiConfigData from './graphql/queries/ci_config.graphql';
import getCurrentBranch from './graphql/queries/client/current_branch.graphql';
import PipelineEditorHome from './pipeline_editor_home.vue'; import PipelineEditorHome from './pipeline_editor_home.vue';
export default { export default {
...@@ -23,9 +24,6 @@ export default { ...@@ -23,9 +24,6 @@ export default {
ciConfigPath: { ciConfigPath: {
default: '', default: '',
}, },
defaultBranch: {
default: null,
},
projectFullPath: { projectFullPath: {
default: '', default: '',
}, },
...@@ -58,7 +56,7 @@ export default { ...@@ -58,7 +56,7 @@ export default {
return { return {
projectPath: this.projectFullPath, projectPath: this.projectFullPath,
path: this.ciConfigPath, path: this.ciConfigPath,
ref: this.defaultBranch, ref: this.currentBranch,
}; };
}, },
update(data) { update(data) {
...@@ -97,6 +95,9 @@ export default { ...@@ -97,6 +95,9 @@ export default {
this.reportFailure(LOAD_FAILURE_UNKNOWN); this.reportFailure(LOAD_FAILURE_UNKNOWN);
}, },
}, },
currentBranch: {
query: getCurrentBranch,
},
}, },
computed: { computed: {
hasUnsavedChanges() { hasUnsavedChanges() {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"commit-sha" => @project.commit ? @project.commit.sha : '', "commit-sha" => @project.commit ? @project.commit.sha : '',
"default-branch" => @project.default_branch, "default-branch" => @project.default_branch,
"empty-state-illustration-path" => image_path('illustrations/empty-state/empty-dag-md.svg'), "empty-state-illustration-path" => image_path('illustrations/empty-state/empty-dag-md.svg'),
"initial-branch-name": params[:branch_name],
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'), "lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'),
"new-merge-request-path" => namespace_project_new_merge_request_path, "new-merge-request-path" => namespace_project_new_merge_request_path,
"project-path" => @project.path, "project-path" => @project.path,
......
---
title: Allow users to work on non-default branch in pipeline editor
merge_request: 55413
author:
type: added
...@@ -12,7 +12,7 @@ describe('Pipeline Editor | Commit Form', () => { ...@@ -12,7 +12,7 @@ describe('Pipeline Editor | Commit Form', () => {
wrapper = mountFn(CommitForm, { wrapper = mountFn(CommitForm, {
propsData: { propsData: {
defaultMessage: mockCommitMessage, defaultMessage: mockCommitMessage,
defaultBranch: mockDefaultBranch, currentBranch: mockDefaultBranch,
...props, ...props,
}, },
...@@ -41,7 +41,7 @@ describe('Pipeline Editor | Commit Form', () => { ...@@ -41,7 +41,7 @@ describe('Pipeline Editor | Commit Form', () => {
expect(findCommitTextarea().attributes('value')).toBe(mockCommitMessage); expect(findCommitTextarea().attributes('value')).toBe(mockCommitMessage);
}); });
it('shows a default branch', () => { it('shows current branch', () => {
expect(findBranchInput().attributes('value')).toBe(mockDefaultBranch); expect(findBranchInput().attributes('value')).toBe(mockDefaultBranch);
}); });
...@@ -66,7 +66,7 @@ describe('Pipeline Editor | Commit Form', () => { ...@@ -66,7 +66,7 @@ describe('Pipeline Editor | Commit Form', () => {
expect(wrapper.emitted('submit')[0]).toEqual([ expect(wrapper.emitted('submit')[0]).toEqual([
{ {
message: mockCommitMessage, message: mockCommitMessage,
branch: mockDefaultBranch, targetBranch: mockDefaultBranch,
openMergeRequest: false, openMergeRequest: false,
}, },
]); ]);
...@@ -101,7 +101,7 @@ describe('Pipeline Editor | Commit Form', () => { ...@@ -101,7 +101,7 @@ describe('Pipeline Editor | Commit Form', () => {
expect(wrapper.emitted('submit')[0]).toEqual([ expect(wrapper.emitted('submit')[0]).toEqual([
{ {
message: anotherMessage, message: anotherMessage,
branch: anotherBranch, targetBranch: anotherBranch,
openMergeRequest: true, openMergeRequest: true,
}, },
]); ]);
......
...@@ -35,7 +35,6 @@ const mockVariables = { ...@@ -35,7 +35,6 @@ const mockVariables = {
const mockProvide = { const mockProvide = {
ciConfigPath: mockCiConfigPath, ciConfigPath: mockCiConfigPath,
defaultBranch: mockDefaultBranch,
projectFullPath: mockProjectFullPath, projectFullPath: mockProjectFullPath,
newMergeRequestPath: mockNewMergeRequestPath, newMergeRequestPath: mockNewMergeRequestPath,
}; };
...@@ -64,6 +63,7 @@ describe('Pipeline Editor | Commit section', () => { ...@@ -64,6 +63,7 @@ describe('Pipeline Editor | Commit section', () => {
data() { data() {
return { return {
commitSha: mockCommitSha, commitSha: mockCommitSha,
currentBranch: mockDefaultBranch,
}; };
}, },
mocks: { mocks: {
...@@ -116,7 +116,7 @@ describe('Pipeline Editor | Commit section', () => { ...@@ -116,7 +116,7 @@ describe('Pipeline Editor | Commit section', () => {
await submitCommit(); await submitCommit();
}); });
it('calls the mutation with the default branch', () => { it('calls the mutation with the current branch', () => {
expect(mockMutate).toHaveBeenCalledTimes(1); expect(mockMutate).toHaveBeenCalledTimes(1);
expect(mockMutate).toHaveBeenCalledWith({ expect(mockMutate).toHaveBeenCalledWith({
mutation: commitCreate, mutation: commitCreate,
......
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