2121import java .util .Properties ;
2222import java .util .function .Function ;
2323import java .util .function .Supplier ;
24+ import java .util .regex .Matcher ;
25+ import java .util .regex .Pattern ;
2426import java .util .stream .Stream ;
2527
2628import static com .gradle .CiUtils .isAzurePipelines ;
@@ -304,6 +306,7 @@ public void execute(BuildResultAdapter buildResult) {
304306 Optional <String > headRef = envVariable ("GITHUB_HEAD_REF" , providers ).filter (value -> !value .isEmpty ());
305307 Optional <String > serverUrl = envVariable ("GITHUB_SERVER_URL" , providers );
306308 Optional <String > gitRepository = envVariable ("GITHUB_REPOSITORY" , providers );
309+ Optional <String > refName = envVariable ("GITHUB_REF_NAME" , providers );
307310
308311 workflow .ifPresent (value ->
309312 addCustomValueAndSearchLink (develocity , "CI workflow" , value ));
@@ -329,6 +332,17 @@ public void execute(BuildResultAdapter buildResult) {
329332 buildScan .link ("GitHub Actions build" , githubActionsBuild .toString ());
330333 }
331334
335+ boolean isPullRequestBuild = headRef .isPresent ();
336+ if (serverUrl .isPresent () && gitRepository .isPresent () && isPullRequestBuild && refName .isPresent ()) {
337+ Matcher matcher = Pattern .compile ("^(\\ d+)/merge$" ).matcher (refName .get ());
338+ if (matcher .matches ()) {
339+ String githubPullRequest = serverUrl .get () +
340+ "/" + gitRepository .get () +
341+ "/pull/" + matcher .group (1 );
342+ buildScan .link ("GitHub pull request" , githubPullRequest );
343+ }
344+ }
345+
332346 if (runId .isPresent ()) {
333347 Map <String , String > params = new HashMap <>();
334348 params .put ("CI run" , runId .get ());
0 commit comments