BigW Consortium Gitlab

client.rb 1.36 KB
Newer Older
1 2 3 4 5
module Gitlab
  module GoogleCodeImport
    class Client
      attr_reader :raw_data

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

12 13 14 15 16 17 18 19 20 21 22 23
      def initialize(raw_data)
        @raw_data = raw_data
      end

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

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

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

28 29 30
      def repo(id)
        repos.find { |repo| repo.id == id }
      end
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

      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
50 51 52
    end
  end
end