Class: Gitlab::GoogleCodeImport::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/google_code_import/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data) ⇒ Client


12
13
14
# File 'lib/gitlab/google_code_import/client.rb', line 12

def initialize(raw_data)
  @raw_data = raw_data
end

Instance Attribute Details

#raw_dataObject (readonly)

Returns the value of attribute raw_data


4
5
6
# File 'lib/gitlab/google_code_import/client.rb', line 4

def raw_data
  @raw_data
end

Class Method Details

.mask_email(author) ⇒ Object


6
7
8
9
10
# File 'lib/gitlab/google_code_import/client.rb', line 6

def self.mask_email(author)
  parts = author.split("@", 2)
  parts[0] = "#{parts[0][0...-3]}..."
  parts.join("@")
end

Instance Method Details

#incompatible_reposObject


24
25
26
# File 'lib/gitlab/google_code_import/client.rb', line 24

def incompatible_repos
  @incompatible_repos ||= raw_data["projects"].map { |raw_repo| GoogleCodeImport::Repository.new(raw_repo) }.reject(&:git?)
end

#repo(id) ⇒ Object


28
29
30
# File 'lib/gitlab/google_code_import/client.rb', line 28

def repo(id)
  repos.find { |repo| repo.id == id }
end

#reposObject


20
21
22
# File 'lib/gitlab/google_code_import/client.rb', line 20

def repos
  @repos ||= raw_data["projects"].map { |raw_repo| GoogleCodeImport::Repository.new(raw_repo) }.select(&:git?)
end

#user_mapObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gitlab/google_code_import/client.rb', line 32

def user_map
  user_map = Hash.new { |hash, user| hash[user] = self.class.mask_email(user) }

  repos.each do |repo|
    next unless repo.valid? && repo.issues

    repo.issues.each do |raw_issue|
      # Touching is enough to add the entry and masked email.
      user_map[raw_issue["author"]["name"]]

      raw_issue["comments"]["items"].each do |raw_comment|
        user_map[raw_comment["author"]["name"]]
      end
    end
  end

  Hash[user_map.sort]
end

#valid?Boolean


16
17
18
# File 'lib/gitlab/google_code_import/client.rb', line 16

def valid?
  raw_data.is_a?(Hash) && raw_data["kind"] == "projecthosting#user" && raw_data.has_key?("projects")
end