diff options
Diffstat (limited to 'lib/gitlab/gitlab_import')
-rw-r--r-- | lib/gitlab/gitlab_import/client.rb | 82 | ||||
-rw-r--r-- | lib/gitlab/gitlab_import/importer.rb | 50 | ||||
-rw-r--r-- | lib/gitlab/gitlab_import/project_creator.rb | 26 |
3 files changed, 0 insertions, 158 deletions
diff --git a/lib/gitlab/gitlab_import/client.rb b/lib/gitlab/gitlab_import/client.rb deleted file mode 100644 index 9c00896c913..00000000000 --- a/lib/gitlab/gitlab_import/client.rb +++ /dev/null @@ -1,82 +0,0 @@ -module Gitlab - module GitlabImport - class Client - attr_reader :client, :api - - PER_PAGE = 100 - - def initialize(access_token) - @client = ::OAuth2::Client.new( - config.app_id, - config.app_secret, - gitlab_options - ) - - if access_token - @api = OAuth2::AccessToken.from_hash(@client, access_token: access_token) - end - end - - def authorize_url(redirect_uri) - client.auth_code.authorize_url({ - redirect_uri: redirect_uri, - scope: "api" - }) - end - - def get_token(code, redirect_uri) - client.auth_code.get_token(code, redirect_uri: redirect_uri).token - end - - def user - api.get("/api/v3/user").parsed - end - - def issues(project_identifier) - lazy_page_iterator(PER_PAGE) do |page| - api.get("/api/v3/projects/#{project_identifier}/issues?per_page=#{PER_PAGE}&page=#{page}").parsed - end - end - - def issue_comments(project_identifier, issue_id) - lazy_page_iterator(PER_PAGE) do |page| - api.get("/api/v3/projects/#{project_identifier}/issues/#{issue_id}/notes?per_page=#{PER_PAGE}&page=#{page}").parsed - end - end - - def project(id) - api.get("/api/v3/projects/#{id}").parsed - end - - def projects - lazy_page_iterator(PER_PAGE) do |page| - api.get("/api/v3/projects?per_page=#{PER_PAGE}&page=#{page}").parsed - end - end - - private - - def lazy_page_iterator(per_page) - Enumerator.new do |y| - page = 1 - loop do - items = yield(page) - items.each do |item| - y << item - end - break if items.empty? || items.size < per_page - page += 1 - end - end - end - - def config - Gitlab.config.omniauth.providers.find{|provider| provider.name == "gitlab"} - end - - def gitlab_options - OmniAuth::Strategies::GitLab.default_options[:client_options].symbolize_keys - end - end - end -end diff --git a/lib/gitlab/gitlab_import/importer.rb b/lib/gitlab/gitlab_import/importer.rb deleted file mode 100644 index c5304a0699b..00000000000 --- a/lib/gitlab/gitlab_import/importer.rb +++ /dev/null @@ -1,50 +0,0 @@ -module Gitlab - module GitlabImport - class Importer - attr_reader :project, :client - - def initialize(project) - @project = project - @client = Client.new(project.creator.gitlab_access_token) - @formatter = Gitlab::ImportFormatter.new - end - - def execute - project_identifier = URI.encode(project.import_source, '/') - - #Issues && Comments - issues = client.issues(project_identifier) - - issues.each do |issue| - body = @formatter.author_line(issue["author"]["name"], issue["description"]) - - comments = client.issue_comments(project_identifier, issue["id"]) - - if comments.any? - body += @formatter.comments_header - end - - comments.each do |comment| - body += @formatter.comment(comment["author"]["name"], comment["created_at"], comment["body"]) - end - - project.issues.create!( - description: body, - title: issue["title"], - state: issue["state"], - author_id: gl_user_id(project, issue["author"]["id"]) - ) - end - - true - end - - private - - def gl_user_id(project, gitlab_id) - user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'gitlab'", gitlab_id.to_s) - (user && user.id) || project.creator_id - end - end - end -end diff --git a/lib/gitlab/gitlab_import/project_creator.rb b/lib/gitlab/gitlab_import/project_creator.rb deleted file mode 100644 index f0d7141bf56..00000000000 --- a/lib/gitlab/gitlab_import/project_creator.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Gitlab - module GitlabImport - class ProjectCreator - attr_reader :repo, :namespace, :current_user - - def initialize(repo, namespace, current_user) - @repo = repo - @namespace = namespace - @current_user = current_user - end - - def execute - ::Projects::CreateService.new(current_user, - name: repo["name"], - path: repo["path"], - description: repo["description"], - namespace_id: namespace.id, - visibility_level: repo["visibility_level"], - import_type: "gitlab", - import_source: repo["path_with_namespace"], - import_url: repo["http_url_to_repo"].sub("://", "://oauth2:#{current_user.gitlab_access_token}@") - ).execute - end - end - end -end |