Skip to content

Commit 3593bd7

Browse files
committed
Use seed commit as lower changelog boundary for initial commercial releases.
Closes #94
1 parent fa4d484 commit 3593bd7

File tree

3 files changed

+62
-11
lines changed

3 files changed

+62
-11
lines changed

src/main/java/org/springframework/data/release/git/GitOperations.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,8 @@ public TicketBranches listTicketBranches(SupportedProject project) {
434434
.filter(branch -> branch.isIssueBranch(project.getProject().getTracker()))//
435435
.collect(Collectors.toMap(Branch::toString, branch -> branch));
436436

437-
Collection<Ticket> tickets = tracker.findTickets(project,
438-
ticketIds.keySet().stream()
439-
.map(it -> TicketReference.ofTicket(it, TicketReference.Style.GitHub))
440-
.collect(Collectors.toList()));
437+
Collection<Ticket> tickets = tracker.findTickets(project, ticketIds.keySet().stream()
438+
.map(it -> TicketReference.ofTicket(it, TicketReference.Style.GitHub)).collect(Collectors.toList()));
441439

442440
return TicketBranches
443441
.from(tickets.stream().collect(Collectors.toMap(ticket -> ticketIds.get(ticket.getId()), ticket -> ticket)));
@@ -461,12 +459,17 @@ public TrainIteration getPreviousIteration(TrainIteration trainIteration) {
461459
return trainToUse.getIteration(Iteration.GA);
462460
}
463461

462+
Iteration iteration = trainIteration.getIteration();
463+
Train train = trainIteration.getTrain();
464+
if (iteration.isServiceIteration()) {
465+
return train.getIteration(iteration.getPrevious());
466+
}
467+
464468
SupportedProject build = trainIteration.getSupportedProject(Projects.BUILD);
465469

466470
Optional<TrainIteration> mostRecentBefore = getTags(build) //
467-
.filter((tag, ti) -> ti.getTrain().equals(trainIteration.getTrain())) //
468-
.find((tag, iteration) -> iteration.getIteration().compareTo(trainIteration.getIteration()) < 0,
469-
Pair::getSecond);
471+
.filter((tag, ti) -> ti.getTrain().equals(train)) //
472+
.find((tag, ti) -> ti.getIteration().compareTo(trainIteration.getIteration()) < 0, Pair::getSecond);
470473

471474
return mostRecentBefore.orElseThrow(() -> new IllegalStateException(
472475
"Cannot determine previous iteration for " + trainIteration.getReleaseTrainNameAndVersion()));
@@ -482,7 +485,7 @@ public List<TicketReference> getTicketReferencesBetween(SupportedProject project
482485
Repository repo = git.getRepository();
483486

484487
ModuleIteration toModuleIteration = to.getModule(project.getProject());
485-
ObjectId fromTag = resolveLowerBoundary(project.getProject(), from, tags, repo);
488+
ObjectId fromTag = resolveLowerBoundary(project.getStatus(), project.getProject(), from, tags, git, repo);
486489
ObjectId toTag = resolveUpperBoundary(toModuleIteration, tags, repo);
487490

488491
Iterable<RevCommit> commits = git.log().addRange(fromTag, toTag).call();
@@ -517,15 +520,30 @@ public List<TicketReference> getTicketReferencesBetween(SupportedProject project
517520
return uniqueTicketReferences;
518521
}
519522

520-
protected ObjectId resolveLowerBoundary(Project project, TrainIteration iteration, VersionTags tags, Repository repo)
521-
throws IOException {
523+
protected ObjectId resolveLowerBoundary(SupportStatus supportStatus, Project project, TrainIteration iteration,
524+
VersionTags tags, Git git, Repository repo) throws IOException, GitAPIException {
522525

523526
if (iteration.contains(project)) {
524527

525-
Optional<Tag> fromTag = tags.filter(iteration.getTrain()).findTag(iteration.getIteration());
528+
Iteration it = iteration.getIteration();
529+
Optional<Tag> fromTag = tags.filter(iteration.getTrain()).findTag(it);
526530

527531
if (!fromTag.isPresent()) {
528532

533+
// commercial releases might not have a previous tag as commercial releases are seeded without OSS tags.
534+
if (supportStatus == SupportStatus.COMMERCIAL && (it.isServiceIteration() || it.isGAIteration())) {
535+
536+
Branch from = Branch.from(iteration.getModule(project));
537+
Iterable<RevCommit> commits = git.log().add(repo.resolve(from.toString())).call();
538+
539+
Optional<RevCommit> first = Streamable.of(commits).stream()
540+
.filter(rev -> rev.getFullMessage().contains("Seed " + from + " branch")).findFirst();
541+
542+
if (first.isPresent()) {
543+
return first.get();
544+
}
545+
}
546+
529547
// fall back to main
530548
return repo.parseCommit(repo.resolve(Branch.MAIN.toString()));
531549
}

src/main/java/org/springframework/data/release/model/Iteration.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public static Iteration valueOf(String iteration) {
107107
return (Iteration) ReflectionUtils.getField(field, null);
108108
}
109109

110+
public static Iteration getServiceRelease(int iterationValue) {
111+
return valueOf("SR" + iterationValue);
112+
}
113+
110114
public boolean isGAIteration() {
111115
return this.equals(GA);
112116
}
@@ -227,4 +231,19 @@ public int compareTo(Iteration o) {
227231

228232
return EQUAL;
229233
}
234+
235+
/**
236+
* Returns the previous iteration for GA or Service Releases.
237+
*
238+
* @return
239+
* @throws IllegalStateException if the current iteration is not a service release.
240+
*/
241+
public Iteration getPrevious() {
242+
243+
if (isServiceIteration()) {
244+
return getIterationValue() == 1 ? Iteration.GA : Iteration.getServiceRelease(getIterationValue() - 1);
245+
}
246+
247+
throw new IllegalStateException(String.format("Cannot determine previous iteration for %s", this));
248+
}
230249
}

src/test/java/org/springframework/data/release/git/GitOperationsIntegrationTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,18 @@ void shouldDeterminePreviousIterationFromGA() throws Exception {
100100
assertThat(hopperSR9.getIteration()).isEqualTo(Iteration.SR9);
101101
}
102102

103+
@Test
104+
void shouldDeterminePreviousIterationFromSR() {
105+
106+
TrainIteration hopperGA = gitOperations.getPreviousIteration(ReleaseTrains.HOPPER.getIteration(Iteration.SR1));
107+
108+
assertThat(hopperGA.getTrain()).isEqualTo(ReleaseTrains.HOPPER);
109+
assertThat(hopperGA.getIteration()).isEqualTo(Iteration.GA);
110+
111+
TrainIteration hopperSR9 = gitOperations.getPreviousIteration(ReleaseTrains.HOPPER.getIteration(Iteration.SR10));
112+
113+
assertThat(hopperSR9.getTrain()).isEqualTo(ReleaseTrains.HOPPER);
114+
assertThat(hopperSR9.getIteration()).isEqualTo(Iteration.SR9);
115+
}
116+
103117
}

0 commit comments

Comments
 (0)