Class: Gitlab::GithubGistsImport::Importer::GistImporter

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

Constant Summary collapse

FileCountLimitError =
Class.new(StandardError)
RepoSizeLimitError =
Class.new(StandardError)
SnippetRepositoryError =
Class.new(StandardError)
FILE_COUNT_LIMIT_MESSAGE =
'Snippet maximum file count exceeded'
REPO_SIZE_LIMIT_MESSAGE =
'Snippet repository size exceeded'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gist, user_id) ⇒ GistImporter

gist - An instance of ‘Gitlab::GithubGistsImport::Representation::Gist`.



16
17
18
19
# File 'lib/gitlab/github_gists_import/importer/gist_importer.rb', line 16

def initialize(gist, user_id)
  @gist = gist
  @user = User.find(user_id)
end

Instance Attribute Details

#gistObject (readonly)

Returns the value of attribute gist.



7
8
9
# File 'lib/gitlab/github_gists_import/importer/gist_importer.rb', line 7

def gist
  @gist
end

#snippetObject (readonly)

Returns the value of attribute snippet.



7
8
9
# File 'lib/gitlab/github_gists_import/importer/gist_importer.rb', line 7

def snippet
  @snippet
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/gitlab/github_gists_import/importer/gist_importer.rb', line 7

def user
  @user
end

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitlab/github_gists_import/importer/gist_importer.rb', line 21

def execute
  validate_gist!

  @snippet = build_snippet
  import_repository if snippet.save!
  validate_repository!

  ServiceResponse.success
rescue FileCountLimitError, RepoSizeLimitError, SnippetRepositoryError => exception
  fail_and_track(snippet, exception)
end