88import java .util .Map ;
99
1010public class RenderScreenshotReport {
11- private static final String MARKER = "<!-- CN1SS_SCREENSHOT_COMMENT -->" ;
11+ private static final String DEFAULT_MARKER = "<!-- CN1SS_SCREENSHOT_COMMENT -->" ;
12+ private static final String DEFAULT_TITLE = "Android screenshot updates" ;
13+ private static final String DEFAULT_SUCCESS_MESSAGE = "✅ Native Android screenshot tests passed." ;
1214
1315 public static void main (String [] args ) throws Exception {
1416 Arguments arguments = Arguments .parse (args );
@@ -24,7 +26,11 @@ public static void main(String[] args) throws Exception {
2426 String text = Files .readString (comparePath , StandardCharsets .UTF_8 );
2527 Object parsed = JsonUtil .parse (text );
2628 Map <String , Object > data = JsonUtil .asObject (parsed );
27- SummaryAndComment output = buildSummaryAndComment (data );
29+ String marker = arguments .marker != null ? arguments .marker : DEFAULT_MARKER ;
30+ String title = arguments .title != null ? arguments .title : DEFAULT_TITLE ;
31+ String successMessage = arguments .successMessage != null ? arguments .successMessage : DEFAULT_SUCCESS_MESSAGE ;
32+
33+ SummaryAndComment output = buildSummaryAndComment (data , title , marker , successMessage );
2834 writeLines (arguments .summaryOut , output .summaryLines );
2935 writeLines (arguments .commentOut , output .commentLines );
3036 }
@@ -43,7 +49,7 @@ private static void writeLines(Path path, List<String> lines) throws IOException
4349 Files .writeString (path , sb .toString (), StandardCharsets .UTF_8 );
4450 }
4551
46- private static SummaryAndComment buildSummaryAndComment (Map <String , Object > data ) {
52+ private static SummaryAndComment buildSummaryAndComment (Map <String , Object > data , String title , String marker , String successMessage ) {
4753 List <String > summaryLines = new ArrayList <>();
4854 List <String > commentLines = new ArrayList <>();
4955 Object resultsObj = data .get ("results" );
@@ -114,8 +120,10 @@ private static SummaryAndComment buildSummaryAndComment(Map<String, Object> data
114120 }
115121
116122 if (!commentEntries .isEmpty ()) {
117- commentLines .add ("### Android screenshot updates" );
118- commentLines .add ("" );
123+ if (title != null && !title .isEmpty ()) {
124+ commentLines .add ("### " + title );
125+ commentLines .add ("" );
126+ }
119127 for (Map <String , Object > entry : commentEntries ) {
120128 String test = stringValue (entry .get ("test" ), "" );
121129 String status = stringValue (entry .get ("status" ), "" );
@@ -127,11 +135,11 @@ private static SummaryAndComment buildSummaryAndComment(Map<String, Object> data
127135 if (!commentLines .isEmpty () && !commentLines .get (commentLines .size () - 1 ).isEmpty ()) {
128136 commentLines .add ("" );
129137 }
130- commentLines .add (MARKER );
138+ commentLines .add (marker );
131139 } else {
132- commentLines .add ("✅ Native Android screenshot tests passed." );
140+ commentLines .add (successMessage != null ? successMessage : DEFAULT_SUCCESS_MESSAGE );
133141 commentLines .add ("" );
134- commentLines .add (MARKER );
142+ commentLines .add (marker );
135143 }
136144 return new SummaryAndComment (summaryLines , commentLines );
137145 }
@@ -258,17 +266,26 @@ private static class Arguments {
258266 final Path compareJson ;
259267 final Path commentOut ;
260268 final Path summaryOut ;
269+ final String marker ;
270+ final String title ;
271+ final String successMessage ;
261272
262- private Arguments (Path compareJson , Path commentOut , Path summaryOut ) {
273+ private Arguments (Path compareJson , Path commentOut , Path summaryOut , String marker , String title , String successMessage ) {
263274 this .compareJson = compareJson ;
264275 this .commentOut = commentOut ;
265276 this .summaryOut = summaryOut ;
277+ this .marker = marker ;
278+ this .title = title ;
279+ this .successMessage = successMessage ;
266280 }
267281
268282 static Arguments parse (String [] args ) {
269283 Path compare = null ;
270284 Path comment = null ;
271285 Path summary = null ;
286+ String marker = null ;
287+ String title = null ;
288+ String successMessage = null ;
272289 for (int i = 0 ; i < args .length ; i ++) {
273290 String arg = args [i ];
274291 switch (arg ) {
@@ -293,6 +310,27 @@ static Arguments parse(String[] args) {
293310 }
294311 summary = Path .of (args [i ]);
295312 }
313+ case "--marker" -> {
314+ if (++i >= args .length ) {
315+ System .err .println ("Missing value for --marker" );
316+ return null ;
317+ }
318+ marker = args [i ];
319+ }
320+ case "--title" -> {
321+ if (++i >= args .length ) {
322+ System .err .println ("Missing value for --title" );
323+ return null ;
324+ }
325+ title = args [i ];
326+ }
327+ case "--success-message" -> {
328+ if (++i >= args .length ) {
329+ System .err .println ("Missing value for --success-message" );
330+ return null ;
331+ }
332+ successMessage = args [i ];
333+ }
296334 default -> {
297335 System .err .println ("Unknown argument: " + arg );
298336 return null ;
@@ -303,7 +341,7 @@ static Arguments parse(String[] args) {
303341 System .err .println ("--compare-json, --comment-out, and --summary-out are required" );
304342 return null ;
305343 }
306- return new Arguments (compare , comment , summary );
344+ return new Arguments (compare , comment , summary , marker , title , successMessage );
307345 }
308346 }
309347}
0 commit comments