Class: AnyGood

Inherits:
Object
  • Object
show all
Defined in:
lib/any_good.rb,
lib/any_good/meters.rb

Defined Under Namespace

Classes: Meter, Metric

Constant Summary collapse

GITHUB_URI_PATTERN =
%r{^https?://(www\.)?github\.com/}
T =
TimeMath

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AnyGood

Returns a new instance of AnyGood.



11
12
13
14
15
16
17
18
19
# File 'lib/any_good.rb', line 11

def initialize(name)
  @name = name
  @github_client =
    if (token = ENV['GITHUB_ACCESS_TOKEN'])
      Octokit::Client.new(access_token: token).tap { |client| client.user. }
    else
      Octokit::Client.new
    end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/any_good.rb', line 9

def name
  @name
end

Class Method Details

.metersObject



58
59
60
# File 'lib/any_good.rb', line 58

def self.meters
  @meters ||= []
end

.metric(name, thresholds: nil, &block) ⇒ Object



62
63
64
# File 'lib/any_good.rb', line 62

def self.metric(name, thresholds: nil, &block)
  meters << Meter.new(name, thresholds, block)
end

Instance Method Details

#fetchObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/any_good.rb', line 23

def fetch
  data = {
    gem: Gems.info(name),
    gem_versions: Gems.versions(name),
    gem_rev_deps: Gems.reverse_dependencies(name)
  }

  repo_id = [data[:gem]['source_code_uri'], data[:gem]['homepage_uri']]
    .grep(GITHUB_URI_PATTERN).first&.sub(GITHUB_URI_PATTERN, '')

  if repo_id
    data.merge!(
      repo: @github_client.repository(repo_id).to_h,
      open_issues: @github_client.issues(repo_id, state: 'open', per_page: 50).map(&:to_h),
      closed_issues: @github_client.issues(repo_id, state: 'closed', per_page: 50).map(&:to_h),
      last_commit: @github_client.commits(repo_id, per_page: 1).first.to_h
      # open_prs: @github_client.issues(repo_id, state: 'open').map(&:to_h)
      # closed_prs: @github_client.issues(repo_id, state: 'closed').map(&:to_h)
    )
  end

  @data = OpenStruct.new(data)

  self
end

#reportObject



49
50
51
52
53
54
# File 'lib/any_good.rb', line 49

def report
  self.class.meters.each do |meter|
    puts meter.call(@data).format
  end
  self
end