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
Léo-Paul Géneau
gitlab-ce
Commits
e001bd5e
Commit
e001bd5e
authored
May 09, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import PRs where branch names were reused across PRs
parent
7e1f14e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
10 deletions
+50
-10
lib/gitlab/github_import/pull_request_formatter.rb
lib/gitlab/github_import/pull_request_formatter.rb
+24
-4
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
+26
-6
No files found.
lib/gitlab/github_import/pull_request_formatter.rb
View file @
e001bd5e
...
...
@@ -30,11 +30,19 @@ module Gitlab
end
def
source_branch_exists?
source_project
.
repository
.
branch_
names
.
include?
(
source_branch
)
source_project
.
repository
.
branch_
exists?
(
source_ref
)
end
def
source_branch
raw_data
.
head
.
ref
@source_branch
||=
if
source_branch_exists?
source_ref
else
"
#{
source_ref
}
-
#{
short_id
(
source_sha
)
}
"
end
end
def
short_id
(
sha
,
length
=
7
)
sha
.
to_s
[
0
..
length
]
end
def
source_sha
...
...
@@ -42,11 +50,15 @@ module Gitlab
end
def
target_branch_exists?
target_project
.
repository
.
branch_
names
.
include?
(
target_branch
)
target_project
.
repository
.
branch_
exists?
(
target_ref
)
end
def
target_branch
raw_data
.
base
.
ref
@target_branch
||=
if
target_branch_exists?
target_ref
else
"
#{
target_ref
}
-
#{
short_id
(
target_sha
)
}
"
end
end
def
target_sha
...
...
@@ -99,6 +111,10 @@ module Gitlab
raw_data
.
head
.
repo
end
def
source_ref
raw_data
.
head
.
ref
end
def
target_project
project
end
...
...
@@ -107,6 +123,10 @@ module Gitlab
raw_data
.
base
.
repo
end
def
target_ref
raw_data
.
base
.
ref
end
def
state
@state
||=
case
true
when
raw_data
.
state
==
'closed'
&&
raw_data
.
merged_at
.
present?
...
...
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
View file @
e001bd5e
...
...
@@ -164,10 +164,20 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
describe
'#source_branch'
do
let
(
:raw_data
)
{
double
(
base_data
)
}
context
'when source branch exists'
do
let
(
:raw_data
)
{
double
(
base_data
)
}
it
'returns head ref'
do
expect
(
pull_request
.
source_branch
).
to
eq
'feature'
it
'returns head ref'
do
expect
(
pull_request
.
source_branch
).
to
eq
'feature'
end
end
context
'when source branch does not exist'
do
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
head:
double
(
ref:
'removed-branch'
,
sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
)))
}
it
'returns head ref'
do
expect
(
pull_request
.
source_branch
).
to
eq
'removed-branch-2e5d3239'
end
end
end
...
...
@@ -198,10 +208,20 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
describe
'#target_branch'
do
let
(
:raw_data
)
{
double
(
base_data
)
}
context
'when target branch exists'
do
let
(
:raw_data
)
{
double
(
base_data
)
}
it
'returns base ref'
do
expect
(
pull_request
.
target_branch
).
to
eq
'master'
it
'returns base ref'
do
expect
(
pull_request
.
target_branch
).
to
eq
'master'
end
end
context
'when target branch does not exist'
do
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
base:
double
(
ref:
'removed-branch'
,
sha:
'8ffb3c15a5475e59ae909384297fede4badcb4c7'
)))
}
it
'returns head ref'
do
expect
(
pull_request
.
target_branch
).
to
eq
'removed-branch-8ffb3c15'
end
end
end
...
...
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