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

Attributes included from BulkImporting

#client, #project

Instance Method Summary collapse

Methods included from BulkImporting

#build_database_rows, #bulk_insert, #initialize

Instance Method Details

#already_imported?(release) ⇒ Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 23

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

#build(release) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 27

def build(release)
  existing_tags.add(release.tag_name)

  {
    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


19
20
21
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 19

def build_releases
  build_database_rows(each_release)
end

#description_for(release) ⇒ Object


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

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

#each_releaseObject


42
43
44
# File 'lib/gitlab/github_import/importer/releases_importer.rb', line 42

def each_release
  client.releases(project.import_source)
end

#executeObject

rubocop: enable CodeReuse/ActiveRecord


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

def execute
  bulk_insert(Release, build_releases)
end

#existing_tagsObject

rubocop: disable CodeReuse/ActiveRecord


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

def existing_tags
  @existing_tags ||= project.releases.pluck(:tag).to_set
end

#object_typeObject


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

def object_type
  :release
end