Module: Hubba
- Defined in:
- lib/hubba.rb,
lib/hubba.rb,
lib/hubba/stats.rb,
lib/hubba/config.rb,
lib/hubba/github.rb,
lib/hubba/update.rb,
lib/hubba/reposet.rb,
lib/hubba/version.rb,
lib/hubba/update_traffic.rb
Overview
add convenience alias for alternate spelling - why? why not?
Defined Under Namespace
Classes: Configuration, Github, HttpError, Stats
Constant Summary collapse
- GitHub =
Github
- MAJOR =
todo: namespace inside version or something - why? why not??
1
- MINOR =
0
- PATCH =
2
- VERSION =
[MAJOR,MINOR,PATCH].join('.')
Class Method Summary collapse
- .banner ⇒ Object
- .configuration ⇒ Object (also: config)
- .configure {|configuration| ... } ⇒ Object
-
.reposet(*users, orgs: true, cache: false) ⇒ Object
orgs - include repos form org(anizations) too cache - save json response to cache_dir - change to/use debug/tmp_dir? - why? why not?.
- .root ⇒ Object
-
.update_stats(hash_or_path = './repos.yml') ⇒ Object
move to reposet e.g.
-
.update_traffic(hash_or_path = './repos.yml') ⇒ Object
note: keep update traffic separate from update (basic) stats traffic stats require (personal access) token with push access!!.
- .version ⇒ Object
Class Method Details
.banner ⇒ Object
11 12 13 |
# File 'lib/hubba/version.rb', line 11 def self. "hubba/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]" end |
.configuration ⇒ Object Also known as: config
39 40 41 |
# File 'lib/hubba/config.rb', line 39 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
47 48 49 |
# File 'lib/hubba/config.rb', line 47 def self.configure yield( configuration ) end |
.reposet(*users, orgs: true, cache: false) ⇒ Object
orgs - include repos form org(anizations) too cache - save json response to cache_dir - change to/use debug/tmp_dir? - why? why not?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# 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 ⇒ Object
15 16 17 |
# File 'lib/hubba/version.rb', line 15 def self.root File.( File.dirname(File.dirname(File.dirname(__FILE__))) ) end |
.update_stats(hash_or_path = './repos.yml') ⇒ Object
move to reposet e.g. Reposet#update_status!!!!
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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') ⇒ Object
note: keep update traffic separate from update (basic) stats
traffic stats require (personal access) token with push access!!
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 ⇒ Object
7 8 9 |
# File 'lib/hubba/version.rb', line 7 def self.version VERSION end |