Class: Metanorma::Release::Platform::GitHub::TopicDiscoverer

Inherits:
Object
  • Object
show all
Includes:
RepoDiscoverer
Defined in:
lib/metanorma/release/platform/github/topic_discoverer.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, organizations:, topic:) ⇒ TopicDiscoverer

Returns a new instance of TopicDiscoverer.



10
11
12
13
14
# File 'lib/metanorma/release/platform/github/topic_discoverer.rb', line 10

def initialize(client:, organizations:, topic:)
  @client = client
  @organizations = organizations
  @topic = topic
end

Instance Method Details

#discoverObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/metanorma/release/platform/github/topic_discoverer.rb', line 16

def discover
  @organizations.flat_map do |org|
    query = "topic:#{@topic} org:#{org}"
    all = []
    page = 1
    loop do
      results = @client.search_repositories(query, per_page: 100,
                                            page: page)
      items = results[:items]
      break if items.nil? || items.empty?

      all.concat(items)
      break if items.length < 100

      page += 1
    end
    all.map do |repo|
      RepoRef.new(owner: org, repo: repo[:name])
    end
  end
end