@@ -648,15 +648,16 @@ private Collection<BuildRevision> getQueuedBuildRevisionForVote(@NotNull BuildTy
648648 if (buildPromotion .isFailedToCollectChanges ()) return publisher .getFallbackRevisions (buildPromotion .getAssociatedBuild ());
649649
650650 if (!((BuildPromotionEx )buildPromotion ).isChangeCollectingNeeded (false )) {
651- return getBuildRevisionForVote (publisher , buildPromotion .getRevisions ());
651+ return getBuildRevisionForVote (publisher , buildPromotion .getRevisions (), buildPromotion . getBranch () );
652652 }
653653 LOG .debug (() -> "No revision is found for build " + buildPromotion .getBuildTypeExternalId () + ". Queue-related status won't be published" );
654654 return Collections .emptyList ();
655655 }
656656
657657 @ NotNull
658658 private List <BuildRevision > getBuildRevisionForVote (@ NotNull CommitStatusPublisher publisher ,
659- @ NotNull Collection <BuildRevision > revisionsToCheck ) {
659+ @ NotNull Collection <BuildRevision > revisionsToCheck ,
660+ @ Nullable Branch buildBranch ) {
660661 if (revisionsToCheck .isEmpty ()) return Collections .emptyList ();
661662
662663 String vcsRootId = publisher .getVcsRootId ();
@@ -667,6 +668,30 @@ private List<BuildRevision> getBuildRevisionForVote(@NotNull CommitStatusPublish
667668 revisions .add (revision );
668669 }
669670 }
671+ // TW-79075
672+ if (buildBranch != null && !buildBranch .isDefaultBranch ()) {
673+ Set <String > selectedBranchNames = new HashSet <>();
674+ selectedBranchNames .add (buildBranch .getName ());
675+ selectedBranchNames .add ("refs/heads/" + buildBranch .getName ()); // git prepends this to the branch name
676+ List <BuildRevision > revisionsForBranch = new ArrayList <>();
677+ for (BuildRevision revision : revisions ) {
678+ String vcsBranch = revision .getRepositoryVersion ().getVcsBranch ();
679+ if (vcsBranch != null && selectedBranchNames .contains (vcsBranch )) {
680+ revisionsForBranch .add (revision );
681+ }
682+ }
683+ if (!revisionsForBranch .isEmpty ()) {
684+ LOG .info ("Selective publishing for buildBranch=" + buildBranch + ", selected "
685+ + revisionsForBranch .stream ().map (r -> r .getRoot ().getName () + '@' + r .getRepositoryVersion ().getVcsBranch ()).collect (Collectors .joining (", " , "[" , "]" ))
686+ + " out of " + revisions .stream ().map (r -> r .getRoot ().getName () + '@' + r .getRepositoryVersion ().getVcsBranch ()).collect (Collectors .joining (", " , "[" , "]" ))
687+ );
688+ revisions = revisionsForBranch ;
689+ } else {
690+ LOG .warn ("Attempted selective publishing, but did not find revisions for buildBranch=" + buildBranch + " among "
691+ + revisions .stream ().map (r -> r .getRoot ().getName () + '@' + r .getRepositoryVersion ().getVcsBranch ()).collect (Collectors .joining (", " , "[" , "]" ))
692+ + ", will publish all" );
693+ }
694+ }
670695 return revisions ;
671696 }
672697
@@ -835,7 +860,7 @@ public RetryInfo publish(Event event, BuildRevision revision, CommitStatusPublis
835860 @ Override
836861 public Collection <BuildRevision > getRevisions (BuildType buildType , CommitStatusPublisher publisher ) {
837862 if (buildPromotion .isFailedToCollectChanges ()) return publisher .getFallbackRevisions (build );
838- return getBuildRevisionForVote (publisher , build .getRevisions ());
863+ return getBuildRevisionForVote (publisher , build .getRevisions (), build . getBranch () );
839864 }
840865 };
841866
0 commit comments