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
Jérome Perrin
gitlab-ce
Commits
9b4dc552
Commit
9b4dc552
authored
Apr 22, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import pull requests from GitHub where the target branch was removed
parent
8532dc0d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
12 deletions
+31
-12
lib/gitlab/github_import/importer.rb
lib/gitlab/github_import/importer.rb
+18
-7
lib/gitlab/github_import/pull_request_formatter.rb
lib/gitlab/github_import/pull_request_formatter.rb
+13
-5
No files found.
lib/gitlab/github_import/importer.rb
View file @
9b4dc552
...
@@ -75,10 +75,11 @@ module Gitlab
...
@@ -75,10 +75,11 @@ module Gitlab
.
map
{
|
raw
|
PullRequestFormatter
.
new
(
project
,
raw
)
}
.
map
{
|
raw
|
PullRequestFormatter
.
new
(
project
,
raw
)
}
.
reject
(
&
:cross_project?
)
.
reject
(
&
:cross_project?
)
source_branches_removed
=
pull_requests
.
reject
(
&
:source_branch_exists?
)
source_branches_removed
=
pull_requests
.
reject
(
&
:source_branch_exists?
).
map
{
|
pr
|
[
pr
.
source_branch
,
pr
.
source_sha
]
}
source_branches_removed
.
each
do
|
pull_request
|
target_branches_removed
=
pull_requests
.
reject
(
&
:target_branch_exists?
).
map
{
|
pr
|
[
pr
.
target_branch
,
pr
.
target_sha
]
}
client
.
create_ref
(
repo
,
"refs/heads/
#{
pull_request
.
source_branch
}
"
,
pull_request
.
source_sha
)
branches_removed
=
source_branches_removed
|
target_branches_removed
end
create_refs
(
branches_removed
)
project
.
repository
.
fetch_ref
(
repo_url
,
'+refs/heads/*'
,
'refs/heads/*'
)
project
.
repository
.
fetch_ref
(
repo_url
,
'+refs/heads/*'
,
'refs/heads/*'
)
...
@@ -92,15 +93,25 @@ module Gitlab
...
@@ -92,15 +93,25 @@ module Gitlab
end
end
end
end
source_branches_removed
.
each
do
|
pull_request
|
delete_refs
(
branches_removed
)
client
.
delete_ref
(
repo
,
"heads/
#{
pull_request
.
source_branch
}
"
)
end
true
true
rescue
ActiveRecord
::
RecordInvalid
=>
e
rescue
ActiveRecord
::
RecordInvalid
=>
e
raise
Projects
::
ImportService
::
Error
,
e
.
message
raise
Projects
::
ImportService
::
Error
,
e
.
message
end
end
def
create_refs
(
branches
)
branches
.
each
do
|
branch
|
client
.
create_ref
(
repo
,
"refs/heads/
#{
branch
.
first
}
"
,
branch
.
last
)
end
end
def
delete_refs
(
branches
)
branches
.
each
do
|
branch
|
client
.
delete_ref
(
repo
,
"heads/
#{
branch
.
first
}
"
)
end
end
def
apply_labels
(
number
,
issuable
)
def
apply_labels
(
number
,
issuable
)
issue
=
client
.
issue
(
project
.
import_source
,
number
)
issue
=
client
.
issue
(
project
.
import_source
,
number
)
...
...
lib/gitlab/github_import/pull_request_formatter.rb
View file @
9b4dc552
...
@@ -9,7 +9,7 @@ module Gitlab
...
@@ -9,7 +9,7 @@ module Gitlab
source_project:
source_project
,
source_project:
source_project
,
source_branch:
source_branch
,
source_branch:
source_branch
,
target_project:
target_project
,
target_project:
target_project
,
target_branch:
target_branch
.
name
,
target_branch:
target_branch
,
state:
state
,
state:
state
,
milestone:
milestone
,
milestone:
milestone
,
author_id:
author_id
,
author_id:
author_id
,
...
@@ -43,6 +43,18 @@ module Gitlab
...
@@ -43,6 +43,18 @@ module Gitlab
raw_data
.
head
.
sha
raw_data
.
head
.
sha
end
end
def
target_branch_exists?
target_project
.
repository
.
branch_names
.
include?
(
target_branch
)
end
def
target_branch
raw_data
.
base
.
ref
end
def
target_sha
raw_data
.
base
.
sha
end
private
private
def
assigned?
def
assigned?
...
@@ -93,10 +105,6 @@ module Gitlab
...
@@ -93,10 +105,6 @@ module Gitlab
raw_data
.
base
.
repo
raw_data
.
base
.
repo
end
end
def
target_branch
target_project
.
repository
.
find_branch
(
raw_data
.
base
.
ref
)
end
def
state
def
state
@state
||=
case
true
@state
||=
case
true
when
raw_data
.
state
==
'closed'
&&
raw_data
.
merged_at
.
present?
when
raw_data
.
state
==
'closed'
&&
raw_data
.
merged_at
.
present?
...
...
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