import Flash from '../../../flash'; import statusIcon from '../mr_widget_status_icon'; import MRWidgetAuthor from '../../components/mr_widget_author'; import eventHub from '../../event_hub'; export default { name: 'MRWidgetMergeWhenPipelineSucceeds', props: { mr: { type: Object, required: true }, service: { type: Object, required: true }, }, components: { 'mr-widget-author': MRWidgetAuthor, statusIcon, }, data() { return { isCancellingAutoMerge: false, isRemovingSourceBranch: false, }; }, computed: { canRemoveSourceBranch() { const { shouldRemoveSourceBranch, canRemoveSourceBranch, mergeUserId, currentUserId } = this.mr; return !shouldRemoveSourceBranch && canRemoveSourceBranch && mergeUserId === currentUserId; }, }, methods: { cancelAutomaticMerge() { this.isCancellingAutoMerge = true; this.service.cancelAutomaticMerge() .then(res => res.data) .then((data) => { eventHub.$emit('UpdateWidgetData', data); }) .catch(() => { this.isCancellingAutoMerge = false; new Flash('Something went wrong. Please try again.'); // eslint-disable-line }); }, removeSourceBranch() { const options = { sha: this.mr.sha, merge_when_pipeline_succeeds: true, should_remove_source_branch: true, }; this.isRemovingSourceBranch = true; this.service.mergeResource.save(options) .then(res => res.data) .then((data) => { if (data.status === 'merge_when_pipeline_succeeds') { eventHub.$emit('MRWidgetUpdateRequested'); } }) .catch(() => { this.isRemovingSourceBranch = false; new Flash('Something went wrong. Please try again.'); // eslint-disable-line }); }, }, template: `

Set by to be merged automatically when the pipeline succeeds