Class: Inq::Sources::Github::Issues

Inherits:
Object
  • Object
show all
Includes:
DateTimeHelpers, Inq::Sources::GithubHelpers
Defined in:
lib/inq/sources/github/issues.rb

Overview

Fetches various information about GitHub Issues.

Direct Known Subclasses

Pulls

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inq::Sources::GithubHelpers

#average_age_for, #newest_for, #obj_to_array_of_hashes, #oldest_for, #sort_iops_by_created_at

Methods included from DateTimeHelpers

#date_ge, #date_le

Constructor Details

#initialize(config, start_date, end_date, cache) ⇒ Issues

Returns a new instance of Issues.

Parameters:

  • repository (String)

    GitHub repository name, of the format user/repo.

  • start_date (String)

    Start date for the report being generated.

  • end_date (String)

    End date for the report being generated.

  • cache (Cacheable)

    Instance of Inq::Cacheable to cache API calls



25
26
27
28
29
30
31
32
# File 'lib/inq/sources/github/issues.rb', line 25

def initialize(config, start_date, end_date, cache)
  @config = config
  @cache = cache
  @repository = config["repository"]
  raise "#{self.class}.new() got nil repository." if @repository.nil?
  @start_date = start_date
  @end_date = end_date
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



19
20
21
# File 'lib/inq/sources/github/issues.rb', line 19

def cache
  @cache
end

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/inq/sources/github/issues.rb', line 19

def config
  @config
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



19
20
21
# File 'lib/inq/sources/github/issues.rb', line 19

def end_date
  @end_date
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



19
20
21
# File 'lib/inq/sources/github/issues.rb', line 19

def start_date
  @start_date
end

Instance Method Details

#average_ageObject



49
50
51
# File 'lib/inq/sources/github/issues.rb', line 49

def average_age
  average_age_for(data)
end

#newestObject



62
63
64
65
66
67
68
69
# File 'lib/inq/sources/github/issues.rb', line 62

def newest
  result = newest_for(data)
  return {} if result.nil?

  result["date"] = pretty_date(result["createdAt"])

  result
end

#oldestObject



53
54
55
56
57
58
59
60
# File 'lib/inq/sources/github/issues.rb', line 53

def oldest
  result = oldest_for(data)
  return {} if result.nil?

  result["date"] = pretty_date(result["createdAt"])

  result
end

#pretty_typeObject



103
104
105
# File 'lib/inq/sources/github/issues.rb', line 103

def pretty_type
  "issue"
end

#summaryObject



71
72
73
74
75
76
77
# File 'lib/inq/sources/github/issues.rb', line 71

def summary
  number_open = to_a.length
  pretty_number = pluralize(pretty_type, number_open, zero_is_no: false)
  was_were = (number_open == 1) ? "was" : "were"

  "<p>A total of <a href=\"#{url}\">#{pretty_number}</a> #{was_were} opened during this period.</p>"
end

#to_aObject



95
96
97
# File 'lib/inq/sources/github/issues.rb', line 95

def to_a
  obj_to_array_of_hashes(data)
end

#to_htmlObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/inq/sources/github/issues.rb', line 79

def to_html
  return summary if to_a.empty?

  Inq::Template.apply("issues_or_pulls_partial.html", {
    summary: summary,
    average_age: average_age,
    pretty_type: pretty_type,

    oldest_link: oldest["url"],
    oldest_date: oldest["date"],

    newest_link: newest["url"],
    newest_date: newest["date"],
  })
end

#typeObject



99
100
101
# File 'lib/inq/sources/github/issues.rb', line 99

def type
  singular_type + "s"
end

#url(values = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/inq/sources/github/issues.rb', line 34

def url(values = {})
  defaults = {
    "is" => singular_type,
    "created" => "#{@start_date}..#{@end_date}",
  }
  values = defaults.merge(values)
  raw_query = values.map { |k, v|
    [k, v].join(":")
  }.join(" ")

  query = CGI.escape(raw_query)

  "https://github.com/#{@repository}/#{url_suffix}?q=#{query}"
end