module Hubba
add convenience alias for alternate spelling - why? why not?
Constants
- GitHub
- MAJOR
- MINOR
- PATCH
- VERSION
Public Class Methods
configuration()
click to toggle source
lets you use
Hubba.configure do |config| config.token = 'secret' -or- config.user = 'testdada' config.password = 'secret' end move configure block to GitHub class - why? why not? e.g. GitHub.configure do |config| ... end
# File lib/hubba/config.rb, line 39 def self.configuration @configuration ||= Configuration.new end
Also aliased as: config
configure() { |configuration| ... }
click to toggle source
# File lib/hubba/config.rb, line 47 def self.configure yield( configuration ) end
reposet( *users, orgs: true, cache: false )
click to toggle source
orgs - include repos form org(anizations) too cache - save json response to cache_dir - change to/use debug/tmp_dir? - why? why not?
# File lib/hubba/reposet.rb, line 6 def self.reposet( *users, orgs: true, cache: false ) # users = [users] if users.is_a?( String ) ### wrap in array if single user gh = Github.new forks = [] h = {} users.each do |user| res = gh.user_repos( user ) save_json( "#{config.cache_dir}/users~#{user}~repos.json", res.data ) if cache repos = [] #### # check for forked repos (auto-exclude personal by default) # note: forked repos in orgs get NOT auto-excluded!!! res.data.each do |repo| fork = repo['fork'] if fork print "FORK " forks << "#{repo['full_name']} (AUTO-EXCLUDED)" else print " " repos << repo['name'] end print repo['full_name'] print "\n" end h[ "#{user} (#{repos.size})" ] = repos.sort end ## all repos from orgs ## note: for now only use first (primary user) - why? why not? if orgs user = users[0] res = gh.user_orgs( user ) save_json( "#{config.cache_dir}/users~#{user}~orgs.json", res.data ) if cache logins = res.logins.each do |login| ## next if ['xxx'].include?( login ) ## add orgs here to skip res = gh.org_repos( login ) save_json( "#{config.cache_dir}/orgs~#{login}~repos.json", res.data ) if cache repos = [] res.data.each do |repo| fork = repo['fork'] if fork print "FORK " forks << repo['full_name'] repos << repo['name'] else print " " repos << repo['name'] end print repo['full_name'] print "\n" end h[ "#{login} (#{repos.size})" ] = repos.sort end end if forks.size > 0 puts puts "#{forks.size} fork(s):" puts forks end h end
root()
click to toggle source
# File lib/hubba/version.rb, line 15 def self.root "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}" end
update_stats( hash_or_path='./repos.yml' )
click to toggle source
# File lib/hubba/update.rb, line 3 def self.update_stats( hash_or_path='./repos.yml' ) ## move to reposet e.g. Reposet#update_status!!!! h = if hash_or_path.is_a?( String ) ## assume it is a file path!!! path = hash_or_path YAML.load_file( path ) else hash_or_path # assume its a hash / reposet already!!! end gh = Github.new h.each do |org_with_counter,names| ## remove optional number from key e.g. ## mrhydescripts (3) => mrhydescripts ## footballjs (4) => footballjs ## etc. org = org_with_counter.sub( /\([0-9]+\)/, '' ).strip ## puts " -- #{key_with_counter} [#{key}] --" names.each do |name| full_name = "#{org}/#{name}" ## puts " fetching stats #{count+1}/#{repo_count} - >#{full_name}<..." stats = Stats.new( full_name ) stats.read puts "update >#{full_name}< [1/4] - fetching repo..." repo = gh.repo( full_name ) puts "update >#{full_name}< [2/4] - fetching repo commits ..." commits = gh.repo_commits( full_name ) puts "update >#{full_name}< [3/4] - fetching repo topics ..." topics = gh.repo_topics( full_name ) puts "update >#{full_name}< [4/4] - fetching repo languages ..." languages = gh.repo_languages( full_name ) stats.update( repo, commits: commits, topics: topics, languages: languages ) stats.write end end end
update_traffic( hash_or_path='./repos.yml' )
click to toggle source
note: keep update traffic separate from update (basic) stats
traffic stats require (personal access) token with push access!!
# File lib/hubba/update_traffic.rb, line 8 def self.update_traffic( hash_or_path='./repos.yml' ) ## move to reposet e.g. Reposet#update_status!!!! h = if hash_or_path.is_a?( String ) ## assume it is a file path!!! path = hash_or_path YAML.load_file( path ) else hash_or_path # assume its a hash / reposet already!!! end gh = Github.new h.each do |org_with_counter,names| ## remove optional number from key e.g. ## mrhydescripts (3) => mrhydescripts ## footballjs (4) => footballjs ## etc. org = org_with_counter.sub( /\([0-9]+\)/, '' ).strip ## puts " -- #{key_with_counter} [#{key}] --" names.each do |name| full_name = "#{org}/#{name}" ## puts " fetching stats #{count+1}/#{repo_count} - >#{full_name}<..." stats = Stats.new( full_name ) stats.read puts "update >#{full_name}< [1/4] - fetching repo traffic clones..." clones = gh.repo_traffic_clones( full_name ) puts "update >#{full_name}< [2/4] - fetching repo traffic views..." views = gh.repo_traffic_views( full_name ) puts "update >#{full_name}< [3/4] - fetching repo traffic popular paths..." paths = gh.repo_traffic_popular_paths( full_name ) puts "update >#{full_name}< [4/4] - fetching repo traffic popular referrers..." referrers = gh.repo_traffic_popular_referrers( full_name ) stats.update_traffic( clones: clones, views: views, paths: paths, referrers: referrers ) stats.write end end end
version()
click to toggle source
# File lib/hubba/version.rb, line 7 def self.version VERSION end