summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-08-01 13:04:46 +0000
committerRémy Coutable <remy@rymai.me>2016-08-01 13:04:46 +0000
commitbe7ab1f2bc73603a8a1f21b3b0f94d737325af35 (patch)
tree81446d5a8d646b1b120aeb002d39a333c7481832
parent5d8726bb68a3f0a2aebf35339343706ede8f835b (diff)
parent285ba1b20f226f0bf7ab01010b64cabdccecf096 (diff)
downloadgitlab-ce-be7ab1f2bc73603a8a1f21b3b0f94d737325af35.tar.gz
Merge branch 'fix-gh-pull-requests' into 'master'
Fix attr reader to force the intended values for source and target shas ## What does this MR do? When importing a pull request from GitHub, the old and new branches may no longer actually exist by those names, but we need to recreate the merge request diff with the right source and target shas. We use these `target_branch_sha` and `source_branch_sha` attributes to force these to the intended values. But the reader methods were always looking up to the target/source branch head instead of check if these values was previously set, this MR applies a memoization pattern to both of them. ## Are there points in the code the reviewer needs to double check? This [commit](https://gitlab.com/gitlab-org/gitlab-ce/commit/6ce25e7b4caa9e94de74378729178c7060d640b2) introduced this bug in the importer. ## What are the relevant issue numbers? gitlab-org/gitlab-ce#20385 ## Does this MR meet the acceptance criteria? - [X] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [X] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~ - [X] ~~API support added~~ - Tests - [X] Added for this feature/bug - [ ] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [ ] Branch has no merge conflicts with `master` (if you do - rebase it please) - [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) /cc @akitaonrails @DouweM See merge request !5573
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/merge_request.rb4
-rw-r--r--spec/models/merge_request_spec.rb18
3 files changed, 18 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index b54d9bbe733..39b77460deb 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -43,6 +43,7 @@ v 8.11.0 (unreleased)
- Sensible state specific default sort order for issues and merge requests !5453 (tomb0y)
v 8.10.3 (unreleased)
+ - Fix importer for GitHub Pull Requests when a branch was removed
- Fix hooks missing on imported GitLab projects
- Properly abort a merge when merge conflicts occur
- Ignore invalid IPs in X-Forwarded-For when trusted proxies are configured.
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 471e32f3b60..f1b9c1d6feb 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -238,11 +238,11 @@ class MergeRequest < ActiveRecord::Base
end
def target_branch_sha
- target_branch_head.try(:sha)
+ @target_branch_sha || target_branch_head.try(:sha)
end
def source_branch_sha
- source_branch_head.try(:sha)
+ @source_branch_sha || source_branch_head.try(:sha)
end
def diff_refs
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index c8ad7ab3e7f..a0e3c26e542 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -65,11 +65,11 @@ describe MergeRequest, models: true do
end
describe '#target_branch_sha' do
- context 'when the target branch does not exist anymore' do
- let(:project) { create(:project) }
+ let(:project) { create(:project) }
- subject { create(:merge_request, source_project: project, target_project: project) }
+ subject { create(:merge_request, source_project: project, target_project: project) }
+ context 'when the target branch does not exist' do
before do
project.repository.raw_repository.delete_branch(subject.target_branch)
end
@@ -78,6 +78,12 @@ describe MergeRequest, models: true do
expect(subject.target_branch_sha).to be_nil
end
end
+
+ it 'returns memoized value' do
+ subject.target_branch_sha = '8ffb3c15a5475e59ae909384297fede4badcb4c7'
+
+ expect(subject.target_branch_sha).to eq '8ffb3c15a5475e59ae909384297fede4badcb4c7'
+ end
end
describe '#source_branch_sha' do
@@ -103,6 +109,12 @@ describe MergeRequest, models: true do
expect(subject.source_branch_sha).to be_nil
end
end
+
+ it 'returns memoized value' do
+ subject.source_branch_sha = '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
+
+ expect(subject.source_branch_sha).to eq '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
+ end
end
describe '#to_reference' do