Commit 78f70545 authored by Sam Bigelow's avatar Sam Bigelow

Set cached MRWidget SHA after rebase

Update changelog to include Merge Request ID and Author

Update changelog to include Merge Request ID and Author
parent 07e079e8
......@@ -72,7 +72,7 @@ export default {
Flash('Something went wrong. Please try again.');
}
eventHub.$emit('MRWidgetUpdateRequested');
eventHub.$emit('MRWidgetRebaseSuccess');
stopPolling();
}
})
......
......@@ -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 => {
......
......@@ -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
......@@ -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');
......
......@@ -3,23 +3,30 @@ import { stateKey } from '~/vue_merge_request_widget/stores/state_maps';
import mockData from '../mock_data';
describe('MergeRequestStore', () => {
describe('setData', () => {
let store;
let store;
beforeEach(() => {
store = new MergeRequestStore(mockData);
});
beforeEach(() => {
store = new MergeRequestStore(mockData);
});
it('should set hasSHAChanged when the diff SHA changes', () => {
describe('setData', () => {
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