Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,16 @@ private Collection<BuildRevision> getQueuedBuildRevisionForVote(@NotNull BuildTy
if (buildPromotion.isFailedToCollectChanges()) return publisher.getFallbackRevisions(buildPromotion.getAssociatedBuild());

if (!((BuildPromotionEx)buildPromotion).isChangeCollectingNeeded(false)) {
return getBuildRevisionForVote(publisher, buildPromotion.getRevisions());
return getBuildRevisionForVote(publisher, buildPromotion.getRevisions(), buildPromotion.getBranch());
}
LOG.debug(() -> "No revision is found for build " + buildPromotion.getBuildTypeExternalId() + ". Queue-related status won't be published");
return Collections.emptyList();
}

@NotNull
private List<BuildRevision> getBuildRevisionForVote(@NotNull CommitStatusPublisher publisher,
@NotNull Collection<BuildRevision> revisionsToCheck) {
@NotNull Collection<BuildRevision> revisionsToCheck,
@Nullable Branch buildBranch) {
if (revisionsToCheck.isEmpty()) return Collections.emptyList();

String vcsRootId = publisher.getVcsRootId();
Expand All @@ -667,6 +668,30 @@ private List<BuildRevision> getBuildRevisionForVote(@NotNull CommitStatusPublish
revisions.add(revision);
}
}
// TW-79075
if (buildBranch != null && !buildBranch.isDefaultBranch()) {
Set<String> selectedBranchNames = new HashSet<>();
selectedBranchNames.add(buildBranch.getName());
selectedBranchNames.add("refs/heads/" + buildBranch.getName()); // git prepends this to the branch name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this relies on a (false) assumption that branch specification of the respective VCS root is always +:refs/heads/*

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it would be better to rely on BuildTypeEx::getLogicalBranchNames instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hated that bit too :)
Ideally the trigger would propagate if the branch is matching or a default

List<BuildRevision> revisionsForBranch = new ArrayList<>();
for(BuildRevision revision: revisions) {
String vcsBranch = revision.getRepositoryVersion().getVcsBranch();
if (vcsBranch != null && selectedBranchNames.contains(vcsBranch)) {
revisionsForBranch.add(revision);
}
}
if (!revisionsForBranch.isEmpty()) {
LOG.info("Selective publishing for buildBranch=" + buildBranch + ", selected "
+ revisionsForBranch.stream().map(r -> r.getRoot().getName() + '@' + r.getRepositoryVersion().getVcsBranch()).collect(Collectors.joining(", ", "[", "]"))
+ " out of " + revisions.stream().map(r -> r.getRoot().getName() + '@' + r.getRepositoryVersion().getVcsBranch()).collect(Collectors.joining(", ", "[", "]"))
);
revisions = revisionsForBranch;
} else {
LOG.warn("Attempted selective publishing, but did not find revisions for buildBranch=" + buildBranch + " among "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within this new functionality scope, I don't think it's correct to fall back to publishing statuses to all revisions if we cannot find a relevant subset. When there is a build chain, it could be the case that some builds in it are fully falling back to default VCS branches wile other builds running on non-default VCS branches, despite all of them marked by a non-default logical branch. It seems we should only publish statuses for the latter kind of builds in such a case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this is more of a failsafe if the code doesn't work for some reason.

+ revisions.stream().map(r -> r.getRoot().getName() + '@' + r.getRepositoryVersion().getVcsBranch()).collect(Collectors.joining(", ", "[", "]"))
+ ", will publish all");
}
}
return revisions;
}

Expand Down Expand Up @@ -835,7 +860,7 @@ public RetryInfo publish(Event event, BuildRevision revision, CommitStatusPublis
@Override
public Collection<BuildRevision> getRevisions(BuildType buildType, CommitStatusPublisher publisher) {
if (buildPromotion.isFailedToCollectChanges()) return publisher.getFallbackRevisions(build);
return getBuildRevisionForVote(publisher, build.getRevisions());
return getBuildRevisionForVote(publisher, build.getRevisions(), build.getBranch());
}
};

Expand Down