Class: Hubba::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/hubba/github.rb

Instance Method Summary collapse

Constructor Details

#initializeGithub

Returns a new instance of Github.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hubba/github.rb', line 30

def initialize
   @client = if Hubba.configuration.token
               Client.new( token: Hubba.configuration.token )
             elsif Hubba.configuration.user &&
                   Hubba.configuration.password
               Client.new( user:     Hubba.configuration.user,
                           password: Hubba.configuration.password )
             else
               Client.new
             end
end

Instance Method Details

#org(name) ⇒ Object



66
67
68
# File 'lib/hubba/github.rb', line 66

def org( name )
  Resource.new( get "/orgs/#{name}" )
end

#org_repos(name) ⇒ Object



70
71
72
# File 'lib/hubba/github.rb', line 70

def org_repos( name )
  Repos.new( get "/orgs/#{name}/repos?per_page=100" )
end

#repo(full_name) ⇒ Object

full_name (handle) e.g. henrythemes/jekyll-starter-theme



76
77
78
# File 'lib/hubba/github.rb', line 76

def repo( full_name )   ## full_name (handle) e.g. henrythemes/jekyll-starter-theme
  Resource.new( get "/repos/#{full_name}" )
end

#repo_commits(full_name) ⇒ Object



80
81
82
# File 'lib/hubba/github.rb', line 80

def repo_commits( full_name )
  Resource.new( get "/repos/#{full_name}/commits" )
end

#update(obj) ⇒ Object

more



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/hubba/github.rb', line 88

def update( obj )
  if obj.is_a?( Stats )
    stats = obj
    full_name = stats.full_name
    puts "[update 1/2] fetching repo >#{full_name}<..."
    repo    = repo( full_name )
    puts "[update 2/2] fetching repo >#{full_name}< commits ..."
    commits = repo_commits( full_name )

    stats.update( repo, commits )
  else
    raise ArgumentError, "unknown source object passed in - expected Hubba::Stats; got #{obj.class.name}"
  end
end

#update_stats(h) ⇒ Object

todo/fix: change to Reposet - why? why not???



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/hubba/github.rb', line 104

def update_stats( h )    ## todo/fix: change to Reposet - why? why not???
    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

        update( stats )   ## fetch & update stats

        stats.write
      end
    end
end

#user(name) ⇒ Object



43
44
45
# File 'lib/hubba/github.rb', line 43

def user( name )
  Resource.new( get "/users/#{name}" )
end

#user_orgs(name) ⇒ Object

note: pagination

requests that return multiple items will be paginated to 30 items by default.
 You can specify further pages with the ?page parameter.

For some resources, you can also set a custom page size up to 100

with the ?per_page=100 parameter


60
61
62
# File 'lib/hubba/github.rb', line 60

def user_orgs( name )
  Orgs.new( get "/users/#{name}/orgs?per_page=100" )
end

#user_repos(name) ⇒ Object



48
49
50
# File 'lib/hubba/github.rb', line 48

def user_repos( name )
  Repos.new( get "/users/#{name}/repos" )   ## add ?per_page=100 - why? why not?
end