Class: HowIs::Fetcher

Inherits:
Object
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/how_is/fetcher.rb

Overview

Fetches data from GitHub.

Defined Under Namespace

Classes: Results

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_github_instanceObject

TODO: Fix this bullshit. :nodoc:



17
18
19
20
21
# File 'lib/how_is/fetcher.rb', line 17

def self.default_github_instance
  Github.new(auto_pagination: true) do |config|
    config.basic_auth = ENV["HOWIS_BASIC_AUTH"] if ENV["HOWIS_BASIC_AUTH"]
  end
end

Instance Method Details

#call(repository, github = nil, pulse = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/how_is/fetcher.rb', line 45

def call(repository,
         github = nil,
         pulse = nil)
  github ||= self.class.default_github_instance
  pulse ||= HowIs::Pulse.new(repository)
  user, repo = repository.split("/", 2)

  unless user && repo
    raise HowIs::CLI::OptionsError, "To generate a report from GitHub, " \
      "provide the repository " \
      "username/project. Quitting!"
  end

  issues  = github.issues.list user: user, repo: repo
  pulls   = github.pulls.list  user: user, repo: repo

  summary = pulse.html_summary

  Results.new(
    repository,
    obj_to_array_of_hashes(issues),
    obj_to_array_of_hashes(pulls),
    summary
  )
end

#StringObject

Fetches repository information from GitHub and returns a Results object.



42
43
44
# File 'lib/how_is/fetcher.rb', line 42

Contract String,
C::Or[C::RespondTo[:issues, :pulls], nil],
C::Or[C::RespondTo[:html_summary], nil] => Results