2018-03-05 22:24:16 +00:00
|
|
|
<script>
|
2019-06-11 14:19:22 +00:00
|
|
|
import _ from 'underscore';
|
2017-05-09 04:15:34 +00:00
|
|
|
import successSvg from 'icons/_icon_status_success.svg';
|
|
|
|
import warningSvg from 'icons/_icon_status_warning.svg';
|
|
|
|
import simplePoll from '~/lib/utils/simple_poll';
|
2019-02-07 15:14:56 +00:00
|
|
|
import { __ } from '~/locale';
|
2019-04-24 14:09:04 +00:00
|
|
|
import readyToMergeMixin from 'ee_else_ce/vue_merge_request_widget/mixins/ready_to_merge';
|
2018-01-15 17:06:38 +00:00
|
|
|
import MergeRequest from '../../../merge_request';
|
2017-10-02 12:32:53 +00:00
|
|
|
import Flash from '../../../flash';
|
2018-01-24 16:54:06 +00:00
|
|
|
import statusIcon from '../mr_widget_status_icon.vue';
|
2017-05-09 04:15:34 +00:00
|
|
|
import eventHub from '../../event_hub';
|
2018-09-21 10:07:17 +00:00
|
|
|
import SquashBeforeMerge from './squash_before_merge.vue';
|
2019-02-07 15:14:56 +00:00
|
|
|
import CommitsHeader from './commits_header.vue';
|
|
|
|
import CommitEdit from './commit_edit.vue';
|
|
|
|
import CommitMessageDropdown from './commit_message_dropdown.vue';
|
2019-06-11 14:19:22 +00:00
|
|
|
import { AUTO_MERGE_STRATEGIES } from '../../constants';
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
export default {
|
2018-03-05 22:24:16 +00:00
|
|
|
name: 'ReadyToMerge',
|
|
|
|
components: {
|
|
|
|
statusIcon,
|
2019-01-15 09:11:34 +00:00
|
|
|
SquashBeforeMerge,
|
2019-02-07 15:14:56 +00:00
|
|
|
CommitsHeader,
|
|
|
|
CommitEdit,
|
|
|
|
CommitMessageDropdown,
|
2018-03-05 22:24:16 +00:00
|
|
|
},
|
2019-04-24 14:09:04 +00:00
|
|
|
mixins: [readyToMergeMixin],
|
2017-05-09 04:15:34 +00:00
|
|
|
props: {
|
|
|
|
mr: { type: Object, required: true },
|
|
|
|
service: { type: Object, required: true },
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2017-05-19 17:33:03 +00:00
|
|
|
removeSourceBranch: this.mr.shouldRemoveSourceBranch,
|
2017-05-09 04:15:34 +00:00
|
|
|
isMakingRequest: false,
|
|
|
|
isMergingImmediately: false,
|
|
|
|
commitMessage: this.mr.commitMessage,
|
2019-01-15 09:11:34 +00:00
|
|
|
squashBeforeMerge: this.mr.squash,
|
2017-05-09 04:15:34 +00:00
|
|
|
successSvg,
|
|
|
|
warningSvg,
|
2019-02-07 15:14:56 +00:00
|
|
|
squashCommitMessage: this.mr.squashCommitMessage,
|
2017-05-09 04:15:34 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2019-06-11 14:19:22 +00:00
|
|
|
isAutoMergeAvailable() {
|
|
|
|
return !_.isEmpty(this.mr.availableAutoMergeStrategies);
|
2017-09-01 00:46:18 +00:00
|
|
|
},
|
2017-09-11 11:47:33 +00:00
|
|
|
status() {
|
2019-06-11 14:19:22 +00:00
|
|
|
const { pipeline, isPipelineFailed, hasCI, ciStatus } = this.mr;
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
if (hasCI && !ciStatus) {
|
2017-09-11 11:47:33 +00:00
|
|
|
return 'failed';
|
2019-06-11 14:19:22 +00:00
|
|
|
} else if (this.isAutoMergeAvailable) {
|
|
|
|
return 'pending';
|
2017-05-09 04:15:34 +00:00
|
|
|
} else if (!pipeline) {
|
2017-09-11 11:47:33 +00:00
|
|
|
return 'success';
|
2017-05-09 04:15:34 +00:00
|
|
|
} else if (isPipelineFailed) {
|
2017-09-11 11:47:33 +00:00
|
|
|
return 'failed';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'success';
|
|
|
|
},
|
|
|
|
mergeButtonClass() {
|
|
|
|
const defaultClass = 'btn btn-sm btn-success accept-merge-request';
|
|
|
|
const failedClass = `${defaultClass} btn-danger`;
|
|
|
|
const inActionClass = `${defaultClass} btn-info`;
|
|
|
|
|
|
|
|
if (this.status === 'failed') {
|
2017-05-09 04:15:34 +00:00
|
|
|
return failedClass;
|
2017-09-11 11:47:33 +00:00
|
|
|
} else if (this.status === 'pending') {
|
|
|
|
return inActionClass;
|
2017-05-09 04:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return defaultClass;
|
|
|
|
},
|
2017-09-11 11:47:33 +00:00
|
|
|
iconClass() {
|
2018-10-30 20:28:31 +00:00
|
|
|
if (
|
|
|
|
this.status === 'failed' ||
|
|
|
|
!this.commitMessage.length ||
|
|
|
|
!this.mr.isMergeAllowed ||
|
|
|
|
this.mr.preventMerge
|
|
|
|
) {
|
2018-01-19 15:56:34 +00:00
|
|
|
return 'warning';
|
2017-09-11 11:47:33 +00:00
|
|
|
}
|
|
|
|
return 'success';
|
|
|
|
},
|
2017-05-09 04:15:34 +00:00
|
|
|
mergeButtonText() {
|
|
|
|
if (this.isMergingImmediately) {
|
2019-02-07 15:14:56 +00:00
|
|
|
return __('Merge in progress');
|
2019-06-11 14:19:22 +00:00
|
|
|
} else if (this.isAutoMergeAvailable) {
|
|
|
|
return this.autoMergeText;
|
2017-05-09 04:15:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:19:22 +00:00
|
|
|
return __('Merge');
|
2017-05-09 04:15:34 +00:00
|
|
|
},
|
|
|
|
shouldShowMergeOptionsDropdown() {
|
2019-06-11 14:19:22 +00:00
|
|
|
return this.isAutoMergeAvailable && !this.mr.onlyAllowMergeIfPipelineSucceeds;
|
2017-05-09 04:15:34 +00:00
|
|
|
},
|
2017-05-19 17:33:03 +00:00
|
|
|
isRemoveSourceBranchButtonDisabled() {
|
2018-03-08 13:33:59 +00:00
|
|
|
return this.isMergeButtonDisabled;
|
2017-05-19 17:33:03 +00:00
|
|
|
},
|
2017-05-09 04:15:34 +00:00
|
|
|
shouldShowSquashBeforeMerge() {
|
|
|
|
const { commitsCount, enableSquashBeforeMerge } = this.mr;
|
|
|
|
return enableSquashBeforeMerge && commitsCount > 1;
|
|
|
|
},
|
2017-09-01 00:46:18 +00:00
|
|
|
shouldShowMergeControls() {
|
2019-06-11 14:19:22 +00:00
|
|
|
return this.mr.isMergeAllowed || this.isAutoMergeAvailable;
|
2017-05-09 04:15:34 +00:00
|
|
|
},
|
2019-03-13 15:44:16 +00:00
|
|
|
shouldShowSquashEdit() {
|
|
|
|
return this.squashBeforeMerge && this.shouldShowSquashBeforeMerge;
|
|
|
|
},
|
|
|
|
shouldShowMergeEdit() {
|
|
|
|
return !this.mr.ffOnlyEnabled;
|
|
|
|
},
|
2019-02-07 15:14:56 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateMergeCommitMessage(includeDescription) {
|
|
|
|
const { commitMessageWithDescription, commitMessage } = this.mr;
|
|
|
|
this.commitMessage = includeDescription ? commitMessageWithDescription : commitMessage;
|
2017-05-09 04:15:34 +00:00
|
|
|
},
|
2019-06-11 14:19:22 +00:00
|
|
|
handleMergeButtonClick(useAutoMerge, mergeImmediately = false) {
|
|
|
|
if (mergeImmediately) {
|
2017-05-09 04:15:34 +00:00
|
|
|
this.isMergingImmediately = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
sha: this.mr.sha,
|
|
|
|
commit_message: this.commitMessage,
|
2019-06-11 14:19:22 +00:00
|
|
|
auto_merge_strategy: useAutoMerge ? this.mr.preferredAutoMergeStrategy : undefined,
|
2017-05-09 04:15:34 +00:00
|
|
|
should_remove_source_branch: this.removeSourceBranch === true,
|
2019-01-15 09:11:34 +00:00
|
|
|
squash: this.squashBeforeMerge,
|
2019-02-07 15:14:56 +00:00
|
|
|
squash_commit_message: this.squashCommitMessage,
|
2017-05-09 04:15:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.isMakingRequest = true;
|
2018-10-30 20:28:31 +00:00
|
|
|
this.service
|
|
|
|
.merge(options)
|
2017-12-15 06:11:00 +00:00
|
|
|
.then(res => res.data)
|
2018-10-30 20:28:31 +00:00
|
|
|
.then(data => {
|
2017-12-15 06:11:00 +00:00
|
|
|
const hasError = data.status === 'failed' || data.status === 'hook_validation_error';
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2019-06-11 14:19:22 +00:00
|
|
|
if (_.includes(AUTO_MERGE_STRATEGIES, data.status)) {
|
2017-05-09 04:15:34 +00:00
|
|
|
eventHub.$emit('MRWidgetUpdateRequested');
|
2017-12-15 06:11:00 +00:00
|
|
|
} else if (data.status === 'success') {
|
2017-05-09 04:15:34 +00:00
|
|
|
this.initiateMergePolling();
|
|
|
|
} else if (hasError) {
|
2017-12-15 06:11:00 +00:00
|
|
|
eventHub.$emit('FailedToMerge', data.merge_error);
|
2017-05-09 04:15:34 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.isMakingRequest = false;
|
2019-02-07 15:14:56 +00:00
|
|
|
new Flash(__('Something went wrong. Please try again.')); // eslint-disable-line
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
initiateMergePolling() {
|
2019-03-11 20:18:36 +00:00
|
|
|
simplePoll(
|
|
|
|
(continuePolling, stopPolling) => {
|
|
|
|
this.handleMergePolling(continuePolling, stopPolling);
|
|
|
|
},
|
|
|
|
{ timeout: 0 },
|
|
|
|
);
|
2017-05-09 04:15:34 +00:00
|
|
|
},
|
|
|
|
handleMergePolling(continuePolling, stopPolling) {
|
2018-10-30 20:28:31 +00:00
|
|
|
this.service
|
|
|
|
.poll()
|
2017-12-15 06:11:00 +00:00
|
|
|
.then(res => res.data)
|
2018-10-30 20:28:31 +00:00
|
|
|
.then(data => {
|
2017-12-15 06:11:00 +00:00
|
|
|
if (data.state === 'merged') {
|
2017-05-09 04:15:34 +00:00
|
|
|
// If state is merged we should update the widget and stop the polling
|
|
|
|
eventHub.$emit('MRWidgetUpdateRequested');
|
|
|
|
eventHub.$emit('FetchActionsContent');
|
2018-01-17 14:09:59 +00:00
|
|
|
MergeRequest.setStatusBoxToMerged();
|
2018-01-15 17:06:38 +00:00
|
|
|
MergeRequest.hideCloseButton();
|
|
|
|
MergeRequest.decreaseCounter();
|
2017-05-09 04:15:34 +00:00
|
|
|
stopPolling();
|
|
|
|
|
|
|
|
// If user checked remove source branch and we didn't remove the branch yet
|
|
|
|
// we should start another polling for source branch remove process
|
2017-12-15 06:11:00 +00:00
|
|
|
if (this.removeSourceBranch && data.source_branch_exists) {
|
2017-05-09 04:15:34 +00:00
|
|
|
this.initiateRemoveSourceBranchPolling();
|
|
|
|
}
|
2017-12-15 06:11:00 +00:00
|
|
|
} else if (data.merge_error) {
|
|
|
|
eventHub.$emit('FailedToMerge', data.merge_error);
|
2017-05-09 04:15:34 +00:00
|
|
|
stopPolling();
|
|
|
|
} else {
|
|
|
|
// MR is not merged yet, continue polling until the state becomes 'merged'
|
|
|
|
continuePolling();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2019-02-07 15:14:56 +00:00
|
|
|
new Flash(__('Something went wrong while merging this merge request. Please try again.')); // eslint-disable-line
|
2019-03-11 20:18:36 +00:00
|
|
|
stopPolling();
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
initiateRemoveSourceBranchPolling() {
|
|
|
|
// We need to show source branch is being removed spinner in another component
|
|
|
|
eventHub.$emit('SetBranchRemoveFlag', [true]);
|
|
|
|
|
|
|
|
simplePoll((continuePolling, stopPolling) => {
|
|
|
|
this.handleRemoveBranchPolling(continuePolling, stopPolling);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleRemoveBranchPolling(continuePolling, stopPolling) {
|
2018-10-30 20:28:31 +00:00
|
|
|
this.service
|
|
|
|
.poll()
|
2017-12-15 06:11:00 +00:00
|
|
|
.then(res => res.data)
|
2018-10-30 20:28:31 +00:00
|
|
|
.then(data => {
|
2017-05-09 04:15:34 +00:00
|
|
|
// If source branch exists then we should continue polling
|
|
|
|
// because removing a source branch is a background task and takes time
|
2017-12-15 06:11:00 +00:00
|
|
|
if (data.source_branch_exists) {
|
2017-05-09 04:15:34 +00:00
|
|
|
continuePolling();
|
|
|
|
} else {
|
|
|
|
// Branch is removed. Update widget, stop polling and hide the spinner
|
|
|
|
eventHub.$emit('MRWidgetUpdateRequested', () => {
|
|
|
|
eventHub.$emit('SetBranchRemoveFlag', [false]);
|
|
|
|
});
|
|
|
|
stopPolling();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2019-02-07 15:14:56 +00:00
|
|
|
new Flash(__('Something went wrong while deleting the source branch. Please try again.')); // eslint-disable-line
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2018-03-05 22:24:16 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2019-02-07 15:14:56 +00:00
|
|
|
<div>
|
|
|
|
<div class="mr-widget-body media">
|
|
|
|
<status-icon :status="iconClass" />
|
|
|
|
<div class="media-body">
|
|
|
|
<div class="mr-widget-body-controls media space-children">
|
|
|
|
<span class="btn-group">
|
2017-08-07 02:29:37 +00:00
|
|
|
<button
|
|
|
|
:disabled="isMergeButtonDisabled"
|
2019-02-07 15:14:56 +00:00
|
|
|
:class="mergeButtonClass"
|
2018-06-11 09:49:47 +00:00
|
|
|
type="button"
|
2019-02-07 15:14:56 +00:00
|
|
|
class="qa-merge-button"
|
2019-06-11 14:19:22 +00:00
|
|
|
@click="handleMergeButtonClick(isAutoMergeAvailable)"
|
2018-11-16 20:07:38 +00:00
|
|
|
>
|
2019-02-07 15:14:56 +00:00
|
|
|
<i v-if="isMakingRequest" class="fa fa-spinner fa-spin" aria-hidden="true"></i>
|
|
|
|
{{ mergeButtonText }}
|
2017-08-07 02:29:37 +00:00
|
|
|
</button>
|
2019-02-07 15:14:56 +00:00
|
|
|
<button
|
2019-06-11 14:19:22 +00:00
|
|
|
v-if="isAutoMergeAvailable"
|
2019-02-07 15:14:56 +00:00
|
|
|
:disabled="isMergeButtonDisabled"
|
|
|
|
type="button"
|
|
|
|
class="btn btn-sm btn-info dropdown-toggle js-merge-moment"
|
|
|
|
data-toggle="dropdown"
|
2019-07-08 08:20:45 +00:00
|
|
|
:aria-label="__('Select merge moment')"
|
2019-02-07 15:14:56 +00:00
|
|
|
>
|
|
|
|
<i class="fa fa-chevron-down qa-merge-moment-dropdown" aria-hidden="true"></i>
|
|
|
|
</button>
|
|
|
|
<ul
|
|
|
|
v-if="shouldShowMergeOptionsDropdown"
|
|
|
|
class="dropdown-menu dropdown-menu-right"
|
|
|
|
role="menu"
|
|
|
|
>
|
|
|
|
<li>
|
|
|
|
<a
|
2019-06-11 14:19:22 +00:00
|
|
|
class="auto_merge_enabled qa-merge-when-pipeline-succeeds-option"
|
2019-02-07 15:14:56 +00:00
|
|
|
href="#"
|
|
|
|
@click.prevent="handleMergeButtonClick(true)"
|
|
|
|
>
|
|
|
|
<span class="media">
|
|
|
|
<span class="merge-opt-icon" aria-hidden="true" v-html="successSvg"></span>
|
2019-06-11 14:19:22 +00:00
|
|
|
<span class="media-body merge-opt-title">{{ autoMergeText }}</span>
|
2019-02-07 15:14:56 +00:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
class="accept-merge-request qa-merge-immediately-option"
|
|
|
|
href="#"
|
|
|
|
@click.prevent="handleMergeButtonClick(false, true)"
|
|
|
|
>
|
|
|
|
<span class="media">
|
|
|
|
<span class="merge-opt-icon" aria-hidden="true" v-html="warningSvg"></span>
|
|
|
|
<span class="media-body merge-opt-title">{{ __('Merge immediately') }}</span>
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</span>
|
|
|
|
<div class="media-body-wrap space-children">
|
|
|
|
<template v-if="shouldShowMergeControls">
|
|
|
|
<label v-if="mr.canRemoveSourceBranch">
|
|
|
|
<input
|
|
|
|
id="remove-source-branch-input"
|
|
|
|
v-model="removeSourceBranch"
|
|
|
|
:disabled="isRemoveSourceBranchButtonDisabled"
|
|
|
|
class="js-remove-source-branch-checkbox"
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
|
|
|
{{ __('Delete source branch') }}
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<!-- Placeholder for EE extension of this component -->
|
|
|
|
<squash-before-merge
|
|
|
|
v-if="shouldShowSquashBeforeMerge"
|
|
|
|
v-model="squashBeforeMerge"
|
|
|
|
:help-path="mr.squashBeforeMergeHelpPath"
|
|
|
|
:is-disabled="isMergeButtonDisabled"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<span class="bold js-resolve-mr-widget-items-message">
|
|
|
|
{{ __('You can only merge once the items above are resolved') }}
|
|
|
|
</span>
|
|
|
|
</template>
|
2017-05-09 04:15:34 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-08-07 02:29:37 +00:00
|
|
|
</div>
|
2017-05-09 04:15:34 +00:00
|
|
|
</div>
|
2019-02-07 15:14:56 +00:00
|
|
|
<template v-if="shouldShowMergeControls">
|
|
|
|
<div v-if="mr.ffOnlyEnabled" class="mr-fast-forward-message">
|
|
|
|
{{ __('Fast-forward merge without a merge commit') }}
|
|
|
|
</div>
|
2019-03-13 15:44:16 +00:00
|
|
|
<commits-header
|
|
|
|
v-if="shouldShowSquashEdit || shouldShowMergeEdit"
|
|
|
|
:is-squash-enabled="squashBeforeMerge"
|
|
|
|
:commits-count="mr.commitsCount"
|
|
|
|
:target-branch="mr.targetBranch"
|
|
|
|
:is-fast-forward-enabled="mr.ffOnlyEnabled"
|
2019-06-04 07:34:35 +00:00
|
|
|
:class="{ 'border-bottom': mr.mergeError }"
|
2019-03-13 15:44:16 +00:00
|
|
|
>
|
|
|
|
<ul class="border-top content-list commits-list flex-list">
|
|
|
|
<commit-edit
|
|
|
|
v-if="shouldShowSquashEdit"
|
|
|
|
v-model="squashCommitMessage"
|
|
|
|
:label="__('Squash commit message')"
|
|
|
|
input-id="squash-message-edit"
|
|
|
|
squash
|
|
|
|
>
|
|
|
|
<commit-message-dropdown
|
|
|
|
slot="header"
|
2019-02-07 15:14:56 +00:00
|
|
|
v-model="squashCommitMessage"
|
2019-03-13 15:44:16 +00:00
|
|
|
:commits="mr.commits"
|
|
|
|
/>
|
|
|
|
</commit-edit>
|
|
|
|
<commit-edit
|
|
|
|
v-if="shouldShowMergeEdit"
|
|
|
|
v-model="commitMessage"
|
|
|
|
:label="__('Merge commit message')"
|
|
|
|
input-id="merge-message-edit"
|
|
|
|
>
|
|
|
|
<label slot="checkbox">
|
|
|
|
<input
|
|
|
|
id="include-description"
|
|
|
|
type="checkbox"
|
|
|
|
@change="updateMergeCommitMessage($event.target.checked)"
|
2019-02-07 15:14:56 +00:00
|
|
|
/>
|
2019-03-13 15:44:16 +00:00
|
|
|
{{ __('Include merge request description') }}
|
|
|
|
</label>
|
|
|
|
</commit-edit>
|
|
|
|
</ul>
|
|
|
|
</commits-header>
|
2019-02-07 15:14:56 +00:00
|
|
|
</template>
|
2018-03-05 22:24:16 +00:00
|
|
|
</div>
|
|
|
|
</template>
|