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
+ */
14
16
package com.google.firebase.gradle.plugins.report
15
17
16
18
import com.google.gson.Gson
@@ -25,23 +27,17 @@ import java.net.http.HttpClient
25
27
import java.net.http.HttpRequest
26
28
import java.net.http.HttpResponse
27
29
import java.time.Duration
28
- import java.util.Arrays
29
- import java.util.function.Function
30
30
import java.util.regex.Matcher
31
31
import java.util.regex.Pattern
32
- import java.util.stream.Collectors
33
32
import org.gradle.internal.Pair
34
33
35
34
@SuppressWarnings(" NewApi" )
36
35
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()
42
38
43
39
fun createReport (commitCount : Int ) {
44
- val response = request(" commits" , JsonArray ::class .java)
40
+ val response = request(" commits?per_page= $commitCount " , JsonArray ::class .java)
45
41
val commits =
46
42
response
47
43
.getAsJsonArray()
@@ -72,18 +68,15 @@ class UnitTestReport(private val apiToken: String) {
72
68
output.append(
73
69
generateTable(
74
70
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 },
76
72
)
77
73
)
78
74
output.append(" \n " )
79
75
output.append(" ### Instrumentation Tests\n\n " )
80
76
output.append(
81
77
generateTable(
82
78
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 },
87
80
)
88
81
)
89
82
output.append(" \n " )
@@ -98,16 +91,10 @@ class UnitTestReport(private val apiToken: String) {
98
91
}
99
92
100
93
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) })
111
98
val successPercentage: MutableMap <String , Int > = HashMap ()
112
99
var passingSdks = 0
113
100
// Get success percentage
@@ -132,10 +119,8 @@ class UnitTestReport(private val apiToken: String) {
132
119
}
133
120
sdks =
134
121
sdks
135
- .stream()
136
122
.filter { s: String? -> successPercentage[s] != 100 }
137
- .sorted(Comparator .comparing<String , Int > { o: String -> successPercentage[o]!! })
138
- .toList()
123
+ .sortedBy { o: String -> successPercentage[o]!! }
139
124
if (sdks.isEmpty()) {
140
125
return " *All tests passing*\n "
141
126
}
@@ -144,12 +129,7 @@ class UnitTestReport(private val apiToken: String) {
144
129
val rc = commitLookup.get(commit)
145
130
output.append(" " )
146
131
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} )" )
153
133
} else {
154
134
output.append(commit)
155
135
}
@@ -269,9 +249,7 @@ class UnitTestReport(private val apiToken: String) {
269
249
if (json is JsonObject ) {
270
250
// Retrieve and merge objects from other pages, if present
271
251
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() }
275
253
for (part in parts) {
276
254
if (part.endsWith(" rel=\" next\" " )) {
277
255
// <foo>; rel="next" -> foo
0 commit comments