1/// Navigation destinations for a run without coverage (DESIGN.md D8).
2public struct UnavailableLinks: Sendable {
3 let runURL: String?
4 let previousReportPath: String?
5 let historyPath: String?
6
7 /// Links only to an available run that publishing will retain.
81 public init(runURL: String?, publishedRuns: [HistoryRun]) {
92 let previous = publishedRuns.filter { $0.totals.unavailable == nil }
101 .max { $0.totals.date < $1.totals.date }
111 self.init(
121 runURL: runURL, previousReportPath: previous.map { "../" + $0.folder + "/index.html" },
131 historyPath: "../index.html")
141 }
15
16 public init(
17 runURL: String? = nil, previousReportPath: String? = nil, historyPath: String? = nil
1812 ) {
1912 self.runURL = runURL
2012 self.previousReportPath = previousReportPath
2112 self.historyPath = historyPath
2212 }
23}
24
25/// The reason coverage is missing and links to the available results.
26public struct UnavailablePage: Sendable {
27 public static let sitePath = IndexPage.sitePath
28 public static let notice = "Coverage is not available for this commit."
29
30 private let links: UnavailableLinks
31 private let title: String
32 private let reason: String
33 private let commit: String?
34 private let subject: String?
35
36 /// - Parameters:
37 /// - title: the project's name, shown as given.
38 /// - reason: why there is no coverage; escaped, since CI supplies it.
39 /// - commit: the commit the run was built from, shown shortened.
40 /// - subject: the commit's first message line.
41 public init(
42 title: String, reason: String, commit: String?, subject: String?,
43 links: UnavailableLinks = UnavailableLinks()
4411 ) {
4511 self.links = links
4611 self.title = title
4711 self.reason = reason
4811 self.commit = commit
4911 self.subject = subject
5011 }
51
5211 public var html: String {
5311 """
5411 <!doctype html>
5511 <html lang="en">
5611 <head>
5711 <meta charset="utf-8">
5811 <meta name="viewport" content="width=device-width, initial-scale=1">
5911 <title>\(escapingHTML(title))</title>
6011 <link rel="stylesheet" href="\(SiteStylesheet.fileName)">
6111 </head>
6211 <body class="unavailable-page">
6311 <header class="page-header">
6411 \(SiteHeader(title: title, currentTab: .coverage, hasTestsPage: true, rootPath: "",
6511 run: ReportHeader(commit: commit, subject: subject, historyPath: links.historyPath)).html)
6611 </header>
6711 <main>
6811 <section class="card unavailable-card">
6911 <h2>Coverage unavailable</h2>
7011 <p class="notice">\(Self.notice)</p>
7111 <p class="reason">\(escapingHTML(reason))</p>
7211 \(linksMarkup)
7311 </section>
7411 </main>
7511 </body>
7611 </html>
7711
7811 """
7911 }
80
8111 private var linksMarkup: String {
8211 let ci =
8311 links.runURL.map { #"<p><a href="\#(escapingHTML($0))">View CI run</a></p>"# } ?? ""
8411 let previous =
8511 links.previousReportPath.map {
861 #"<p><a href="\#(escapingHTML($0))">Last run with coverage</a></p>"#
8710 } ?? "<p>No earlier run has data</p>"
8811 return ci + previous
8911 }
90}