# frozen_string_literal: true require "google/api_client/client_secrets" module NeetoReposVerfier class ListVerfier NEETO_REPOS_SHEET_LINK = "https://docs.google.com/spreadsheets/d/1QaYz_s0j7wX8kmp8_JQPYXqFGs18helJRORS-8edsyQ/edit#gid=0" NEETO_REPOS_SHEET_QUERY = "https://sheets.googleapis.com/v4/spreadsheets/1QaYz_s0j7wX8kmp8_JQPYXqFGs18helJRORS-8edsyQ/values/products!B2:B?access_token=" def process print_verifier_name valid? ? print_success_message : print_failure_message end private def local_list @_local_list ||= fetch_local_lists end def fetch_local_lists NeetoCompliance::NeetoRepos::products.keys + NeetoCompliance::NeetoRepos::nanos + NeetoCompliance::NeetoRepos::widgets + NeetoCompliance::NeetoRepos::chrome_extensions + NeetoCompliance::NeetoRepos::helper_packages + NeetoCompliance::NeetoRepos::electron_apps + NeetoCompliance::NeetoRepos::executables + NeetoCompliance::NeetoRepos::mobile_apps + NeetoCompliance::NeetoRepos::other_repos + NeetoCompliance::NeetoRepos::nanos_mono_repos end def actual_list @_actual_list ||= build_app_list end def fetch_actual_list uri = URI("#{NEETO_REPOS_SHEET_QUERY}#{access_token}") response = JSON.parse(Net::HTTP.get(uri)) print_error_message(response["error"]["message"]) if response["error"] response["values"] end def build_app_list filter_and_clean_app_list(fetch_actual_list.flatten) end def filter_and_clean_app_list(apps) apps.filter { |app| !app.match?(/ |[A-Z]/) } end def valid? @unwanted_apps = local_list - actual_list @missing_apps = actual_list - local_list @unwanted_apps.size == 0 && @missing_apps.size == 0 end def print_verifier_name print self.class.name end def print_success_message puts "[PASS]".green end def print_failure_message puts "[FAIL]".red puts "The Neeto repos list that is \"data/neeto_repos.json\" file must be in sync with #{NEETO_REPOS_SHEET_LINK}".yellow unless @unwanted_apps.nil? || @unwanted_apps.empty? puts "The following apps must be removed from the \"data/neeto_repos.json\" file: \n#{@unwanted_apps.to_s.red}\n" end unless @missing_apps.nil? || @missing_apps.empty? puts "The following apps must be added to the \"data/neeto_repos.json\" file: \n#{@missing_apps.to_s.green}" end exit(1) end def print_error_message(message) puts "[ERROR]".red puts message.red exit(1) end def access_token client_secrets = Google::APIClient::ClientSecrets.load("bin/neeto_repos_verifier/client_config.json") auth_client = client_secrets.to_authorization auth_client.fetch_access_token! auth_client.access_token end end end