Merge branch '47052-merge-button-does-not-appear-after-rebase-ing' into 'master'

Resolve "Merge button does not appear after Rebase-ing"

Closes #47052

See merge request gitlab-org/gitlab-ce!23572
This commit is contained in:
Mike Greiling 2018-12-14 22:40:31 +00:00
commit 9d57e8af69
8 changed files with 38 additions and 18 deletions

View file

@ -72,7 +72,7 @@ export default {
Flash('Something went wrong. Please try again.');
}
eventHub.$emit('MRWidgetUpdateRequested');
eventHub.$emit('MRWidgetRebaseSuccess');
stopPolling();
}
})

View file

@ -155,13 +155,13 @@ export default {
};
return new MRWidgetService(endpoints);
},
checkStatus(cb) {
checkStatus(cb, isRebased) {
return this.service
.checkStatus()
.then(res => res.data)
.then(data => {
this.handleNotification(data);
this.mr.setData(data);
this.mr.setData(data, isRebased);
this.setFaviconHelper();
if (cb) {
@ -263,6 +263,10 @@ export default {
this.checkStatus(cb);
});
eventHub.$on('MRWidgetRebaseSuccess', cb => {
this.checkStatus(cb, true);
});
// `params` should be an Array contains a Boolean, like `[true]`
// Passing parameter as Boolean didn't work.
eventHub.$on('SetBranchRemoveFlag', params => {

View file

@ -19,7 +19,7 @@ export default function deviseState(data) {
return stateKey.unresolvedDiscussions;
} else if (this.isPipelineBlocked) {
return stateKey.pipelineBlocked;
} else if (this.hasSHAChanged) {
} else if (this.isSHAMismatch) {
return stateKey.shaMismatch;
} else if (this.mergeWhenPipelineSucceeds) {
return this.mergeError ? stateKey.autoMergeFailed : stateKey.mergeWhenPipelineSucceeds;

View file

@ -11,7 +11,11 @@ export default class MergeRequestStore {
this.setData(data);
}
setData(data) {
setData(data, isRebased) {
if (isRebased) {
this.sha = data.diff_head_sha;
}
const currentUser = data.current_user;
const pipelineStatus = data.pipeline ? data.pipeline.details.status : null;
@ -84,7 +88,7 @@ export default class MergeRequestStore {
this.canMerge = !!data.merge_path;
this.canCreateIssue = currentUser.can_create_issue || false;
this.canCancelAutomaticMerge = !!data.cancel_merge_when_pipeline_succeeds_path;
this.hasSHAChanged = this.sha !== data.diff_head_sha;
this.isSHAMismatch = this.sha !== data.diff_head_sha;
this.canBeMerged = data.can_be_merged || false;
this.isMergeAllowed = data.mergeable || false;
this.mergeOngoing = data.merge_ongoing;

View file

@ -0,0 +1,5 @@
---
title: Allow merge after rebase without page refresh on FF repositories
merge_request: 23572
author:
type: fixed

View file

@ -114,7 +114,7 @@ describe('Merge request widget rebase component', () => {
// Wait for the eventHub to be called
.then(vm.$nextTick())
.then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested');
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetRebaseSuccess');
})
.then(done)
.catch(done.fail);

View file

@ -35,7 +35,7 @@ describe('getStateKey', () => {
expect(bound()).toEqual('mergeWhenPipelineSucceeds');
context.hasSHAChanged = true;
context.isSHAMismatch = true;
expect(bound()).toEqual('shaMismatch');

View file

@ -3,23 +3,30 @@ import { stateKey } from '~/vue_merge_request_widget/stores/state_maps';
import mockData from '../mock_data';
describe('MergeRequestStore', () => {
let store;
beforeEach(() => {
store = new MergeRequestStore(mockData);
});
describe('setData', () => {
let store;
beforeEach(() => {
store = new MergeRequestStore(mockData);
});
it('should set hasSHAChanged when the diff SHA changes', () => {
it('should set isSHAMismatch when the diff SHA changes', () => {
store.setData({ ...mockData, diff_head_sha: 'a-different-string' });
expect(store.hasSHAChanged).toBe(true);
expect(store.isSHAMismatch).toBe(true);
});
it('should not set hasSHAChanged when other data changes', () => {
it('should not set isSHAMismatch when other data changes', () => {
store.setData({ ...mockData, work_in_progress: !mockData.work_in_progress });
expect(store.hasSHAChanged).toBe(false);
expect(store.isSHAMismatch).toBe(false);
});
it('should update cached sha after rebasing', () => {
store.setData({ ...mockData, diff_head_sha: 'abc123' }, true);
expect(store.isSHAMismatch).toBe(false);
expect(store.sha).toBe('abc123');
});
describe('isPipelinePassing', () => {