Class: Onair::Report

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

Overview

What renderers consume. Pure domain logic — all IO goes through the injected git wrapper; render output must be derivable from this alone.

delta: :current, Integer (commits behind), or nil (diverged/unknown — silence over speculation). pinned: a newer build succeeded but is not what's running. mine: the local user's commit just below someone else's deployed head. commits: sha => CommitInfo (or nil when absent locally) for every sha a renderer may need to describe.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#commitsObject (readonly)

Returns the value of attribute commits

Returns:

  • (Object)

    the current value of commits



13
14
15
# File 'lib/onair/report.rb', line 13

def commits
  @commits
end

#deltaObject (readonly)

Returns the value of attribute delta

Returns:

  • (Object)

    the current value of delta



13
14
15
# File 'lib/onair/report.rb', line 13

def delta
  @delta
end

#mineObject (readonly)

Returns the value of attribute mine

Returns:

  • (Object)

    the current value of mine



13
14
15
# File 'lib/onair/report.rb', line 13

def mine
  @mine
end

#pinnedObject (readonly)

Returns the value of attribute pinned

Returns:

  • (Object)

    the current value of pinned



13
14
15
# File 'lib/onair/report.rb', line 13

def pinned
  @pinned
end

#remote_headObject (readonly)

Returns the value of attribute remote_head

Returns:

  • (Object)

    the current value of remote_head



13
14
15
# File 'lib/onair/report.rb', line 13

def remote_head
  @remote_head
end

#snapshotObject (readonly)

Returns the value of attribute snapshot

Returns:

  • (Object)

    the current value of snapshot



13
14
15
# File 'lib/onair/report.rb', line 13

def snapshot
  @snapshot
end

Class Method Details

.build(snapshot:, remote_head:, git:) ⇒ Object



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

def self.build(snapshot:, remote_head:, git:)
  # Pinned is judged before the stale pending is dropped: during the
  # stale window the newest *succeeded* build is still the previous
  # deploy, which must not read as a rollback.
  pinned = pinned?(snapshot)
  snapshot = drop_stale_pending(snapshot)
  deployed_sha = snapshot.deployed&.sha
  mine = compute_mine(snapshot, git)
  commits = [deployed_sha, snapshot.pending&.sha, mine&.sha].compact.uniq
                                                            .to_h { |sha| [sha, git.commit_info(sha)] }
  new(
    snapshot: snapshot,
    remote_head: remote_head,
    delta: compute_delta(deployed_sha, remote_head, git),
    pinned: pinned,
    mine: mine,
    commits: commits
  )
end