Skip to content

Commit 1aaee4b

Browse files
committed
Move to Qute for report rendering
1 parent 41b9762 commit 1aaee4b

File tree

6 files changed

+224
-36
lines changed

6 files changed

+224
-36
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
<groupId>io.quarkus</groupId>
9191
<artifactId>quarkus-smallrye-health</artifactId>
9292
</dependency>
93+
<dependency>
94+
<groupId>io.quarkus</groupId>
95+
<artifactId>quarkus-qute</artifactId>
96+
</dependency>
9397
<dependency>
9498
<groupId>io.quarkus</groupId>
9599
<artifactId>quarkus-cache</artifactId>

src/main/java/org/hibernate/infra/bot/ExtractDevelocityBuildScans.java

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.hibernate.infra.bot.config.DeploymentConfig;
1212
import org.hibernate.infra.bot.config.RepositoryConfig;
1313
import org.hibernate.infra.bot.develocity.DevelocityCIBuildScan;
14+
import org.hibernate.infra.bot.develocity.DevelocityReportFormatter;
1415

1516
import com.gradle.develocity.api.BuildsApi;
1617
import com.gradle.develocity.model.Build;
@@ -37,6 +38,9 @@ public class ExtractDevelocityBuildScans {
3738
@RestClient
3839
BuildsApi develocityBuildsApi;
3940

41+
@Inject
42+
DevelocityReportFormatter reportFormatter;
43+
4044
void checkRunRerequested(@CheckRun.Rerequested GHEventPayload.CheckRun payload) {
4145
var repository = payload.getRepository();
4246
var checkRun = payload.getCheckRun();
@@ -185,7 +189,7 @@ private void updateDevelocityCheck(GHRepository repository, long checkId,
185189
throws IOException {
186190
String formattedBuildScanList = "";
187191
try {
188-
formattedBuildScanList = formatBuildScanList( buildScans );
192+
formattedBuildScanList = reportFormatter.summary( buildScans );
189193
}
190194
catch (RuntimeException e) {
191195
if ( failure == null ) {
@@ -226,39 +230,4 @@ private void updateDevelocityCheck(GHRepository repository, long checkId,
226230
.create();
227231
}
228232

229-
private String formatBuildScanList(List<DevelocityCIBuildScan> buildScans) {
230-
if ( buildScans == null || buildScans.isEmpty() ) {
231-
return "No build scan found for this CI run.";
232-
}
233-
234-
StringBuilder summary = new StringBuilder();
235-
summary.append( "\n\n| Status | Job/Workflow | Tags | Goals | Build Scan | Tests | Logs |\n" );
236-
summary.append( "| :-: | -- | -- | -- | :-: | :-: | :-: |\n" );
237-
for ( DevelocityCIBuildScan buildScan : buildScans ) {
238-
summary.append(
239-
"| [%s](%s) | `%s` | `%s` | `%s` | [:mag:](%s) | [%s](%s) | [:page_with_curl:](%s) |\n"
240-
.formatted(
241-
statusToEmoji( buildScan.status() ),
242-
switch ( buildScan.status() ) {
243-
case SUCCESS -> buildScan.buildScanUri();
244-
case FAILURE -> buildScan.failuresUri();
245-
},
246-
String.join( " ", buildScan.jobOrWorkflow(), buildScan.stage() ),
247-
String.join( "` `", buildScan.tags() ),
248-
String.join( " ", buildScan.goals() ),
249-
buildScan.buildScanUri(),
250-
statusToEmoji( buildScan.testStatus() ),
251-
buildScan.testsUri(),
252-
buildScan.logsUri()
253-
) );
254-
}
255-
return summary.toString();
256-
}
257-
258-
private String statusToEmoji(DevelocityCIBuildScan.Status status) {
259-
return switch ( status ) {
260-
case SUCCESS -> ":white_check_mark:";
261-
case FAILURE -> ":x:";
262-
};
263-
}
264233
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.hibernate.infra.bot.develocity;
2+
3+
import java.net.URI;
4+
import java.util.List;
5+
import java.util.stream.Collectors;
6+
7+
import jakarta.enterprise.context.ApplicationScoped;
8+
9+
import io.quarkus.qute.CheckedTemplate;
10+
import io.quarkus.qute.TemplateExtension;
11+
import io.quarkus.qute.TemplateInstance;
12+
13+
@ApplicationScoped
14+
public class DevelocityReportFormatter {
15+
16+
public String summary(List<DevelocityCIBuildScan> buildScans) {
17+
return Templates.summary( buildScans )
18+
.render();
19+
}
20+
21+
@CheckedTemplate
22+
private static class Templates {
23+
public static native TemplateInstance summary(List<DevelocityCIBuildScan> buildScans);
24+
}
25+
26+
@TemplateExtension
27+
@SuppressWarnings("unused")
28+
private static class TemplateExtensions {
29+
30+
static String backQuoted(String content) {
31+
return content == null || content.isBlank() ? null : '`' + content + '`';
32+
}
33+
34+
static List<String> backQuoted(List<String> content) {
35+
return content.stream()
36+
.map( TemplateExtensions::backQuoted )
37+
.toList();
38+
}
39+
40+
static String spaceDelimited(List<String> content) {
41+
return content.stream()
42+
.filter( s -> s != null && !s.isBlank() )
43+
.collect( Collectors.joining( " " ) );
44+
}
45+
46+
static URI statusUri(DevelocityCIBuildScan buildScan) {
47+
return switch ( buildScan.status() ) {
48+
case SUCCESS -> buildScan.buildScanUri();
49+
case FAILURE -> buildScan.failuresUri();
50+
};
51+
}
52+
53+
static String emoji(DevelocityCIBuildScan.Status status) {
54+
return switch ( status ) {
55+
case SUCCESS -> ":white_check_mark:";
56+
case FAILURE -> ":x:";
57+
};
58+
}
59+
}
60+
61+
@TemplateExtension(namespace = "list")
62+
@SuppressWarnings("unused")
63+
private static class ListTemplateExtensions {
64+
static List<String> create(String... content) {
65+
return List.of( content );
66+
}
67+
}
68+
}

src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ quarkus.application.name=hibernate-github-bot
33
quarkus.management.enabled=true
44
quarkus.info.enabled=true
55

6+
quarkus.qute.suffixes=md
7+
quarkus.qute.content-types."md"=text/markdown
8+
69
quarkus.cache.caffeine."glob-cache".maximum-size=200
710

811
quarkus.jib.base-jvm-image=openjdk:17.0.1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{#if buildScans == null || buildScans.empty}
2+
No build scan found for this CI run.
3+
{#else}
4+
| Status | Job/Workflow | Tags | Goals | Build Scan | Tests | Logs |
5+
| :-: | -- | -- | -- | :-: | :-: | :-: |
6+
{#for buildScan in buildScans}
7+
|[{buildScan.status.emoji}]({buildScan.statusUri}){!
8+
!}|{list:create(buildScan.jobOrWorkflow, buildScan.stage).spaceDelimited.backQuoted}{!
9+
!}|{buildScan.tags.backQuoted.spaceDelimited}{!
10+
!}|{buildScan.goals.spaceDelimited.backQuoted}{!
11+
!}|[:mag:]({buildScan.buildScanUri}){!
12+
!}|[{buildScan.testStatus.emoji}]({buildScan.testsUri}){!
13+
!}|[:page_with_curl:]({buildScan.logsUri}){!
14+
!}|
15+
{/for}
16+
{/if}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
*
3+
* * Hibernate Search, full-text search for your domain model
4+
* *
5+
* * License: GNU Lesser General Public License (LGPL), version 2.1 or later
6+
* * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
7+
*
8+
*/
9+
package org.hibernate.infra.bot.develocity;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
import java.net.URI;
14+
import java.util.List;
15+
16+
import jakarta.inject.Inject;
17+
18+
import org.junit.jupiter.api.Test;
19+
20+
import io.quarkus.test.junit.QuarkusTest;
21+
22+
@QuarkusTest
23+
class DevelocityReportFormatterTest {
24+
25+
@Inject
26+
DevelocityReportFormatter formatter;
27+
28+
@Test
29+
void summary_simple() {
30+
var buildScans = List.of(
31+
buildScanStub( "GitHub", "GitHub Actions Build", "",
32+
List.of( "Linux", "hibernate-search", "jdk-17", "main" ),
33+
List.of( "clean install" ),
34+
DevelocityCIBuildScan.Status.SUCCESS,
35+
DevelocityCIBuildScan.Status.SUCCESS ),
36+
buildScanStub( "GitHub", "GitHub Actions Build", "",
37+
List.of( "Linux", "elasticsearch", "elasticsearch-8.13", "h2", "hibernate-search", "jdk-17", "lucene",
38+
"main" ),
39+
List.of( "clean install" ),
40+
DevelocityCIBuildScan.Status.SUCCESS,
41+
DevelocityCIBuildScan.Status.SUCCESS ),
42+
buildScanStub( "GitHub", "GitHub Actions Build", "",
43+
List.of( "Windows Server 2022", "hibernate-search", "jdk-17", "main" ),
44+
List.of( "clean install" ),
45+
DevelocityCIBuildScan.Status.SUCCESS,
46+
DevelocityCIBuildScan.Status.SUCCESS ),
47+
buildScanStub( "GitHub", "GitHub Actions Build", "",
48+
List.of( "Windows Server 2022", "h2", "hibernate-search", "jdk-17", "lucene", "main" ),
49+
List.of( "clean install" ),
50+
DevelocityCIBuildScan.Status.SUCCESS,
51+
DevelocityCIBuildScan.Status.SUCCESS ),
52+
buildScanStub( "Jenkins", "hibernate-search/PR-4125", "Default build",
53+
List.of( "Linux", "hibernate-search", "jdk-17", "PR-4125" ),
54+
List.of( "clean install" ),
55+
DevelocityCIBuildScan.Status.SUCCESS,
56+
DevelocityCIBuildScan.Status.SUCCESS ),
57+
buildScanStub( "Jenkins", "hibernate-search/PR-4125", "Default build",
58+
List.of( "Linux", "elasticsearch", "elasticsearch-8.13", "h2", "hibernate-search", "jdk-17", "lucene" ),
59+
List.of( "clean verify" ),
60+
DevelocityCIBuildScan.Status.FAILURE,
61+
DevelocityCIBuildScan.Status.FAILURE )
62+
);
63+
assertThat( formatter.summary( buildScans ) )
64+
.isEqualTo( """
65+
| Status | Job/Workflow | Tags | Goals | Build Scan | Tests | Logs |
66+
| :-: | -- | -- | -- | :-: | :-: | :-: |
67+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
68+
|`GitHub Actions Build`\
69+
|`Linux` `hibernate-search` `jdk-17` `main`\
70+
|`clean install`\
71+
|[:mag:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
72+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy/tests)\
73+
|[:page_with_curl:](https://ge.hibernate.org/s/45fv2rr67ofuy/console-log)\
74+
|
75+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
76+
|`GitHub Actions Build`\
77+
|`Linux` `elasticsearch` `elasticsearch-8.13` `h2` `hibernate-search` `jdk-17` `lucene` `main`\
78+
|`clean install`\
79+
|[:mag:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
80+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy/tests)\
81+
|[:page_with_curl:](https://ge.hibernate.org/s/45fv2rr67ofuy/console-log)\
82+
|
83+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
84+
|`GitHub Actions Build`\
85+
|`Windows Server 2022` `hibernate-search` `jdk-17` `main`\
86+
|`clean install`\
87+
|[:mag:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
88+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy/tests)\
89+
|[:page_with_curl:](https://ge.hibernate.org/s/45fv2rr67ofuy/console-log)\
90+
|
91+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
92+
|`GitHub Actions Build`\
93+
|`Windows Server 2022` `h2` `hibernate-search` `jdk-17` `lucene` `main`\
94+
|`clean install`\
95+
|[:mag:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
96+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy/tests)\
97+
|[:page_with_curl:](https://ge.hibernate.org/s/45fv2rr67ofuy/console-log)\
98+
|
99+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
100+
|`hibernate-search/PR-4125 Default build`\
101+
|`Linux` `hibernate-search` `jdk-17` `PR-4125`\
102+
|`clean install`\
103+
|[:mag:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
104+
|[:white_check_mark:](https://ge.hibernate.org/s/45fv2rr67ofuy/tests)\
105+
|[:page_with_curl:](https://ge.hibernate.org/s/45fv2rr67ofuy/console-log)\
106+
|
107+
|[:x:](https://ge.hibernate.org/s/45fv2rr67ofuy/failures)\
108+
|`hibernate-search/PR-4125 Default build`\
109+
|`Linux` `elasticsearch` `elasticsearch-8.13` `h2` `hibernate-search` `jdk-17` `lucene`\
110+
|`clean verify`\
111+
|[:mag:](https://ge.hibernate.org/s/45fv2rr67ofuy)\
112+
|[:x:](https://ge.hibernate.org/s/45fv2rr67ofuy/tests)\
113+
|[:page_with_curl:](https://ge.hibernate.org/s/45fv2rr67ofuy/console-log)\
114+
|
115+
""" );
116+
}
117+
118+
private DevelocityCIBuildScan buildScanStub(String provider, String jobOrWorkflow, String stage, List<String> tags,
119+
List<String> goals, DevelocityCIBuildScan.Status status, DevelocityCIBuildScan.Status testStatus) {
120+
return new DevelocityCIBuildScan( provider, jobOrWorkflow, stage, 0L,
121+
tags, goals, status, testStatus,
122+
URI.create( "https://ge.hibernate.org/s/45fv2rr67ofuy" ),
123+
URI.create( "https://ge.hibernate.org/s/45fv2rr67ofuy/failures" ),
124+
URI.create( "https://ge.hibernate.org/s/45fv2rr67ofuy/tests" ),
125+
URI.create( "https://ge.hibernate.org/s/45fv2rr67ofuy/console-log" ) );
126+
}
127+
128+
}

0 commit comments

Comments
 (0)