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
Boxiang Sun
gitlab-ce
Commits
046a5e39
Commit
046a5e39
authored
Jun 25, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More work towards supporting Bitbucket Server
parent
c9deb7ce
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
33 additions
and
165 deletions
+33
-165
app/controllers/import/bitbucket_server_controller.rb
app/controllers/import/bitbucket_server_controller.rb
+2
-2
lib/bitbucket_server/client.rb
lib/bitbucket_server/client.rb
+2
-2
lib/bitbucket_server/connection.rb
lib/bitbucket_server/connection.rb
+1
-1
lib/bitbucket_server/representation/issue.rb
lib/bitbucket_server/representation/issue.rb
+0
-53
lib/bitbucket_server/representation/pull_request.rb
lib/bitbucket_server/representation/pull_request.rb
+9
-9
lib/bitbucket_server/representation/repo.rb
lib/bitbucket_server/representation/repo.rb
+2
-10
lib/gitlab/bitbucket_server_import/importer.rb
lib/gitlab/bitbucket_server_import/importer.rb
+5
-76
lib/gitlab/bitbucket_server_import/project_creator.rb
lib/gitlab/bitbucket_server_import/project_creator.rb
+12
-12
No files found.
app/controllers/import/bitbucket_server_controller.rb
View file @
046a5e39
...
...
@@ -20,7 +20,7 @@ class Import::BitbucketServerController < Import::BaseController
target_namespace
=
find_or_create_namespace
(
namespace_path
,
current_user
)
if
current_user
.
can?
(
:create_projects
,
target_namespace
)
project
=
Gitlab
::
Bitbucket
Import
::
ProjectCreator
.
new
(
repo
,
project_name
,
target_namespace
,
current_user
,
credentials
).
execute
project
=
Gitlab
::
Bitbucket
ServerImport
::
ProjectCreator
.
new
(
project_slug
,
repo_slug
,
repo
,
project_name
,
target_namespace
,
current_user
,
credentials
).
execute
if
project
.
persisted?
render
json:
ProjectSerializer
.
new
.
represent
(
project
)
...
...
@@ -86,7 +86,7 @@ class Import::BitbucketServerController < Import::BaseController
{
base_uri:
session
[
bitbucket_server_url_key
],
username:
session
[
bitbucket_server_username_key
],
p
ersonal_access_token
:
session
[
personal_access_token_key
]
p
assword
:
session
[
personal_access_token_key
]
}
end
end
lib/bitbucket_server/client.rb
View file @
046a5e39
...
...
@@ -16,8 +16,8 @@ module BitbucketServer
get_collection
(
path
,
:comment
)
end
def
pull_requests
(
repo
)
path
=
"/
repositories/
#{
repo
}
/pull
requests?state=ALL"
def
pull_requests
(
project_key
,
repository_slug
)
path
=
"/
projects/
#{
project
}
/repos/
#{
repo
}
/pull-
requests?state=ALL"
get_collection
(
path
,
:pull_request
)
end
...
...
lib/bitbucket_server/connection.rb
View file @
046a5e39
...
...
@@ -8,7 +8,7 @@ module BitbucketServer
@api_version
=
options
.
fetch
(
:api_version
,
DEFAULT_API_VERSION
)
@base_uri
=
options
[
:base_uri
]
@username
=
options
[
:username
]
@token
=
options
[
:p
ersonal_access_token
]
@token
=
options
[
:p
assword
]
end
def
get
(
path
,
extra_query
=
{})
...
...
lib/bitbucket_server/representation/issue.rb
deleted
100644 → 0
View file @
c9deb7ce
module
Bitbucket
module
Representation
class
Issue
<
Representation
::
Base
CLOSED_STATUS
=
%w(resolved invalid duplicate wontfix closed)
.
freeze
def
iid
raw
[
'id'
]
end
def
kind
raw
[
'kind'
]
end
def
author
raw
.
dig
(
'reporter'
,
'username'
)
end
def
description
raw
.
fetch
(
'content'
,
{}).
fetch
(
'raw'
,
nil
)
end
def
state
closed?
?
'closed'
:
'opened'
end
def
title
raw
[
'title'
]
end
def
milestone
raw
[
'milestone'
][
'name'
]
if
raw
[
'milestone'
].
present?
end
def
created_at
raw
[
'created_on'
]
end
def
updated_at
raw
[
'edited_on'
]
end
def
to_s
iid
end
private
def
closed?
CLOSED_STATUS
.
include?
(
raw
[
'state'
])
end
end
end
end
lib/bitbucket_server/representation/pull_request.rb
View file @
046a5e39
...
...
@@ -2,7 +2,7 @@ module BitbucketServer
module
Representation
class
PullRequest
<
Representation
::
Base
def
author
raw
.
fetch
(
'author'
,
{}).
fetch
(
'user
name'
,
nil
)
raw
.
fetch
(
'author'
,
{}).
fetch
(
'user
'
,
{}).
fetch
(
'name'
)
end
def
description
...
...
@@ -24,11 +24,11 @@ module BitbucketServer
end
def
created_at
raw
[
'created
_on
'
]
raw
[
'created
Date
'
]
end
def
updated_at
raw
[
'updated
_on
'
]
raw
[
'updated
Date
'
]
end
def
title
...
...
@@ -36,29 +36,29 @@ module BitbucketServer
end
def
source_branch_name
source_branch
.
fetch
(
'branch'
,
{}).
fetch
(
'name'
,
nil
)
source_branch
[
'id'
]
end
def
source_branch_sha
source_branch
.
fetch
(
'commit'
,
{}).
fetch
(
'hash'
,
nil
)
# XXX Not implemented?
end
def
target_branch_name
target_branch
.
fetch
(
'branch'
,
{}).
fetch
(
'name'
,
nil
)
target_branch
[
'id'
]
end
def
target_branch_sha
target_branch
.
fetch
(
'commit'
,
{}).
fetch
(
'hash'
,
nil
)
# XXX Not implemented?
end
private
def
source_branch
raw
[
'
source'
]
raw
[
'
fromRef'
]
||
{}
end
def
target_branch
raw
[
'
destination'
]
raw
[
'
toRef'
]
||
{}
end
end
end
...
...
lib/bitbucket_server/representation/repo.rb
View file @
046a5e39
...
...
@@ -15,16 +15,8 @@ module BitbucketServer
raw
[
'slug'
]
end
def
clone_url
(
token
=
nil
)
url
=
raw
[
'links'
][
'clone'
].
find
{
|
link
|
link
[
'name'
].
starts_with?
(
'http'
)
}.
fetch
(
'href'
)
if
token
.
present?
clone_url
=
URI
.
parse
(
url
)
clone_url
.
user
=
"x-token-auth:
#{
token
}
"
clone_url
.
to_s
else
url
end
def
clone_url
raw
[
'links'
][
'clone'
].
find
{
|
link
|
link
[
'name'
].
starts_with?
(
'http'
)
}.
fetch
(
'href'
)
end
def
description
...
...
lib/gitlab/bitbucket_server_import/importer.rb
View file @
046a5e39
...
...
@@ -8,10 +8,12 @@ module Gitlab
{
title:
'proposal'
,
color:
'#69D100'
},
{
title:
'task'
,
color:
'#7F8C8D'
}].
freeze
attr_reader
:project
,
:client
,
:errors
,
:users
attr_reader
:project
_key
,
:repository_slug
,
:client
,
:errors
,
:users
def
initialize
(
project
)
@project
=
project
@project_key
=
project
.
import_data
.
data
[
'project_key'
]
@repository_slug
=
project
.
import_data
.
data
[
'repo_slug'
]
@client
=
BitbucketServer
::
Client
.
new
(
project
.
import_data
.
credentials
)
@formatter
=
Gitlab
::
ImportFormatter
.
new
@labels
=
{}
...
...
@@ -20,7 +22,6 @@ module Gitlab
end
def
execute
import_issues
import_pull_requests
handle_errors
...
...
@@ -49,7 +50,7 @@ module Gitlab
users
[
username
]
=
User
.
select
(
:id
)
.
joins
(
:identities
)
.
find_by
(
"identities.extern_uid = ? AND identities.provider = 'bitbucket'"
,
username
)
.
find_by
(
"identities.extern_uid = ? AND identities.provider = 'bitbucket
_server
'"
,
username
)
.
try
(
:id
)
end
...
...
@@ -57,80 +58,8 @@ module Gitlab
@repo
||=
client
.
repo
(
project
.
import_source
)
end
def
import_issues
return
unless
repo
.
issues_enabled?
create_labels
client
.
issues
(
repo
).
each
do
|
issue
|
begin
description
=
''
description
+=
@formatter
.
author_line
(
issue
.
author
)
unless
find_user_id
(
issue
.
author
)
description
+=
issue
.
description
label_name
=
issue
.
kind
milestone
=
issue
.
milestone
?
project
.
milestones
.
find_or_create_by
(
title:
issue
.
milestone
)
:
nil
gitlab_issue
=
project
.
issues
.
create!
(
iid:
issue
.
iid
,
title:
issue
.
title
,
description:
description
,
state:
issue
.
state
,
author_id:
gitlab_user_id
(
project
,
issue
.
author
),
milestone:
milestone
,
created_at:
issue
.
created_at
,
updated_at:
issue
.
updated_at
)
gitlab_issue
.
labels
<<
@labels
[
label_name
]
import_issue_comments
(
issue
,
gitlab_issue
)
if
gitlab_issue
.
persisted?
rescue
StandardError
=>
e
errors
<<
{
type: :issue
,
iid:
issue
.
iid
,
errors:
e
.
message
}
end
end
end
def
import_issue_comments
(
issue
,
gitlab_issue
)
client
.
issue_comments
(
repo
,
issue
.
iid
).
each
do
|
comment
|
# The note can be blank for issue service messages like "Changed title: ..."
# We would like to import those comments as well but there is no any
# specific parameter that would allow to process them, it's just an empty comment.
# To prevent our importer from just crashing or from creating useless empty comments
# we do this check.
next
unless
comment
.
note
.
present?
note
=
''
note
+=
@formatter
.
author_line
(
comment
.
author
)
unless
find_user_id
(
comment
.
author
)
note
+=
comment
.
note
begin
gitlab_issue
.
notes
.
create!
(
project:
project
,
note:
note
,
author_id:
gitlab_user_id
(
project
,
comment
.
author
),
created_at:
comment
.
created_at
,
updated_at:
comment
.
updated_at
)
rescue
StandardError
=>
e
errors
<<
{
type: :issue_comment
,
iid:
issue
.
iid
,
errors:
e
.
message
}
end
end
end
def
create_labels
LABELS
.
each
do
|
label_params
|
label
=
::
Labels
::
CreateService
.
new
(
label_params
).
execute
(
project:
project
)
if
label
.
valid?
@labels
[
label_params
[
:title
]]
=
label
else
raise
"Failed to create label
\"
#{
label_params
[
:title
]
}
\"
for project
\"
#{
project
.
full_name
}
\"
"
end
end
end
def
import_pull_requests
pull_requests
=
client
.
pull_requests
(
repo
)
pull_requests
=
client
.
pull_requests
(
project_key
,
repository_slug
)
pull_requests
.
each
do
|
pull_request
|
begin
...
...
lib/gitlab/bitbucket_server_import/project_creator.rb
View file @
046a5e39
module
Gitlab
module
BitbucketServerImport
class
ProjectCreator
attr_reader
:repo
,
:name
,
:namespace
,
:current_user
,
:session_data
attr_reader
:
project_key
,
:repo_slug
,
:
repo
,
:name
,
:namespace
,
:current_user
,
:session_data
def
initialize
(
repo
,
name
,
namespace
,
current_user
,
session_data
)
def
initialize
(
project_key
,
repo_slug
,
repo
,
name
,
namespace
,
current_user
,
session_data
)
@project_key
=
project_key
@repo_slug
=
repo_slug
@repo
=
repo
@name
=
name
@namespace
=
namespace
...
...
@@ -19,19 +21,17 @@ module Gitlab
description:
repo
.
description
,
namespace_id:
namespace
.
id
,
visibility_level:
repo
.
visibility_level
,
import_type:
'bitbucket'
,
import_type:
'bitbucket
_server
'
,
import_source:
repo
.
full_name
,
import_url:
repo
.
clone_url
(
session_data
[
:token
]),
import_data:
{
credentials:
session_data
},
skip_wiki:
skip_wiki
import_url:
repo
.
clone_url
,
import_data:
{
credentials:
session_data
,
data:
{
project_key:
project_key
,
repo_slug:
repo_slug
},
},
skip_wiki:
true
).
execute
end
private
def
skip_wiki
repo
.
has_wiki?
end
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