Class: EndOfLife::Repository

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(full_name:, url:, github_client:) ⇒ Repository

Returns a new instance of Repository.



61
62
63
64
65
# File 'lib/end_of_life/repository.rb', line 61

def initialize(full_name:, url:, github_client:)
  @full_name = full_name
  @url = url
  @github_client = github_client
end

Instance Attribute Details

#full_nameObject (readonly)

Returns the value of attribute full_name.



59
60
61
# File 'lib/end_of_life/repository.rb', line 59

def full_name
  @full_name
end

Class Method Details

.fetch(options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/end_of_life/repository.rb', line 6

def fetch(options)
  github_client.bind do |github|
    github.auto_paginate = true
    options[:user] ||= github.user.

    query = search_query_for(options)
    items = github.search_repositories(query).items

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

.github_clientObject



28
29
30
31
32
# File 'lib/end_of_life/repository.rb', line 28

def github_client
  Maybe(ENV["GITHUB_TOKEN"])
    .fmap { |token| Octokit::Client.new(access_token: token) }
    .or { Failure("Please set GITHUB_TOKEN environment variable") }
end

.search_query_for(options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/end_of_life/repository.rb', line 34

def search_query_for(options)
  query = "language:ruby"

  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

Instance Method Details

#eol_ruby?(at: Date.today) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/end_of_life/repository.rb', line 67

def eol_ruby?(at: Date.today)
  ruby_version&.eol?(at: at)
end

#ruby_versionObject



71
72
73
74
75
# File 'lib/end_of_life/repository.rb', line 71

def ruby_version
  return @ruby_version if defined?(@ruby_version)

  @ruby_version = ruby_versions.min
end