-
Notifications
You must be signed in to change notification settings - Fork 90
TW-79075 Publish commit status selectively for feature branches builds #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
@@ -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 | ||
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 " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
|
@@ -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()); | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
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/*
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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