diff --git a/script/cibuild b/script/cibuild index 2656804e..4cf04d70 100755 --- a/script/cibuild +++ b/script/cibuild @@ -9,10 +9,6 @@ export PATH=/usr/share/rbenv/shims:$PATH RBENV_VERSION=$(cat .ruby-version) bundle exec rake test bundle exec rubocop -D -S -# Ensure the Code for America and Code for All list only contain official chapters/partners -# Disabled for now due to false positives -# bundle exec script/fetch-cfa - # Ensure only organizations are listed bundle exec script/ensure-orgs diff --git a/script/fetch-cfa b/script/fetch-cfa deleted file mode 100755 index 3196236b..00000000 --- a/script/fetch-cfa +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# fetches list of CFA brigades from the CFA API, and outputs merged list to command line - -require 'open-uri' -require 'json' -require 'yaml' -require 'addressable/uri' -require 'addressable/template' -require 'logger' -require 'typhoeus' - -module CFA - class Fetcher - ENDPOINT = 'http://api.codeforamerica.org/api/organizations' - DEFAULT_ARGS = { - 'per_page' => 200 - }.freeze - - def fetch - logger.info 'Updating CFA list...' - logger.info "Found #{code_for_all_orgs.count} Code for All orgs" - logger.info "Found #{brigades.count} Brigades" - - to_be_removed = org_file['Code For America'] - brigades - code_for_all_orgs - msg = "The following orgs aren't listed on http://api.codeforamerica.org/api/#api-organizations: \n" - logger.info msg + to_be_removed.join("\n") unless to_be_removed.empty? - - org_file['Code For America'] = brigades - org_file['Code for All'] = code_for_all_orgs - org_file['Civic Hackers'] = civic_hackers - brigades - code_for_all_orgs + to_be_removed - - comment = File.read(org_file_path).lines.first - output = comment - output << "\n" - output << org_file.to_yaml.sub(/\A---\n/, '').gsub(/^-/, ' -').gsub(/\n([^ ])/, "\n\n\\1") - - File.write(org_file_path, output) - - logger.info 'Done.' - exit to_be_removed.empty? ? 0 : 1 - end - - def civic_hackers - @civic_hackerse = org_file['Civic Hackers'].map(&:downcase) - end - - def gov_orgs - @gov_orgs ||= YAML.load_file('./_data/governments.yml').values.flatten.map(&:downcase) - end - - def code_for_all_orgs - @code_for_all_orgs ||= get_orgs('Code+for+All') - gov_orgs - end - - def brigades - @brigades ||= get_orgs('Brigade') - code_for_all_orgs - gov_orgs - end - - def all - @all ||= brigades + code_for_all_orgs - end - - def logger - @logger ||= Logger.new($stdout) - end - - private - - def org_file - @org_file ||= YAML.load_file org_file_path - end - - def org_file_path - File.expand_path '../_data/civic_hackers.yml', File.dirname(__FILE__) - end - - def get_orgs(type) - url = url_for_query('type' => type) - response = Typhoeus.get(url) - return unless response.success? - - data = JSON.parse(response.body) - parse_response(data) - rescue JSON::ParserError - nil - end - - def parse_response(data) - orgs = data['objects'].map do |org| - org['current_projects'].map do |project| - project.dig('github_details', 'owner', 'login') - end - end - orgs.flatten.compact.uniq.map(&:downcase).select { |o| org?(o) }.sort - end - - # The CFA API expects "Code For All" to be passed as the unescaped "Code+For+All" - # Manually build the query arguments to avoid the +'s being (properly) escaped - def url_for_query(args = {}) - args = DEFAULT_ARGS.merge(args) - args = args.map { |k, v| "#{k}=#{v}" }.join('&') - "#{ENDPOINT}?#{args}" - end - - # Ideally this would be an API call, but given the volume of calls, - # We'd constantly hit any rate limit as each needs to be its own query - def org?(user) - Typhoeus.head("https://github.com/orgs/#{user}/people", accept_encoding: 'gzip').success? - end - end -end - -CFA::Fetcher.new.fetch