class Gitlang::Organization
Class representing a GitHub organization
Attributes
name[R]
repositories[R]
Public Class Methods
new(name, client)
click to toggle source
# File lib/gitlang/organization.rb, line 13 def initialize(name, client) @name = name.downcase @client = client @repositories = fetch_repo_names.each_with_object([]) do |repo_name, repositories| # There is a tight coupling between Organisation and Repository, but I # think it's fine regarding the scope of the application. repositories << Repository.new(@name, repo_name, @client) end end
Public Instance Methods
usage_per_repo()
click to toggle source
Creates an array of hashes with the language usage for each repository.
# File lib/gitlang/organization.rb, line 24 def usage_per_repo conditional_rescue do @repositories.each_with_object([]) do |repository, result| result << repository.languages end end end
Private Instance Methods
fetch_all_pages()
click to toggle source
Get every repository name. Acts as a helper for fetch_repo_names
since we're dealing with an external paginated service.
# File lib/gitlang/organization.rb, line 40 def fetch_all_pages result = @client.org_repos(name, query: { type: 'sources', visibility: 'public' }, per_page: 100) .map(&:name) last_response = @client.last_response until last_response.rels[:next].nil? last_response = last_response.rels[:next].get result << last_response.data.map(&:name) end result end
fetch_repo_names()
click to toggle source
# File lib/gitlang/organization.rb, line 34 def fetch_repo_names conditional_rescue { fetch_all_pages.flatten } end