Class: Gitlab::GithubImport::Importer::ReleasesImporter

Inherits:
Object
  • Object
show all
Includes:
BulkImporting
Defined in:
lib/gitlab/github_import/importer/releases_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BulkImporting

#build_database_rows, #bulk_insert

Constructor Details

#initialize(project, client) ⇒ ReleasesImporter

project - An instance of `Project` client - An instance of `Gitlab::GithubImport::Client` rubocop: disable CodeReuse/ActiveRecord


14
15
16
17
18
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 14

def initialize(project, client)
  @project = project
  @client = client
  @existing_tags = project.releases.pluck(:tag).to_set
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


9
10
11
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 9

def client
  @client
end

#existing_tagsObject (readonly)

Returns the value of attribute existing_tags


9
10
11
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 9

def existing_tags
  @existing_tags
end

#projectObject (readonly)

Returns the value of attribute project


9
10
11
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 9

def project
  @project
end

Instance Method Details

#already_imported?(release) ⇒ Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 29

def already_imported?(release)
  existing_tags.include?(release.tag_name)
end

#build(release) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 33

def build(release)
  {
    name: release.name,
    tag: release.tag_name,
    description: description_for(release),
    created_at: release.created_at,
    updated_at: release.created_at,
    # Draft releases will have a null published_at
    released_at: release.published_at || Time.current,
    project_id: project.id
  }
end

#build_releasesObject


25
26
27
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 25

def build_releases
  build_database_rows(each_release)
end

#description_for(release) ⇒ Object


50
51
52
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 50

def description_for(release)
  release.body.presence || "Release for tag #{release.tag_name}"
end

#each_releaseObject


46
47
48
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 46

def each_release
  client.releases(project.import_source)
end

#executeObject

rubocop: enable CodeReuse/ActiveRecord


21
22
23
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 21

def execute
  bulk_insert(Release, build_releases)
end