11package io .quarkus .bot .retest ;
22
33import java .io .IOException ;
4+ import java .net .URL ;
45import java .util .ArrayList ;
56import java .util .List ;
7+ import java .util .stream .Collectors ;
68
79import jakarta .inject .Inject ;
810
2325import io .quarkus .bot .config .Feature ;
2426import io .quarkus .bot .config .QuarkusGitHubBotConfig ;
2527import io .quarkus .bot .config .QuarkusGitHubBotConfigFile ;
28+ import io .quarkus .bot .service .GHIssueCommentService ;
2629
2730/**
2831 * Handles {@code @quarkusbot retest} comments on pull requests.
@@ -43,6 +46,9 @@ class RetestCommand implements RetestCommandHandler {
4346 @ Inject
4447 FailedJobsRerunner failedJobsRerunner ;
4548
49+ @ Inject
50+ GHIssueCommentService issueCommentService ;
51+
4652 @ Override
4753 public void run (QuarkusGitHubBotConfigFile quarkusBotConfigFile , GHEventPayload .IssueComment issueCommentPayload ) {
4854 if (!Feature .RETEST_PULL_REQUEST_WORKFLOWS .isEnabled (quarkusBotConfigFile )) {
@@ -56,11 +62,11 @@ public void run(QuarkusGitHubBotConfigFile quarkusBotConfigFile, GHEventPayload.
5662
5763 RetestWorkflowSelection workflowSelection = getWorkflowSelection (pullRequest );
5864
59- if (! workflowSelection .hasEligibleRuns ()) {
65+ if (workflowSelection .eligibleRuns (). isEmpty ()) {
6066 throw RetestCommandException .noEligibleWorkflowRuns (workflowSelection .noEligibleReason ());
6167 }
6268
63- List <Long > startedWorkflowRunIds = new ArrayList <>();
69+ List <GHWorkflowRun > startedWorkflowRuns = new ArrayList <>();
6470 for (GHWorkflowRun workflowRun : workflowSelection .eligibleRuns ()) {
6571 if (quarkusBotConfig .isDryRun ()) {
6672 LOG .infof ("Pull request #%d - Retest failed jobs for workflow run #%d (dry-run)" ,
@@ -70,15 +76,21 @@ public void run(QuarkusGitHubBotConfigFile quarkusBotConfigFile, GHEventPayload.
7076
7177 try {
7278 failedJobsRerunner .rerunFailedJobs (issueCommentPayload , workflowRun );
73- startedWorkflowRunIds .add (workflowRun . getId () );
79+ startedWorkflowRuns .add (workflowRun );
7480 } catch (RuntimeException e ) {
75- if (startedWorkflowRunIds .isEmpty ()) {
81+ if (startedWorkflowRuns .isEmpty ()) {
7682 throw e ;
7783 }
7884
79- throw RetestCommandException .partialRerunFailure (startedWorkflowRunIds , workflowRun .getId (), e );
85+ throw RetestCommandException .partialRerunFailure (
86+ startedWorkflowRuns .stream ().map (GHWorkflowRun ::getId ).toList (), workflowRun .getId (), e );
8087 }
8188 }
89+
90+ if (!startedWorkflowRuns .isEmpty ()) {
91+ issueCommentService .addComment (issueCommentPayload .getIssue (), successMessage (startedWorkflowRuns ), false ,
92+ quarkusBotConfig .isDryRun ());
93+ }
8294 }
8395
8496 private static GHPullRequest getPullRequest (GHEventPayload .IssueComment issueCommentPayload ) {
@@ -97,4 +109,27 @@ private RetestWorkflowSelection getWorkflowSelection(GHPullRequest pullRequest)
97109 throw RetestCommandException .unableToInspectWorkflowRuns (e );
98110 }
99111 }
112+
113+ private static String successMessage (List <GHWorkflowRun > startedWorkflowRuns ) {
114+ String workflowRunLinks = startedWorkflowRuns .stream ()
115+ .map (RetestCommand ::workflowRunReference )
116+ .collect (Collectors .joining (", " ));
117+ String label = startedWorkflowRuns .size () == 1 ? "workflow run " : "workflow runs " ;
118+ return ":arrows_counterclockwise: Retest started for failed jobs in " + label + workflowRunLinks + "." ;
119+ }
120+
121+ private static String workflowRunReference (GHWorkflowRun workflowRun ) {
122+ String label = "#" + workflowRun .getId ();
123+ URL htmlUrl ;
124+ try {
125+ htmlUrl = workflowRun .getHtmlUrl ();
126+ } catch (IOException e ) {
127+ return label ;
128+ }
129+ if (htmlUrl == null ) {
130+ return label ;
131+ }
132+
133+ return "[" + label + "](" + htmlUrl + ")" ;
134+ }
100135}
0 commit comments