Skip to content

Commit e157a9f

Browse files
committed
Clean up
1 parent a5919ea commit e157a9f

File tree

3 files changed

+58
-77
lines changed

3 files changed

+58
-77
lines changed
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
// Copyright 2025 Google LLC
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1416
package com.google.firebase.gradle.plugins.report
1517

16-
@JvmRecord data class ReportCommit(val sha: String, val pr: Int)
18+
data class ReportCommit(val sha: String, val pr: Int)

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
// Copyright 2025 Google LLC
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1416
package com.google.firebase.gradle.plugins.report
1517

16-
@JvmRecord
1718
data class TestReport(
1819
val name: String,
1920
val type: Type,

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

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
// Copyright 2025 Google LLC
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1416
package com.google.firebase.gradle.plugins.report
1517

1618
import com.google.gson.Gson
@@ -25,23 +27,17 @@ import java.net.http.HttpClient
2527
import java.net.http.HttpRequest
2628
import java.net.http.HttpResponse
2729
import java.time.Duration
28-
import java.util.Arrays
29-
import java.util.function.Function
3030
import java.util.regex.Matcher
3131
import java.util.regex.Pattern
32-
import java.util.stream.Collectors
3332
import org.gradle.internal.Pair
3433

3534
@SuppressWarnings("NewApi")
3635
class UnitTestReport(private val apiToken: String) {
37-
private val client: HttpClient
38-
39-
init {
40-
this.client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build()
41-
}
36+
private val client: HttpClient =
37+
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build()
4238

4339
fun createReport(commitCount: Int) {
44-
val response = request("commits", JsonArray::class.java)
40+
val response = request("commits?per_page=$commitCount", JsonArray::class.java)
4541
val commits =
4642
response
4743
.getAsJsonArray()
@@ -72,18 +68,15 @@ class UnitTestReport(private val apiToken: String) {
7268
output.append(
7369
generateTable(
7470
commits,
75-
reports.stream().filter { r: TestReport -> r.type == TestReport.Type.UNIT_TEST }.toList(),
71+
reports.filter { r: TestReport -> r.type == TestReport.Type.UNIT_TEST },
7672
)
7773
)
7874
output.append("\n")
7975
output.append("### Instrumentation Tests\n\n")
8076
output.append(
8177
generateTable(
8278
commits,
83-
reports
84-
.stream()
85-
.filter { r: TestReport -> r.type == TestReport.Type.INSTRUMENTATION_TEST }
86-
.toList(),
79+
reports.filter { r: TestReport -> r.type == TestReport.Type.INSTRUMENTATION_TEST },
8780
)
8881
)
8982
output.append("\n")
@@ -98,16 +91,10 @@ class UnitTestReport(private val apiToken: String) {
9891
}
9992

10093
private fun generateTable(reportCommits: List<ReportCommit>, reports: List<TestReport>): String {
101-
val commitLookup =
102-
reportCommits
103-
.stream()
104-
.collect(Collectors.toMap(ReportCommit::sha, Function { c: ReportCommit? -> c }))
105-
val commits = reports.stream().map(TestReport::commit).distinct().toList()
106-
var sdks = reports.stream().map(TestReport::name).distinct().sorted().toList()
107-
val lookup: MutableMap<Pair<String, String>, TestReport> = HashMap()
108-
for (report in reports) {
109-
lookup.put(Pair.of(report.name, report.commit), report)
110-
}
94+
val commitLookup = reportCommits.associateBy(ReportCommit::sha)
95+
val commits = reports.map(TestReport::commit).distinct()
96+
var sdks = reports.map(TestReport::name).distinct().sorted()
97+
val lookup = reports.associateBy({ report -> Pair.of(report.name, report.commit) })
11198
val successPercentage: MutableMap<String, Int> = HashMap()
11299
var passingSdks = 0
113100
// Get success percentage
@@ -132,10 +119,8 @@ class UnitTestReport(private val apiToken: String) {
132119
}
133120
sdks =
134121
sdks
135-
.stream()
136122
.filter { s: String? -> successPercentage[s] != 100 }
137-
.sorted(Comparator.comparing<String, Int> { o: String -> successPercentage[o]!! })
138-
.toList()
123+
.sortedBy { o: String -> successPercentage[o]!! }
139124
if (sdks.isEmpty()) {
140125
return "*All tests passing*\n"
141126
}
@@ -144,12 +129,7 @@ class UnitTestReport(private val apiToken: String) {
144129
val rc = commitLookup.get(commit)
145130
output.append(" ")
146131
if (rc != null && rc.pr != -1) {
147-
output
148-
.append("[#")
149-
.append(rc.pr)
150-
.append("](https://github.com/firebase/firebase-android-sdk/pull/")
151-
.append(rc.pr)
152-
.append(")")
132+
output.append("[#${rc.pr}](https://github.com/firebase/firebase-android-sdk/pull/${rc.pr})")
153133
} else {
154134
output.append(commit)
155135
}
@@ -269,9 +249,7 @@ class UnitTestReport(private val apiToken: String) {
269249
if (json is JsonObject) {
270250
// Retrieve and merge objects from other pages, if present
271251
response.headers().firstValue("Link").ifPresent { link: String ->
272-
val parts =
273-
Arrays.stream(link.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray())
274-
.toList()
252+
val parts = link.split(",".toRegex()).dropLastWhile { it.isEmpty() }
275253
for (part in parts) {
276254
if (part.endsWith("rel=\"next\"")) {
277255
// <foo>; rel="next" -> foo

0 commit comments

Comments
 (0)