diff options
Diffstat (limited to 'lib/gitlab/github_import')
-rw-r--r-- | lib/gitlab/github_import/client.rb | 53 | ||||
-rw-r--r-- | lib/gitlab/github_import/importer.rb | 46 | ||||
-rw-r--r-- | lib/gitlab/github_import/project_creator.rb | 26 |
3 files changed, 0 insertions, 125 deletions
diff --git a/lib/gitlab/github_import/client.rb b/lib/gitlab/github_import/client.rb deleted file mode 100644 index 270cbcd9ccd..00000000000 --- a/lib/gitlab/github_import/client.rb +++ /dev/null @@ -1,53 +0,0 @@ -module Gitlab - module GithubImport - class Client - attr_reader :client, :api - - def initialize(access_token) - @client = ::OAuth2::Client.new( - config.app_id, - config.app_secret, - github_options - ) - - if access_token - ::Octokit.auto_paginate = true - @api = ::Octokit::Client.new(access_token: access_token) - end - end - - def authorize_url(redirect_uri) - client.auth_code.authorize_url({ - redirect_uri: redirect_uri, - scope: "repo, user, user:email" - }) - end - - def get_token(code) - client.auth_code.get_token(code).token - end - - def method_missing(method, *args, &block) - if api.respond_to?(method) - api.send(method, *args, &block) - else - super(method, *args, &block) - end - end - - def respond_to?(method) - api.respond_to?(method) || super - end - - private - - def config - Gitlab.config.omniauth.providers.find{|provider| provider.name == "github"} - end - - def github_options - OmniAuth::Strategies::GitHub.default_options[:client_options].symbolize_keys - end - end - end -end diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb deleted file mode 100644 index 23832b3233c..00000000000 --- a/lib/gitlab/github_import/importer.rb +++ /dev/null @@ -1,46 +0,0 @@ -module Gitlab - module GithubImport - class Importer - attr_reader :project, :client - - def initialize(project) - @project = project - @client = Client.new(project.creator.github_access_token) - @formatter = Gitlab::ImportFormatter.new - end - - def execute - #Issues && Comments - client.list_issues(project.import_source, state: :all).each do |issue| - if issue.pull_request.nil? - - body = @formatter.author_line(issue.user.login, issue.body) - - if issue.comments > 0 - body += @formatter.comments_header - - client.issue_comments(project.import_source, issue.number).each do |c| - body += @formatter.comment(c.user.login, c.created_at, c.body) - end - end - - project.issues.create!( - description: body, - title: issue.title, - state: issue.state == 'closed' ? 'closed' : 'opened', - author_id: gl_user_id(project, issue.user.id) - ) - end - end - end - - private - - def gl_user_id(project, github_id) - user = User.joins(:identities). - find_by("identities.extern_uid = ? AND identities.provider = 'github'", github_id.to_s) - (user && user.id) || project.creator_id - end - end - end -end diff --git a/lib/gitlab/github_import/project_creator.rb b/lib/gitlab/github_import/project_creator.rb deleted file mode 100644 index 2723eec933e..00000000000 --- a/lib/gitlab/github_import/project_creator.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Gitlab - module GithubImport - 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.name, - description: repo.description, - namespace_id: namespace.id, - visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC, - import_type: "github", - import_source: repo.full_name, - import_url: repo.clone_url.sub("https://", "https://#{current_user.github_access_token}@") - ).execute - end - end - end -end |