@@ -619,15 +619,16 @@ private Collection<BuildRevision> getQueuedBuildRevisionForVote(@NotNull BuildTy
619619 if (buildPromotion .isFailedToCollectChanges ()) return Collections .emptyList ();
620620
621621 if (!((BuildPromotionEx )buildPromotion ).isChangeCollectingNeeded (false )) {
622- return getBuildRevisionForVote (publisher , buildPromotion .getRevisions ());
622+ return getBuildRevisionForVote (publisher , buildPromotion .getRevisions (), buildPromotion . getBranch () );
623623 }
624624 LOG .debug ("No revision is found for build " + buildPromotion .getBuildTypeExternalId () + ". Queue-related status won't be published" );
625625 return Collections .emptyList ();
626626 }
627627
628628 @ NotNull
629629 private List <BuildRevision > getBuildRevisionForVote (@ NotNull CommitStatusPublisher publisher ,
630- @ NotNull Collection <BuildRevision > revisionsToCheck ) {
630+ @ NotNull Collection <BuildRevision > revisionsToCheck ,
631+ @ Nullable Branch buildBranch ) {
631632 if (revisionsToCheck .isEmpty ()) return Collections .emptyList ();
632633
633634 String vcsRootId = publisher .getVcsRootId ();
@@ -638,6 +639,30 @@ private List<BuildRevision> getBuildRevisionForVote(@NotNull CommitStatusPublish
638639 revisions .add (revision );
639640 }
640641 }
642+ // TW-79075
643+ if (buildBranch != null && !buildBranch .isDefaultBranch ()) {
644+ Set <String > selectedBranchNames = new HashSet <>();
645+ selectedBranchNames .add (buildBranch .getName ());
646+ selectedBranchNames .add ("refs/heads/" + buildBranch .getName ()); // git prepends this to the branch name
647+ List <BuildRevision > revisionsForBranch = new ArrayList <>();
648+ for (BuildRevision revision : revisions ) {
649+ String vcsBranch = revision .getRepositoryVersion ().getVcsBranch ();
650+ if (vcsBranch != null && selectedBranchNames .contains (vcsBranch )) {
651+ revisionsForBranch .add (revision );
652+ }
653+ }
654+ if (!revisionsForBranch .isEmpty ()) {
655+ LOG .info ("Selective publishing for buildBranch=" + buildBranch + ", selected "
656+ + revisionsForBranch .stream ().map (r -> r .getRoot ().getName () + '@' + r .getRepositoryVersion ().getVcsBranch ()).collect (Collectors .joining (", " , "[" , "]" ))
657+ + " out of " + revisions .stream ().map (r -> r .getRoot ().getName () + '@' + r .getRepositoryVersion ().getVcsBranch ()).collect (Collectors .joining (", " , "[" , "]" ))
658+ );
659+ revisions = revisionsForBranch ;
660+ } else {
661+ LOG .warn ("Attempted selective publishing, but did not find revisions for buildBranch=" + buildBranch + " among "
662+ + revisions .stream ().map (r -> r .getRoot ().getName () + '@' + r .getRepositoryVersion ().getVcsBranch ()).collect (Collectors .joining (", " , "[" , "]" ))
663+ + ", will publish all" );
664+ }
665+ }
641666 return revisions ;
642667 }
643668
@@ -785,7 +810,7 @@ public void publish(Event event, BuildRevision revision, CommitStatusPublisher p
785810 @ Override
786811 public Collection <BuildRevision > getRevisions (BuildType buildType , CommitStatusPublisher publisher ) {
787812 if (buildPromotion .isFailedToCollectChanges ()) return Collections .emptyList ();
788- return getBuildRevisionForVote (publisher , build .getRevisions ());
813+ return getBuildRevisionForVote (publisher , build .getRevisions (), build . getBranch () );
789814 }
790815 };
791816
0 commit comments