2018-03-17 18:26:18 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
module Importer
|
|
|
|
class ReleasesImporter
|
|
|
|
include BulkImporting
|
|
|
|
|
|
|
|
attr_reader :project, :client, :existing_tags
|
|
|
|
|
|
|
|
# project - An instance of `Project`
|
|
|
|
# client - An instance of `Gitlab::GithubImport::Client`
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
def initialize(project, client)
|
|
|
|
@project = project
|
|
|
|
@client = client
|
|
|
|
@existing_tags = project.releases.pluck(:tag).to_set
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def execute
|
|
|
|
bulk_insert(Release, build_releases)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_releases
|
|
|
|
build_database_rows(each_release)
|
|
|
|
end
|
|
|
|
|
|
|
|
def already_imported?(release)
|
|
|
|
existing_tags.include?(release.tag_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build(release)
|
|
|
|
{
|
2019-12-21 20:55:43 +05:30
|
|
|
name: release.name,
|
2018-03-17 18:26:18 +05:30
|
|
|
tag: release.tag_name,
|
|
|
|
description: description_for(release),
|
|
|
|
created_at: release.created_at,
|
2019-12-21 20:55:43 +05:30
|
|
|
updated_at: release.created_at,
|
|
|
|
# Draft releases will have a null published_at
|
|
|
|
released_at: release.published_at || Time.current,
|
2018-03-17 18:26:18 +05:30
|
|
|
project_id: project.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_release
|
|
|
|
client.releases(project.import_source)
|
|
|
|
end
|
|
|
|
|
|
|
|
def description_for(release)
|
2019-12-21 20:55:43 +05:30
|
|
|
release.body.presence || "Release for tag #{release.tag_name}"
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|