Class: Gitlab::ManifestImport::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/manifest_import/manifest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Manifest

Returns a new instance of Manifest.



21
22
23
24
25
26
# File 'lib/gitlab/manifest_import/manifest.rb', line 21

def initialize(file)
  @parsed_xml = Nokogiri::XML(file) { |config| config.strict }
  @errors = []
rescue Nokogiri::XML::SyntaxError
  @errors = ['The uploaded file is not a valid XML file.']
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



19
20
21
# File 'lib/gitlab/manifest_import/manifest.rb', line 19

def errors
  @errors
end

#parsed_xmlObject (readonly)

Returns the value of attribute parsed_xml.



19
20
21
# File 'lib/gitlab/manifest_import/manifest.rb', line 19

def parsed_xml
  @parsed_xml
end

Instance Method Details

#projectsObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/manifest_import/manifest.rb', line 28

def projects
  raw_projects.each_with_index.map do |project, i|
    {
      id: i,
      name: project['name'],
      path: project['path'],
      url: repository_url(project['name'])
    }
  end
end

#valid?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitlab/manifest_import/manifest.rb', line 39

def valid?
  return false if @errors.any?

  unless validate_remote
    @errors << 'Make sure a <remote> tag is present and is valid.'
  end

  unless validate_projects
    @errors << 'Make sure every <project> tag has name and path attributes.'
  end

  unless validate_scheme
    @errors << 'Make sure the url does not start with javascript'
  end

  @errors.empty?
end