class Unlearn::Runner

Attributes

batches[R]
filtered_repos[R]
repos[R]

Public Class Methods

new() click to toggle source
# File lib/unlearn/runner.rb, line 5
def initialize
  @batches = [
    '-v-000',
    '-bootcamp-prep-000',
    '-cb-000',
    '-cb-gh-000',
    '-re-coded-000',
    '-js-intro-000'
  ]

  @repos = []
  @filtered_repos = []
end

Public Instance Methods

run() click to toggle source
# File lib/unlearn/runner.rb, line 19
def run
  get_repos

  filter_repos
end

Private Instance Methods

filter_repos() click to toggle source
# File lib/unlearn/runner.rb, line 54
def filter_repos
  batches.each do |batch|
    repos.each do |repo|
      filtered_repos << repo if repo.include? batch
    end
  end

  filtered_repos
end
get_repos() click to toggle source
# File lib/unlearn/runner.rb, line 27
def get_repos
  has_next_page = true
  end_cursor = nil

  while has_next_page
    if end_cursor
      result = Unlearn::GitHubAPI::Client.query(Unlearn::GitHubAPI::Query::Repos, variables: { endCursor: end_cursor })
    else
      result = Unlearn::GitHubAPI::Client.query(Unlearn::GitHubAPI::Query::Repos)
    end

    if result.data
      result.data.viewer.repositories.nodes.each do |n|
        repos << n.name_with_owner
      end

      has_next_page = result.data.viewer.repositories.page_info.has_next_page
      end_cursor = result.data.viewer.repositories.page_info.end_cursor
    else
      puts "Unable to load repositories. Please check that"
      puts "your token is valid and try again. Goodbye!"

      exit
    end
  end
end