class Hubkit::Repo

Represents one GitHub repo @attr [String] org the github organization containing the repo @attr [String] repo the github repo name

Attributes

org[RW]
repo[RW]

Public Class Methods

from_gh(gh) click to toggle source

Initialize a Repo model from a github API payload @param [Github::Mash] gh the github API response @return [Repo] the matching Repo model

# File lib/hubkit/repo.rb, line 25
def self.from_gh(gh)
  new(org: gh['owner']['login'], repo: gh.name)
end
from_name(name) click to toggle source

Initialize a Repo model from the organization and repo name @param [String] name the name of the organization/repo separated by a slash (/) @return [Repo] the matching Repo model

# File lib/hubkit/repo.rb, line 42
def self.from_name(name)
  org, repo = name.split('/')
  self.new(org: org, repo: repo)
end
from_name_with_default_org(name) click to toggle source

Initialize a Repo model from the name of the repo within the default organization @param [String] name the name of the repo @return [Repo] the matching Repo model

# File lib/hubkit/repo.rb, line 33
def self.from_name_with_default_org(name)
  fail('Hubkit::Configuration.default_org is not set') if Hubkit::Configuration.default_org.nil?
  return from_name(name) if name.include?('/')
  from_name "#{Hubkit::Configuration.default_org}/#{name}"
end
list(visibility='all') click to toggle source

List available repos @param [optional String] visibility if missing or 'all', retrieves all

repos. if 'public', only retrieves public repos

@return [Enumerable] a list of Repo models accessible with the current

credentials
# File lib/hubkit/repo.rb, line 13
def self.list(visibility='all')
  RepoCollection.new(
    RepoPaginator
      .new(visibility)
      .map { |repo| { org: repo.owner.login, repo: repo.name } }
      .map { |params| new(**params) }
  )
end
new(org:, repo:) click to toggle source

Construct a Repo model from the organization and repo name @param [String] org the name of the github organization @param [String] repo the name of the github repo

# File lib/hubkit/repo.rb, line 50
def initialize(org:, repo:)
  @org = org
  @repo = repo
end

Public Instance Methods

inspect() click to toggle source

Return a human readable description of the Repo model @return [String] the human readable representation of the Repo model

for the console
# File lib/hubkit/repo.rb, line 109
def inspect
  "#<Hubkit::Repo:0x#{(object_id << 1).to_s(16)} #{@org}/#{@repo}>"
end
issues(include_closed = false) click to toggle source

A list of issues for this Repo @param [Boolean] include_closed if true, will include closed issue. if

false or missing, the result will only include open issues

@return [IssueCollection] the list of issues for the repo

# File lib/hubkit/repo.rb, line 59
def issues(include_closed = false)
  issues_and_pulls(include_closed).true_issues
end
issues_and_pulls(include_closed = false) click to toggle source

A list of issues and pull requests for this Repo @param [Boolean] include_closed if true, will include closed issue. if

false or missing, the result will only include open issues

@return [IssueCollection] the list of issues and pulls for the repo

# File lib/hubkit/repo.rb, line 69
def issues_and_pulls(include_closed = false)
  @_issues_and_pulls ||= {}

  @_issues_and_pulls[include_closed] ||=
    IssueCollection.new(
      paginator_for_status(include_closed).to_a.flat_map do |gh|
        Issue.from_gh(org: @org, repo: @repo, gh: gh)
      end,
    )
end
labels() click to toggle source

Get an array of label strings which are available on this repo @return [Enumerable] a list of strings which are the names of labels

available on this repo
# File lib/hubkit/repo.rb, line 97
def labels
  @_labels ||=
    Github
    .issues.labels.list(@org, @repo, per_page: 100)
    .map(&:name)
    .map(&:downcase)
    .uniq
end
paginator_for_status(include_closed) click to toggle source

Get an IssuePaginator for a given open/closed issue status @param [Boolean] include_closed if true, paginator will return results

with closed issues. if false, closed issues will be excluded

@return [IssuePaginator] the issue paginator for this status and repo

# File lib/hubkit/repo.rb, line 84
def paginator_for_status(include_closed)
  state_flag = include_closed ? 'all' : 'open'

  IssuePaginator.new(
    org: @org,
    repo: @repo,
    state: state_flag,
  )
end