Class: Debci::HTML::JSON

Inherits:
Rooted
  • Object
show all
Defined in:
lib/debci/html.rb

Instance Attribute Summary collapse

Attributes inherited from Rooted

#datadir, #root

Instance Method Summary collapse

Constructor Details

#initialize(suite, arch) ⇒ JSON

Returns a new instance of JSON.



45
46
47
48
49
50
# File 'lib/debci/html.rb', line 45

def initialize(suite, arch)
  @datadir = 'status'
  super()
  self.suite = suite
  self.arch = arch
end

Instance Attribute Details

#archObject

Returns the value of attribute arch.



43
44
45
# File 'lib/debci/html.rb', line 43

def arch
  @arch
end

#suiteObject

Returns the value of attribute suite.



43
44
45
# File 'lib/debci/html.rb', line 43

def suite
  @suite
end

Instance Method Details

#historyObject



84
85
86
87
88
89
90
# File 'lib/debci/html.rb', line 84

def history
  status_history = (root / suite / arch).glob('[0-9]*/[0-9]*/[0-9]*.json')
  status_history_data = status_history.sort.map { |f| ::JSON.parse(f.read) }

  h = root / suite / arch / 'history.json'
  h.write(::JSON.pretty_generate(status_history_data))
end

#packagesObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/debci/html.rb', line 92

def packages
  p = root / suite / arch / 'packages.json'
  data = []
  status_packages_data.includes(job: :package).in_batches do |batch|
    batch.each do |status|
      data << status.job.public_api_attributes
    end
  end
  p.write(::JSON.pretty_generate(data.as_json))
end

#statusObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/debci/html.rb', line 57

def status
  data = {
    pass: 0,
    fail: 0,
    neutral: 0,
    tmpfail: 0,
    total: 0,
  }
  status_packages_data.in_batches.each do |batch|
    batch.each do |package_status|
      status = package_status.job.status
      data[status.to_sym] += 1
      data[:total] += 1
    end
  end
  data[:date] = Time.now.strftime('%Y-%m-%dT%H:%M:%S')

  output = ::JSON.pretty_generate(data)

  today = root / suite / arch / Time.now.strftime('%Y/%m/%d.json')
  today.parent.mkpath
  today.write(output)

  current = root / suite / arch / 'status.json'
  current.write(output)
end

#status_packages_dataObject



52
53
54
55
# File 'lib/debci/html.rb', line 52

def status_packages_data
  @status_packages_data ||=
    Debci::PackageStatus.where(suite: suite, arch: arch).includes(:job)
end