Class: Inq::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/inq/report.rb

Overview

Class for generating a report.

Instance Method Summary collapse

Constructor Details

#initialize(config, end_date) ⇒ Report

Returns a new instance of Report.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/inq/report.rb', line 17

def initialize(config, end_date)
  @config = config
  @repository = config["repository"]

  # NOTE: Use DateTime because it defaults to UTC and that's less gross
  #       than trying to get Date to use UTC.
  #
  #       Not using UTC for this results in #compare_url giving different
  #       results for different time zones, which makes it harder to test.
  #
  #       (I'm also guessing/hoping that GitHub's URLs use UTC.)
  end_dt = DateTime.strptime(end_date, "%Y-%m-%d")
  start_dt = start_dt_from_end_dt(end_dt)

  @end_date = end_dt.strftime("%Y-%m-%d")
  @start_date = start_dt.strftime("%Y-%m-%d")
end

Instance Method Details

#appveyorObject



55
56
57
# File 'lib/inq/report.rb', line 55

def appveyor
  @appveyor ||= Sources::CI::Appveyor.new(@config, @start_date, @end_date, cache)
end

#cacheObject



35
36
37
# File 'lib/inq/report.rb', line 35

def cache
  @cache ||= Cacheable.new(@config, @start_date, @end_date)
end

#contributionsObject



39
40
41
# File 'lib/inq/report.rb', line 39

def contributions
  @gh_contributions ||= Sources::Github::Contributions.new(@config, @start_date, @end_date, cache)
end

#issuesObject



43
44
45
# File 'lib/inq/report.rb', line 43

def issues
  @gh_issues ||= Sources::Github::Issues.new(@config, @start_date, @end_date, cache)
end

#pullsObject



47
48
49
# File 'lib/inq/report.rb', line 47

def pulls
  @gh_pulls ||= Sources::Github::Pulls.new(@config, @start_date, @end_date, cache)
end

#report_hashObject

rubocop:disable Metrics/AbcSize



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/inq/report.rb', line 104

def report_hash
  {
    title: "How is #{@repository}?",
    repository: @repository,

    contributions_summary: contributions.to_html,
    new_contributors: contributions.new_contributors_html,
    issues_summary: issues.to_html,
    pulls_summary: pulls.to_html,

    issues: issues.to_a,
    pulls: issues.to_a,

    average_issue_age: issues.average_age,
    average_pull_age:  pulls.average_age,

    oldest_issue_link: issues.oldest["url"],
    oldest_issue_date: issues.oldest["createdAt"],

    newest_issue_link: issues.newest["url"],
    newest_issue_date: issues.newest["createdAt"],

    newest_pull_link: pulls.newest["url"],
    newest_pull_date: pulls.newest["createdAt"],

    oldest_pull_link: pulls.oldest["url"],
    oldest_pull_date: pulls.oldest["createdAt"],

    travis_builds: travis.builds,
    appveyor_builds: appveyor.builds,

    date: @end_date,
  }
end

#save_as(filename) ⇒ Object



79
80
81
# File 'lib/inq/report.rb', line 79

def save_as(filename)
  File.write(filename, to_format_for(filename))
end

#start_dt_from_end_dt(end_dt) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/inq/report.rb', line 89

def start_dt_from_end_dt(end_dt)
  d = end_dt.day
  m = end_dt.month
  y = end_dt.year
  start_year = y
  start_month = m - 1
  if start_month <= 0
    start_month = 12 - start_month
    start_year -= 1
  end

  DateTime.new(start_year, start_month, d)
end

#to_h(frontmatter_data = nil) ⇒ Object



59
60
61
62
63
64
# File 'lib/inq/report.rb', line 59

def to_h(frontmatter_data = nil)
  @report_hash ||= report_hash
  frontmatter = Frontmatter.generate(frontmatter_data, @report_hash)

  @report_hash.merge(frontmatter: frontmatter)
end

#to_html(frontmatter = nil) ⇒ Object



70
71
72
73
# File 'lib/inq/report.rb', line 70

def to_html(frontmatter = nil)
  template_data = to_h(frontmatter).merge({report: to_html_partial})
  Inq::Template.apply("report.html", template_data)
end

#to_html_partial(frontmatter = nil) ⇒ Object



66
67
68
# File 'lib/inq/report.rb', line 66

def to_html_partial(frontmatter = nil)
  Inq::Template.apply("report_partial.html", to_h(frontmatter))
end

#to_json(frontmatter = nil) ⇒ Object



75
76
77
# File 'lib/inq/report.rb', line 75

def to_json(frontmatter = nil)
  frontmatter.to_s + JSON.pretty_generate(to_h)
end

#travisObject



51
52
53
# File 'lib/inq/report.rb', line 51

def travis
  @travis ||= Sources::CI::Travis.new(@config, @start_date, @end_date, cache)
end