2018-11-09 18:39:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-03 13:29:27 +00:00
|
|
|
module Gitlab
|
|
|
|
module GoogleCodeImport
|
|
|
|
class Client
|
|
|
|
attr_reader :raw_data
|
|
|
|
|
2015-04-14 12:50:56 +00:00
|
|
|
def self.mask_email(author)
|
|
|
|
parts = author.split("@", 2)
|
|
|
|
parts[0] = "#{parts[0][0...-3]}..."
|
|
|
|
parts.join("@")
|
|
|
|
end
|
|
|
|
|
2015-04-03 13:29:27 +00:00
|
|
|
def initialize(raw_data)
|
|
|
|
@raw_data = raw_data
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
2017-06-02 17:11:26 +00:00
|
|
|
raw_data.is_a?(Hash) && raw_data["kind"] == "projecthosting#user" && raw_data.key?("projects")
|
2015-04-03 13:29:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def repos
|
|
|
|
@repos ||= raw_data["projects"].map { |raw_repo| GoogleCodeImport::Repository.new(raw_repo) }.select(&:git?)
|
|
|
|
end
|
|
|
|
|
2015-04-29 07:33:49 +00:00
|
|
|
def incompatible_repos
|
|
|
|
@incompatible_repos ||= raw_data["projects"].map { |raw_repo| GoogleCodeImport::Repository.new(raw_repo) }.reject(&:git?)
|
|
|
|
end
|
|
|
|
|
2015-04-03 13:29:27 +00:00
|
|
|
def repo(id)
|
|
|
|
repos.find { |repo| repo.id == id }
|
|
|
|
end
|
2015-04-14 12:50:56 +00:00
|
|
|
|
|
|
|
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
|
2015-04-03 13:29:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|