Class: Hubkit::Repo
- Inherits:
-
Object
- Object
- Hubkit::Repo
- Defined in:
- lib/hubkit/repo.rb
Overview
Represents one GitHub repo
Instance Attribute Summary collapse
-
#org ⇒ String
the github organization containing the repo.
-
#repo ⇒ String
the github repo name.
Class Method Summary collapse
-
.from_gh(gh) ⇒ Repo
Initialize a Repo model from a github API payload.
-
.from_name(name) ⇒ Repo
Initialize a Repo model from the organization and repo name.
-
.from_name_with_default_org(name) ⇒ Repo
Initialize a Repo model from the name of the repo within the default organization.
-
.list(visibility = 'all') ⇒ Enumerable
List available repos.
Instance Method Summary collapse
-
#initialize(org:, repo:) ⇒ Repo
constructor
Construct a Repo model from the organization and repo name.
-
#inspect ⇒ String
Return a human readable description of the Repo model.
-
#issues(include_closed = false) ⇒ IssueCollection
A list of issues for this Repo.
-
#issues_and_pulls(include_closed = false) ⇒ IssueCollection
A list of issues and pull requests for this Repo.
-
#labels ⇒ Enumerable
Get an array of label strings which are available on this repo.
-
#paginator_for_status(include_closed) ⇒ IssuePaginator
Get an IssuePaginator for a given open/closed issue status.
Constructor Details
#initialize(org:, repo:) ⇒ Repo
Construct a Repo model from the organization and repo name
50 51 52 53 |
# File 'lib/hubkit/repo.rb', line 50 def initialize(org:, repo:) @org = org @repo = repo end |
Instance Attribute Details
#org ⇒ String
the github organization containing the repo
5 6 7 |
# File 'lib/hubkit/repo.rb', line 5 def org @org end |
#repo ⇒ String
the github repo name
5 6 7 |
# File 'lib/hubkit/repo.rb', line 5 def repo @repo end |
Class Method Details
.from_gh(gh) ⇒ Repo
Initialize a Repo model from a github API payload
25 26 27 |
# File 'lib/hubkit/repo.rb', line 25 def self.from_gh(gh) new(org: gh['owner']['login'], repo: gh.name) end |
.from_name(name) ⇒ Repo
Initialize a Repo model from the organization and repo name
42 43 44 45 |
# 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) ⇒ Repo
Initialize a Repo model from the name of the repo within the default organization
33 34 35 36 37 |
# 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') ⇒ Enumerable
List available repos
13 14 15 16 17 18 19 20 |
# 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 |
Instance Method Details
#inspect ⇒ String
Return a human readable description of the Repo model
109 110 111 |
# 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) ⇒ IssueCollection
A list of issues for this Repo
59 60 61 |
# 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) ⇒ IssueCollection
A list of issues and pull requests for this Repo
69 70 71 72 73 74 75 76 77 78 |
# 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 ⇒ Enumerable
Get an array of label strings which are available on this repo
97 98 99 100 101 102 103 104 |
# 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) ⇒ IssuePaginator
Get an IssuePaginator for a given open/closed issue status
84 85 86 87 88 89 90 91 92 |
# 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 |