| 1 | | /// Navigation destinations for a run without coverage (DESIGN.md D8). |
| 2 | | public 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. |
| 8 | 1 | public init(runURL: String?, publishedRuns: [HistoryRun]) { |
| 9 | 2 | let previous = publishedRuns.filter { $0.totals.unavailable == nil } |
| 10 | 1 | .max { $0.totals.date < $1.totals.date } |
| 11 | 1 | self.init( |
| 12 | 1 | runURL: runURL, previousReportPath: previous.map { "../" + $0.folder + "/index.html" }, |
| 13 | 1 | historyPath: "../index.html") |
| 14 | 1 | } |
| 15 | | |
| 16 | | public init( |
| 17 | | runURL: String? = nil, previousReportPath: String? = nil, historyPath: String? = nil |
| 18 | 12 | ) { |
| 19 | 12 | self.runURL = runURL |
| 20 | 12 | self.previousReportPath = previousReportPath |
| 21 | 12 | self.historyPath = historyPath |
| 22 | 12 | } |
| 23 | | } |
| 24 | | |
| 25 | | /// The reason coverage is missing and links to the available results. |
| 26 | | public 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() |
| 44 | 11 | ) { |
| 45 | 11 | self.links = links |
| 46 | 11 | self.title = title |
| 47 | 11 | self.reason = reason |
| 48 | 11 | self.commit = commit |
| 49 | 11 | self.subject = subject |
| 50 | 11 | } |
| 51 | | |
| 52 | 11 | public var html: String { |
| 53 | 11 | """ |
| 54 | 11 | <!doctype html> |
| 55 | 11 | <html lang="en"> |
| 56 | 11 | <head> |
| 57 | 11 | <meta charset="utf-8"> |
| 58 | 11 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 59 | 11 | <title>\(escapingHTML(title))</title> |
| 60 | 11 | <link rel="stylesheet" href="\(SiteStylesheet.fileName)"> |
| 61 | 11 | </head> |
| 62 | 11 | <body class="unavailable-page"> |
| 63 | 11 | <header class="page-header"> |
| 64 | 11 | \(SiteHeader(title: title, currentTab: .coverage, hasTestsPage: true, rootPath: "", |
| 65 | 11 | run: ReportHeader(commit: commit, subject: subject, historyPath: links.historyPath)).html) |
| 66 | 11 | </header> |
| 67 | 11 | <main> |
| 68 | 11 | <section class="card unavailable-card"> |
| 69 | 11 | <h2>Coverage unavailable</h2> |
| 70 | 11 | <p class="notice">\(Self.notice)</p> |
| 71 | 11 | <p class="reason">\(escapingHTML(reason))</p> |
| 72 | 11 | \(linksMarkup) |
| 73 | 11 | </section> |
| 74 | 11 | </main> |
| 75 | 11 | </body> |
| 76 | 11 | </html> |
| 77 | 11 | |
| 78 | 11 | """ |
| 79 | 11 | } |
| 80 | | |
| 81 | 11 | private var linksMarkup: String { |
| 82 | 11 | let ci = |
| 83 | 11 | links.runURL.map { #"<p><a href="\#(escapingHTML($0))">View CI run</a></p>"# } ?? "" |
| 84 | 11 | let previous = |
| 85 | 11 | links.previousReportPath.map { |
| 86 | 1 | #"<p><a href="\#(escapingHTML($0))">Last run with coverage</a></p>"# |
| 87 | 10 | } ?? "<p>No earlier run has data</p>" |
| 88 | 11 | return ci + previous |
| 89 | 11 | } |
| 90 | | } |