lib/ghtorrent/ghtorrent.rb
def ensure_forks(owner, repo)
      currepo = ensure_repo(owner, repo)

      if currepo.nil?
        warn "Could not find repo #{owner}/#{repo} for retrieving forks"
        return
      end

      existing_forks = db.from(:projects, :users).\
          where(Sequel.qualify('users', 'id') => Sequel.qualify('projects', 'owner_id')). \
          where(Sequel.qualify('projects', 'forked_from') => currepo[:id]).\
          select(Sequel.qualify('projects', 'name'), :login).all

      retrieve_forks(owner, repo).reduce([]) do |acc, x|
        if existing_forks.find do |y|
          forked_repo_owner = x['url'].split(/\//)[4]
          forked_repo_name = x['url'].split(/\//)[5]
          y[:login] == forked_repo_owner && y[:name] == forked_repo_name
        end.nil?
          acc << x
        else
          acc
        end
      end.map { |x| save{ensure_fork(owner, repo, x['id']) }}.select{|x| !x.nil?}
    end
def ensure_forks(owner, repo)
      currepo = ensure_repo(owner, repo)

      if currepo.nil?
        warn "Could not find repo #{owner}/#{repo} for retrieving forks"
        return
      end

      existing_forks = db.from(:projects, :users).\
          where(Sequel.qualify('users', 'id') => Sequel.qualify('projects', 'owner_id')). \
          where(Sequel.qualify('projects', 'forked_from') => currepo[:id]).\
          select(Sequel.qualify('projects', 'name'), :login).all

      retrieve_forks(owner, repo).reduce([]) do |acc, x|
        if existing_forks.find do |y|
          forked_repo_owner = x['url'].split(/\//)[4]
          forked_repo_name = x['url'].split(/\//)[5]
          y[:login] == forked_repo_owner && y[:name] == forked_repo_name
        end.nil?
          acc << x
        else
          acc
        end
      end.map { |x| save{ensure_fork(owner, repo, x['id']) }}.select{|x| !x.nil?}
    end
Get all forks for a project.

 ==Parameters:
 [owner]  The user to which the project belongs
 [repo]  The repository/project to find forks for