Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
7e1f14e2
Commit
7e1f14e2
authored
Apr 26, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preserve commits/diff/comments for PRs that were merged on GitHub
parent
3b508675
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
9 deletions
+50
-9
app/models/merge_request.rb
app/models/merge_request.rb
+9
-1
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+20
-6
lib/gitlab/github_import/pull_request_formatter.rb
lib/gitlab/github_import/pull_request_formatter.rb
+2
-0
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
+6
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+13
-2
No files found.
app/models/merge_request.rb
View file @
7e1f14e2
...
...
@@ -26,6 +26,10 @@ class MergeRequest < ActiveRecord::Base
# when creating new merge request
attr_accessor
:can_be_created
,
:compare_commits
,
:compare
# Temporary fields to store target_sha, and base_sha to
# compare when importing pull requests from GitHub
attr_accessor
:base_target_sha
,
:head_source_sha
state_machine
:state
,
initial: :opened
do
event
:close
do
transition
[
:reopened
,
:opened
]
=>
:closed
...
...
@@ -490,10 +494,14 @@ class MergeRequest < ActiveRecord::Base
end
def
target_sha
@target_sha
||=
target_project
.
repository
.
commit
(
target_branch
).
try
(
:sha
)
return
@base_target_sha
if
defined?
(
@base_target_sha
)
target_project
.
repository
.
commit
(
target_branch
).
try
(
:sha
)
end
def
source_sha
return
@head_source_sha
if
defined?
(
@head_source_sha
)
last_commit
.
try
(
:sha
)
||
source_tip
.
try
(
:sha
)
end
...
...
app/models/merge_request_diff.rb
View file @
7e1f14e2
...
...
@@ -6,7 +6,7 @@ class MergeRequestDiff < ActiveRecord::Base
belongs_to
:merge_request
delegate
:target_branch
,
:source_branch
,
to: :merge_request
,
prefix:
nil
delegate
:
head_source_sha
,
:
target_branch
,
:source_branch
,
to: :merge_request
,
prefix:
nil
state_machine
:state
,
initial: :empty
do
state
:collected
...
...
@@ -38,8 +38,8 @@ class MergeRequestDiff < ActiveRecord::Base
@diffs_no_whitespace
||=
begin
compare
=
Gitlab
::
Git
::
Compare
.
new
(
self
.
repository
.
raw_repository
,
self
.
target_branch
,
self
.
source_sha
,
self
.
base
,
self
.
head
,
)
compare
.
diffs
(
options
)
end
...
...
@@ -144,7 +144,7 @@ class MergeRequestDiff < ActiveRecord::Base
self
.
st_diffs
=
new_diffs
self
.
base_commit_sha
=
self
.
repository
.
merge_base
(
self
.
source_sha
,
self
.
target_branch
)
self
.
base_commit_sha
=
self
.
repository
.
merge_base
(
self
.
head
,
self
.
base
)
self
.
save
end
...
...
@@ -160,10 +160,24 @@ class MergeRequestDiff < ActiveRecord::Base
end
def
source_sha
return
head_source_sha
if
head_source_sha
.
present?
source_commit
=
merge_request
.
source_project
.
commit
(
source_branch
)
source_commit
.
try
(
:sha
)
end
def
target_sha
merge_request
.
target_sha
end
def
base
self
.
target_sha
||
self
.
target_branch
end
def
head
self
.
source_sha
end
def
compare
@compare
||=
begin
...
...
@@ -172,8 +186,8 @@ class MergeRequestDiff < ActiveRecord::Base
Gitlab
::
Git
::
Compare
.
new
(
self
.
repository
.
raw_repository
,
self
.
target_branch
,
self
.
source_sha
self
.
base
,
self
.
head
)
end
end
...
...
lib/gitlab/github_import/pull_request_formatter.rb
View file @
7e1f14e2
...
...
@@ -8,8 +8,10 @@ module Gitlab
description:
description
,
source_project:
source_project
,
source_branch:
source_branch
,
head_source_sha:
source_sha
,
target_project:
target_project
,
target_branch:
target_branch
,
base_target_sha:
target_sha
,
state:
state
,
milestone:
milestone
,
author_id:
author_id
,
...
...
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
View file @
7e1f14e2
...
...
@@ -41,8 +41,10 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
description:
"*Created by: octocat*
\n\n
Please pull these awesome changes"
,
source_project:
project
,
source_branch:
'feature'
,
head_source_sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
,
target_project:
project
,
target_branch:
'master'
,
base_target_sha:
'8ffb3c15a5475e59ae909384297fede4badcb4c7'
,
state:
'opened'
,
milestone:
nil
,
author_id:
project
.
creator_id
,
...
...
@@ -66,8 +68,10 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
description:
"*Created by: octocat*
\n\n
Please pull these awesome changes"
,
source_project:
project
,
source_branch:
'feature'
,
head_source_sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
,
target_project:
project
,
target_branch:
'master'
,
base_target_sha:
'8ffb3c15a5475e59ae909384297fede4badcb4c7'
,
state:
'closed'
,
milestone:
nil
,
author_id:
project
.
creator_id
,
...
...
@@ -91,8 +95,10 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
description:
"*Created by: octocat*
\n\n
Please pull these awesome changes"
,
source_project:
project
,
source_branch:
'feature'
,
head_source_sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
,
target_project:
project
,
target_branch:
'master'
,
base_target_sha:
'8ffb3c15a5475e59ae909384297fede4badcb4c7'
,
state:
'merged'
,
milestone:
nil
,
author_id:
project
.
creator_id
,
...
...
spec/models/merge_request_spec.rb
View file @
7e1f14e2
...
...
@@ -64,7 +64,13 @@ describe MergeRequest, models: true do
describe
'#target_sha'
do
context
'when the target branch does not exist anymore'
do
subject
{
create
(
:merge_request
).
tap
{
|
mr
|
mr
.
update_attribute
(
:target_branch
,
'deleted'
)
}
}
let
(
:project
)
{
create
(
:project
)
}
subject
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
before
do
project
.
repository
.
raw_repository
.
delete_branch
(
subject
.
target_branch
)
end
it
'returns nil'
do
expect
(
subject
.
target_sha
).
to
be_nil
...
...
@@ -289,7 +295,12 @@ describe MergeRequest, models: true do
let
(
:fork_project
)
{
create
(
:project
,
forked_from_project:
project
)
}
context
'when the target branch does not exist anymore'
do
subject
{
create
(
:merge_request
).
tap
{
|
mr
|
mr
.
update_attribute
(
:target_branch
,
'deleted'
)
}
}
subject
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
before
do
project
.
repository
.
raw_repository
.
delete_branch
(
subject
.
target_branch
)
subject
.
reload
end
it
'does not crash'
do
expect
{
subject
.
diverged_commits_count
}.
not_to
raise_error
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment