Commit a443acbc authored by Sam Bigelow's avatar Sam Bigelow Committed by Mike Greiling

Set cached MRWidget SHA after rebase

parent 111b7465
......@@ -72,7 +72,7 @@ export default {
Flash('Something went wrong. Please try again.');
}
eventHub.$emit('MRWidgetUpdateRequested');
eventHub.$emit('MRWidgetRebaseSuccess');
stopPolling();
}
})
......
......@@ -156,13 +156,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) {
......@@ -264,6 +264,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 => {
......
......@@ -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;
......
......@@ -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;
......
---
title: Allow merge after rebase without page refresh on FF repositories
merge_request: 23572
author:
type: fixed
......@@ -27,11 +27,11 @@ export default class MergeRequestStore extends CEMergeRequestStore {
this.licenseManagement = data.license_management;
}
setData(data) {
setData(data, isRebased) {
this.initGeo(data);
this.initApprovals(data);
super.setData(data);
super.setData(data, isRebased);
}
initGeo(data) {
......
......@@ -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);
......
......@@ -35,7 +35,7 @@ describe('getStateKey', () => {
expect(bound()).toEqual('mergeWhenPipelineSucceeds');
context.hasSHAChanged = true;
context.isSHAMismatch = true;
expect(bound()).toEqual('shaMismatch');
......
......@@ -10,16 +10,23 @@ describe('MergeRequestStore', () => {
});
describe('setData', () => {
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', () => {
......
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