Class: Hubkit::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/hubkit/repo.rb

Overview

Represents one GitHub repo

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#orgString

the github organization containing the repo


5
6
7
# File 'lib/hubkit/repo.rb', line 5

def org
  @org
end

#repoString

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., repo: repo.name } }
      .map { |params| new(**params) }
  )
end

Instance Method Details

#inspectString

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

#labelsEnumerable

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