Commit 737f322e authored by Douwe Maan's avatar Douwe Maan

Import GitHub, Bitbucket or GitLab.com projects owned by authenticated user into current namespace.

parent 33a8f53f
...@@ -48,6 +48,7 @@ v 7.10.0 (unreleased) ...@@ -48,6 +48,7 @@ v 7.10.0 (unreleased)
- Prevent note form from being cleared when submitting failed. - Prevent note form from being cleared when submitting failed.
- Improve file icons rendering on tree (Sullivan Sénéchal) - Improve file icons rendering on tree (Sullivan Sénéchal)
- API: Add pagination to project events - API: Add pagination to project events
- Import GitHub, Bitbucket or GitLab.com projects owned by authenticated user into current namespace.
v 7.9.0 v 7.9.0
- Send EmailsOnPush email when branch or tag is created or deleted. - Send EmailsOnPush email when branch or tag is created or deleted.
......
...@@ -36,9 +36,12 @@ class Import::BitbucketController < Import::BaseController ...@@ -36,9 +36,12 @@ class Import::BitbucketController < Import::BaseController
def create def create
@repo_id = params[:repo_id] || "" @repo_id = params[:repo_id] || ""
repo = client.project(@repo_id.gsub("___", "/")) repo = client.project(@repo_id.gsub("___", "/"))
@target_namespace = params[:new_namespace].presence || repo["owner"]
@project_name = repo["slug"] @project_name = repo["slug"]
repo_owner = repo["owner"]
repo_owner = current_user.username if repo_owner == client.user["user"]["username"]
@target_namespace = params[:new_namespace].presence || repo_owner
namespace = get_or_create_namespace || (render and return) namespace = get_or_create_namespace || (render and return)
unless Gitlab::BitbucketImport::KeyAdder.new(repo, current_user).execute unless Gitlab::BitbucketImport::KeyAdder.new(repo, current_user).execute
......
...@@ -31,9 +31,12 @@ class Import::GithubController < Import::BaseController ...@@ -31,9 +31,12 @@ class Import::GithubController < Import::BaseController
def create def create
@repo_id = params[:repo_id].to_i @repo_id = params[:repo_id].to_i
repo = client.repo(@repo_id) repo = client.repo(@repo_id)
@target_namespace = params[:new_namespace].presence || repo.owner.login
@project_name = repo.name @project_name = repo.name
repo_owner = repo.owner.login
repo_owner = current_user.username if repo_owner == client.user.login
@target_namespace = params[:new_namespace].presence || repo_owner
namespace = get_or_create_namespace || (render and return) namespace = get_or_create_namespace || (render and return)
@project = Gitlab::GithubImport::ProjectCreator.new(repo, namespace, current_user).execute @project = Gitlab::GithubImport::ProjectCreator.new(repo, namespace, current_user).execute
......
...@@ -28,9 +28,12 @@ class Import::GitlabController < Import::BaseController ...@@ -28,9 +28,12 @@ class Import::GitlabController < Import::BaseController
def create def create
@repo_id = params[:repo_id].to_i @repo_id = params[:repo_id].to_i
repo = client.project(@repo_id) repo = client.project(@repo_id)
@target_namespace = params[:new_namespace].presence || repo["namespace"]["path"]
@project_name = repo["name"] @project_name = repo["name"]
repo_owner = repo["namespace"]["path"]
repo_owner = current_user.username if repo_owner == client.user["username"]
@target_namespace = params[:new_namespace].presence || repo_owner
namespace = get_or_create_namespace || (render and return) namespace = get_or_create_namespace || (render and return)
@project = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, current_user).execute @project = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, current_user).execute
......
...@@ -28,6 +28,10 @@ module Gitlab ...@@ -28,6 +28,10 @@ module Gitlab
client.auth_code.get_token(code, redirect_uri: redirect_uri).token client.auth_code.get_token(code, redirect_uri: redirect_uri).token
end end
def user
api.get("/api/v3/user").parsed
end
def issues(project_identifier) def issues(project_identifier)
lazy_page_iterator(PER_PAGE) do |page| lazy_page_iterator(PER_PAGE) do |page|
api.get("/api/v3/projects/#{project_identifier}/issues?per_page=#{PER_PAGE}&page=#{page}").parsed api.get("/api/v3/projects/#{project_identifier}/issues?per_page=#{PER_PAGE}&page=#{page}").parsed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment