Improve MR code reloading when push code

Every time you pushed to master it updates merge requests that has master
as target branch. So if you have 50 open merge requests point to master
it will reload all of them every time you push a single commit to
master. The funny thing is that after reloading diff of most merge
requests looks the same.

After this patch we update diff only if we push commit to master that
includes in MR commits list.

For example we have next repository:

feature: A - B - C
master: A

We create merge requests #1 with code from feature to master.

MR #1: B - C

If we push to master commit D - MR will not be reloaded. So picture will
look next:

feature: A - B - C
master: A - D
MR #1: B - C

And if we push to master commit B - MR will be reloaded. So picture will
look next:

feature: A - B - C
master: A - B
MR #1: C

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-12-02 16:22:23 +02:00
parent bf39347970
commit 9211b541d3
No known key found for this signature in database
GPG Key ID: 161B5D6A44D3D88A
1 changed files with 16 additions and 2 deletions

View File

@ -43,8 +43,22 @@ module MergeRequests
merge_requests = filter_merge_requests(merge_requests)
merge_requests.each do |merge_request|
merge_request.reload_code
merge_request.mark_as_unchecked
if merge_request.source_branch == @branch_name
merge_request.reload_code
merge_request.mark_as_unchecked
else
mr_commit_ids = merge_request.commits.map(&:id)
push_commit_ids = @commits.map(&:id)
matches = mr_commit_ids & push_commit_ids
if matches.any?
merge_request.reload_code
merge_request.mark_as_unchecked
else
merge_request.mark_as_unchecked
end
end
end
end