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
6979b3af
Commit
6979b3af
authored
Feb 18, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete deploy key from Bitbucket after importing.
parent
f2b37de5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
24 deletions
+56
-24
app/workers/repository_import_worker.rb
app/workers/repository_import_worker.rb
+18
-18
lib/gitlab/bitbucket_import/client.rb
lib/gitlab/bitbucket_import/client.rb
+15
-4
lib/gitlab/bitbucket_import/key_adder.rb
lib/gitlab/bitbucket_import/key_adder.rb
+0
-2
lib/gitlab/bitbucket_import/key_deleter.rb
lib/gitlab/bitbucket_import/key_deleter.rb
+23
-0
No files found.
app/workers/repository_import_worker.rb
View file @
6979b3af
...
@@ -6,27 +6,27 @@ class RepositoryImportWorker
...
@@ -6,27 +6,27 @@ class RepositoryImportWorker
def
perform
(
project_id
)
def
perform
(
project_id
)
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
result
=
gitlab_shell
.
send
(
:import_repository
,
import_result
=
gitlab_shell
.
send
(
:import_repository
,
project
.
path_with_namespace
,
project
.
path_with_namespace
,
project
.
import_url
)
project
.
import_url
)
return
project
.
import_fail
unless
import_result
result_of_data_import
=
if
project
.
import_type
==
'github'
data_import_result
=
if
project
.
import_type
==
'github'
Gitlab
::
GithubImport
::
Importer
.
new
(
project
).
execute
Gitlab
::
GithubImport
::
Importer
.
new
(
project
).
execute
elsif
project
.
import_type
==
'gitlab'
elsif
project
.
import_type
==
'gitlab'
Gitlab
::
GitlabImport
::
Importer
.
new
(
project
).
execute
Gitlab
::
GitlabImport
::
Importer
.
new
(
project
).
execute
elsif
project
.
import_type
==
'bitbucket'
elsif
project
.
import_type
==
'bitbucket'
Gitlab
::
BitbucketImport
::
Importer
.
new
(
project
).
execute
Gitlab
::
BitbucketImport
::
Importer
.
new
(
project
).
execute
else
else
true
true
end
end
return
project
.
import_fail
unless
data_import_result
if
result
&&
result_of_data_import
project
.
import_finish
project
.
import_finish
project
.
save
project
.
save
project
.
satellite
.
create
unless
project
.
satellite
.
exists?
project
.
satellite
.
create
unless
project
.
satellite
.
exists?
project
.
update_repository_size
project
.
update_repository_size
Gitlab
::
BitbucketImport
::
KeyDeleter
.
new
(
project
).
execute
if
project
.
import_type
==
'bitbucket'
else
project
.
import_fail
end
end
end
end
end
lib/gitlab/bitbucket_import/client.rb
View file @
6979b3af
...
@@ -61,17 +61,28 @@ module Gitlab
...
@@ -61,17 +61,28 @@ module Gitlab
JSON
.
parse
(
api
.
get
(
"/api/1.0/repositories/
#{
project_identifier
}
"
).
body
)
JSON
.
parse
(
api
.
get
(
"/api/1.0/repositories/
#{
project_identifier
}
"
).
body
)
end
end
def
deploy_key
(
project_identifier
)
def
find_deploy_key
(
project_identifier
,
key
)
JSON
.
parse
(
api
.
get
(
"/api/1.0/repositories/
#{
project_identifier
}
/deploy-keys"
).
body
).
find
{
|
key
|
key
[
"label"
]
=~
/GitLab/
}
JSON
.
parse
(
api
.
get
(
"/api/1.0/repositories/
#{
project_identifier
}
/deploy-keys"
).
body
).
find
{
|
deploy_key
|
deploy_key
[
"key"
].
chomp
==
key
.
chomp
}
end
end
def
add_deploy_key
(
project_identifier
,
key
)
def
add_deploy_key
(
project_identifier
,
key
)
deploy_key
=
find_deploy_key
(
project_identifier
,
key
)
return
if
deploy_key
JSON
.
parse
(
api
.
post
(
"/api/1.0/repositories/
#{
project_identifier
}
/deploy-keys"
,
key:
key
,
label:
"GitLab import key"
).
body
)
JSON
.
parse
(
api
.
post
(
"/api/1.0/repositories/
#{
project_identifier
}
/deploy-keys"
,
key:
key
,
label:
"GitLab import key"
).
body
)
end
end
def
delete_deploy_key
(
project_identifier
,
key
)
deploy_key
=
find_deploy_key
(
project_identifier
,
key
)
return
unless
deploy_key
api
.
delete
(
"/api/1.0/repositories/
#{
project_identifier
}
/deploy-keys/
#{
deploy_key
[
"pk"
]
}
"
).
code
==
"204"
end
def
projects
def
projects
JSON
.
parse
(
api
.
get
(
"/api/1.0/user/repositories"
).
body
).
JSON
.
parse
(
api
.
get
(
"/api/1.0/user/repositories"
).
body
).
select
{
|
repo
|
repo
[
"scm"
]
==
"git"
}
select
{
|
repo
|
repo
[
"scm"
]
==
"git"
}
end
end
private
private
...
...
lib/gitlab/bitbucket_import/key_adder.rb
View file @
6979b3af
...
@@ -12,8 +12,6 @@ module Gitlab
...
@@ -12,8 +12,6 @@ module Gitlab
return
false
unless
BitbucketImport
.
public_key
.
present?
return
false
unless
BitbucketImport
.
public_key
.
present?
project_identifier
=
"
#{
repo
[
"owner"
]
}
/
#{
repo
[
"slug"
]
}
"
project_identifier
=
"
#{
repo
[
"owner"
]
}
/
#{
repo
[
"slug"
]
}
"
return
true
if
client
.
deploy_key
(
project_identifier
)
client
.
add_deploy_key
(
project_identifier
,
BitbucketImport
.
public_key
)
client
.
add_deploy_key
(
project_identifier
,
BitbucketImport
.
public_key
)
true
true
...
...
lib/gitlab/bitbucket_import/key_deleter.rb
0 → 100644
View file @
6979b3af
module
Gitlab
module
BitbucketImport
class
KeyDeleter
attr_reader
:project
,
:current_user
,
:client
def
initialize
(
project
)
@project
=
project
@current_user
=
project
.
creator
@client
=
Client
.
new
(
current_user
.
bitbucket_access_token
,
current_user
.
bitbucket_access_token_secret
)
end
def
execute
return
false
unless
BitbucketImport
.
public_key
.
present?
client
.
delete_deploy_key
(
project
.
import_source
,
BitbucketImport
.
public_key
)
true
rescue
false
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