class WhatTheGem::Gem::GitHub

Constants

CHANGELOG_PATTERN
Path

Attributes

repo_id[R]

Public Class Methods

new(repo_id) click to toggle source
# File lib/whatthegem/gem/github.rb, line 19
def initialize(repo_id)
  @repo_id = repo_id
end
octokit() click to toggle source
# File lib/whatthegem/gem/github.rb, line 8
        def octokit
  if (token = ENV['GITHUB_ACCESS_TOKEN'])
    Octokit::Client.new(access_token: token).tap { |client| client.user.login }
  else
    Octokit::Client.new
  end
end

Public Instance Methods

changelog() click to toggle source
# File lib/whatthegem/gem/github.rb, line 51
        def changelog
  locate_file(CHANGELOG_PATTERN)
end
closed_issues() click to toggle source
# File lib/whatthegem/gem/github.rb, line 37
        def closed_issues
  req(:issues, state: 'closed', per_page: 50)
end
contents(path = '.') click to toggle source
# File lib/whatthegem/gem/github.rb, line 45
def contents(path = '.')
  req(:contents, path: path)
end
Also aliased as: files
files(path = '.')
Alias for: contents
last_commit() click to toggle source
# File lib/whatthegem/gem/github.rb, line 29
        def last_commit
  req(:commits, per_page: 1).first
end
open_issues() click to toggle source
# File lib/whatthegem/gem/github.rb, line 33
        def open_issues
  req(:issues, state: 'open', per_page: 50)
end
readme() click to toggle source
# File lib/whatthegem/gem/github.rb, line 55
        def readme
  locate_file(/^readme(\.\w+)?$/i)
end
releases() click to toggle source
# File lib/whatthegem/gem/github.rb, line 41
        def releases
  req(:releases)
end
repo()
Alias for: repository
repository() click to toggle source
# File lib/whatthegem/gem/github.rb, line 23
        def repository
  req(:repository)
end
Also aliased as: repo

Private Instance Methods

decode_content(obj) click to toggle source
# File lib/whatthegem/gem/github.rb, line 84
def decode_content(obj)
  # TODO: encoding is specified as a part of the answer, could it be other than base64?
  Base64.decode64(obj.fetch(:content)).force_encoding('UTF-8')
end
locate_file(pattern) click to toggle source
# File lib/whatthegem/gem/github.rb, line 61
def locate_file(pattern)
  files.detect { |f| f.fetch(:name).match?(pattern) }
    &.fetch(:path)
    &.then { |path|
      Path.new(path, contents(path).then(&method(:decode_content)))
    }
end
octokit() click to toggle source
# File lib/whatthegem/gem/github.rb, line 89
def octokit
  self.class.octokit
end
req(method, *args) click to toggle source
# File lib/whatthegem/gem/github.rb, line 69
def req(method, *args)
  octokit.public_send(method, repo_id, *args).then(&method(:sawyer_to_hashes))
end
sawyer_to_hashes(val) click to toggle source
# File lib/whatthegem/gem/github.rb, line 73
def sawyer_to_hashes(val)
  case
  when val.respond_to?(:to_hash)
    val.to_hash.transform_values(&method(:sawyer_to_hashes))
  when val.respond_to?(:to_ary)
    val.to_ary.map(&method(:sawyer_to_hashes))
  else
    val
  end
end