app/controllers/projects_controller.rb
# Retrieve a set of (GitHub) repositories managed by the current user.
# We intentionally retrieve a subset (to self-protect from overlong lists
# that might lead to a timeout), so we prioritize recently pushed repos.
# We omit repos that are already pursuing a badge.
# rubocop:disable Style/MethodCalledOnDoEndBlock, Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
Retrieve a set of (GitHub) repositories managed by the current user.
We intentionally retrieve a subset (to self-protect from overlong lists
that might lead to a timeout), so we prioritize recently pushed repos.
We omit repos that are already pursuing a badge.
Retrieve a set of ( GitHub ) repositories managed by the current user . We intentionally retrieve a subset ( to self - protect from overlong lists that might lead to a timeout ) so we prioritize recently pushed repos . We omit repos that are already pursuing a badge .
def repo_data
    github = Octokit::Client.new access_token: session[:user_token]
    github.auto_paginate = false
    repos = github.repos(
      nil,
      sort: 'pushed', per_page: MAX_GITHUB_REPOS_FROM_USER
    )
    return if repos.blank?
    repo_urls = repos.pluck(:html_url) 
    already = Project.where(repo_url: repo_urls).pluck(:repo_url).to_set
    repos = repos.reject { |repo| already.member?(repo.html_url) }
    repos.sort_by! { |v| v['full_name'] }
    repos.map do |repo|
      [repo.full_name, repo.fork, repo.homepage, repo.html_url]
    end.compact
  end
def repo_data github = Octokit :: Client . new access_token : session [ :user_token ] github . auto_paginate = false repos = github . repos ( nil , sort : 'pushed' , per_page : MAX_GITHUB_REPOS_FROM_USER ) return if repos . blank? repo_urls = repos . pluck ( :html_url ) already = Project . where ( repo_url : repo_urls ) . pluck ( :repo_url ) . to_set repos = repos . reject { | repo | already . member? ( repo . html_url ) } repos . sort_by! { | v | v [ 'full_name' ] } repos . map do | repo | [ repo . full_name , repo . fork , repo . homepage , repo . html_url ] end . compact end
Retrieve a set of (GitHub) repositories managed by the current user.
Retrieve a set of ( GitHub ) repositories managed by the current user .
# Take extra steps to prevent a timeout when retrieving repo data. # If we enable auto_pagination we get a list of all the repos, but it # appears that GitHub sometimes hangs in those cases if the user has # a large number of repos.  David A. Wheeler suspects that problem is that # GitHub itself uses Rails and Rails doesn't stream JSON output by default; # that is fine for small datasets but can lead timeouts on larger datasets. # Thus, we no longer enable auto_paginate. # By default a call to github.repos will only return the first 30; # we pass a per_page value to control this.  For more information, see: # https://developer.github.com/v3/#pagination # Find & remove the repos already in our database. # We do this to make the user's job easier. # URLs of all of this user's repos # Sort by name for user convenience: