Skip to content

Commit 98179ca

Browse files
committed
Adjustments
1 parent d62ba9e commit 98179ca

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

plugins/src/main/java/com/google/firebase/gradle/plugins/report/TestReport.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package com.google.firebase.gradle.plugins.report
1717

1818
/**
19-
* Represents a single run of a test in CI. One unit/implementation test workflow run creates many
19+
* Represents a single run of a test in CI. One unit/instrumentation test workflow run creates many
2020
* `TestReport`s, one for each tested SDK.
2121
*
2222
* @param name SDK name of the associated test run.

plugins/src/main/java/com/google/firebase/gradle/plugins/report/TestReportGenerator.kt

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import java.net.http.HttpClient
2222
import java.net.http.HttpRequest
2323
import java.net.http.HttpResponse
2424
import java.time.Duration
25-
import java.util.stream.Stream
2625
import kotlinx.serialization.json.Json
2726
import kotlinx.serialization.json.JsonArray
2827
import kotlinx.serialization.json.JsonElement
@@ -62,8 +61,6 @@ class TestReportGenerator(private val apiToken: String) {
6261
?.jsonObject
6362
?.get("nodes")
6463
?.jsonArray ?: throw RuntimeException("Missing fields in response: $response"))
65-
.stream()
66-
.limit(commitCount.toLong())
6764
.map { el: JsonElement ->
6865
val obj = el as JsonObject
6966
ReportCommit(
@@ -80,15 +77,11 @@ class TestReportGenerator(private val apiToken: String) {
8077
?.int ?: throw RuntimeException("Couldn't find PR number for commit $obj"),
8178
)
8279
}
83-
.toList()
8480
outputReport(commits)
8581
}
8682

8783
private fun outputReport(commits: List<ReportCommit>) {
88-
val reports: MutableList<TestReport> = mutableListOf()
89-
for (commit in commits) {
90-
reports.addAll(parseTestReports(commit.sha))
91-
}
84+
val reports = commits.flatMap { commit -> parseTestReports(commit.sha) }
9285
val output = StringBuilder()
9386
output.append("### Unit Tests\n\n")
9487
output.append(
@@ -114,20 +107,18 @@ class TestReportGenerator(private val apiToken: String) {
114107
}
115108
}
116109

117-
private fun generateTable(reportCommits: List<ReportCommit>, reports: List<TestReport>): String {
118-
val commitLookup = reportCommits.associateBy(ReportCommit::sha)
119-
val commits = reports.map(TestReport::commit).distinct()
120-
var sdks = reports.map(TestReport::name).distinct().sorted()
121-
val lookup = reports.associateBy({ report -> Pair.of(report.name, report.commit) })
110+
private fun calculateSuccess(
111+
sdks: List<String>,
112+
commits: List<String>,
113+
testLookup: Map<Pair<String, String>, TestReport>,
114+
): Map<String, Int> {
122115
val successPercentage: MutableMap<String, Int> = hashMapOf()
123-
var passingSdks = 0
124-
// Get success percentage
125116
for (sdk in sdks) {
126117
var sdkTestCount = 0
127118
var sdkTestSuccess = 0
128119
for (commit in commits) {
129-
if (lookup.containsKey(Pair.of(sdk, commit))) {
130-
val report: TestReport = lookup[Pair.of(sdk, commit)]!!
120+
if (testLookup.containsKey(Pair.of(sdk, commit))) {
121+
val report: TestReport = testLookup[Pair.of(sdk, commit)]!!
131122
if (report.status != TestReport.Status.OTHER) {
132123
sdkTestCount++
133124
if (report.status == TestReport.Status.SUCCESS) {
@@ -136,11 +127,17 @@ class TestReportGenerator(private val apiToken: String) {
136127
}
137128
}
138129
}
139-
if (sdkTestSuccess == sdkTestCount) {
140-
passingSdks++
141-
}
142130
successPercentage.put(sdk, sdkTestSuccess * 100 / sdkTestCount)
143131
}
132+
return successPercentage
133+
}
134+
135+
private fun generateTable(reportCommits: List<ReportCommit>, reports: List<TestReport>): String {
136+
val commitLookup = reportCommits.associateBy(ReportCommit::sha)
137+
val commits = reports.map(TestReport::commit).distinct()
138+
var sdks = reports.map(TestReport::name).distinct().sorted()
139+
val testLookup = reports.associateBy({ report -> Pair.of(report.name, report.commit) })
140+
val successPercentage = calculateSuccess(sdks, commits, testLookup)
144141
sdks =
145142
sdks
146143
.filter { s: String? -> successPercentage[s] != 100 }
@@ -166,8 +163,8 @@ class TestReportGenerator(private val apiToken: String) {
166163
for (sdk in sdks) {
167164
output.append("\n| $sdk |")
168165
for (commit in commits) {
169-
if (lookup.containsKey(Pair.of(sdk, commit))) {
170-
val report: TestReport = lookup[Pair.of(sdk, commit)]!!
166+
if (testLookup.containsKey(Pair.of(sdk, commit))) {
167+
val report: TestReport = testLookup[Pair.of(sdk, commit)]!!
171168
val icon =
172169
when (report.status) {
173170
TestReport.Status.SUCCESS -> ""
@@ -190,6 +187,7 @@ class TestReportGenerator(private val apiToken: String) {
190187
output.append(" |")
191188
}
192189
output.append("\n")
190+
val passingSdks = successPercentage.values.count { it == 100 }
193191
if (passingSdks > 0) {
194192
output.append("\n*+$passingSdks passing SDKs")
195193
}
@@ -309,7 +307,7 @@ class TestReportGenerator(private val apiToken: String) {
309307
}
310308
.uri(uri)
311309
.header("Authorization", "Bearer $apiToken")
312-
.header("X-GitHub-Api-Version", "2022-11-28")
310+
.header("X-GitHub-Api-Version", GITHUB_API_VERSION)
313311
.build()
314312
try {
315313
val response = client.send(request, HttpResponse.BodyHandlers.ofString())
@@ -347,11 +345,7 @@ class TestReportGenerator(private val apiToken: String) {
347345
json.keys.associateWith { key: String ->
348346
if (json[key] is JsonArray && p.containsKey(key) && p[key] is JsonArray) {
349347
return@associateWith JsonArray(
350-
Stream.concat(
351-
(json[key] as JsonArray).stream(),
352-
(p[key] as JsonArray).stream(),
353-
)
354-
.toList()
348+
(json[key] as JsonArray) + (p[key] as JsonArray)
355349
)
356350
}
357351
return@associateWith json[key]!!
@@ -373,5 +367,6 @@ class TestReportGenerator(private val apiToken: String) {
373367

374368
companion object {
375369
private const val URL_PREFIX = "https://api.github.com/repos/firebase/firebase-android-sdk/"
370+
private const val GITHUB_API_VERSION = "2022-11-28"
376371
}
377372
}

0 commit comments

Comments
 (0)