Class: Gitlab::GitlabImport::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/gitlab_import/importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Importer

Returns a new instance of Importer


6
7
8
9
10
11
12
13
14
15
# File 'lib/gitlab/gitlab_import/importer.rb', line 6

def initialize(project)
  @project = project
  credentials = import_data
  if credentials && credentials[:password]
    @client = Client.new(credentials[:password])
    @formatter = Gitlab::ImportFormatter.new
  else
    raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


4
5
6
# File 'lib/gitlab/gitlab_import/importer.rb', line 4

def client
  @client
end

#projectObject (readonly)

Returns the value of attribute project


4
5
6
# File 'lib/gitlab/gitlab_import/importer.rb', line 4

def project
  @project
end

Instance Method Details

#executeObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gitlab/gitlab_import/importer.rb', line 17

def execute
  project_identifier = CGI.escape(project.import_source)

  #Issues && Comments
  issues = client.issues(project_identifier)

  issues.each do |issue|
    body = @formatter.author_line(issue["author"]["name"])
    body += 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