Class: EndOfLife::Repository::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/end_of_life/repository/search.rb,
lib/end_of_life/repository/search/query.rb

Constant Summary collapse

Query =
Data.define(:options) do
  def to_s
    query = options[:product].search_query

    query += if options[:repository]
      " repo:#{options[:repository]}"
    elsif options[:organizations]
      options[:organizations].map { |org| " org:#{org}" }.join
    else
      " user:#{options[:user]}"
    end

    if options[:visibility]
      query += " is:#{options[:visibility]}"
    end

    if options[:excludes]
      words_to_exclude = options[:excludes].map { |word| "NOT #{word} " }.join

      query += " #{words_to_exclude} in:name"
    end

    query
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Search

Returns a new instance of Search.



8
9
10
# File 'lib/end_of_life/repository/search.rb', line 8

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/end_of_life/repository/search.rb', line 6

def options
  @options
end

Instance Method Details

#resultObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/end_of_life/repository/search.rb', line 12

def result
  github_client.bind do |github|
    github.auto_paginate = true
    options[:user] ||= github.user.

    query = Query.new(options).to_s
    items = github.search_repositories(query, {sort: :updated}).items

    Success(
      items.filter_map do |repo|
        next if repo.archived && options[:skip_archived]

        Repository.new(
          full_name: repo.full_name,
          url: repo.html_url,
          github_client: github
        )
      end
    )
  rescue => e
    Failure("Unexpected error: #{e}")
  end
end