Skip to content

Commit

Permalink
Fix milestone due date
Browse files Browse the repository at this point in the history
Closes gh-31
  • Loading branch information
sjohnr committed Apr 16, 2024
1 parent c593f17 commit 06cda9e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/io/spring/release/SpringReleases.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ public void scheduleReleaseIfNotExists(String owner, String repo, String version
var releaseTrainSpec = SpringReleaseTrainSpec.builder()
.nextTrain()
.version(baseVersion)
.weekOfMonth(dayOfWeek)
.dayOfWeek(weekOfMonth)
.weekOfMonth(weekOfMonth)
.dayOfWeek(dayOfWeek)
.build();
// @formatter:on

Expand Down
34 changes: 34 additions & 0 deletions core/src/test/java/io/spring/release/SpringReleasesTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
Expand Down Expand Up @@ -55,6 +56,10 @@ public class SpringReleasesTests {

private static final String REPO = "spring-security";

private static final int WEEK_OF_MONTH = 3;

private static final int DAY_OF_WEEK = 1;

// @formatter:off
private static final List<Milestone> MILESTONES = List.of(new Milestone("6.0.4", 6L, toInstant("2023-06-19")),
new Milestone("6.1.x", 100L, null),
Expand Down Expand Up @@ -558,6 +563,35 @@ public void scheduleReleaseIfNotExistsWhenSnapshotVersionExistsThenNotCreated()
assertThat(repository.name()).isEqualTo(REPO);
}

// gh-31
@Test
public void scheduleReleaseIfNotExistsWhenCreatedThenDueOnCorrectDate() {
var version = "6.1.9";
this.springReleases.scheduleReleaseIfNotExists(OWNER, REPO, version, WEEK_OF_MONTH, DAY_OF_WEEK);

var repositoryCaptor = forClass(Repository.class);
var milestoneCaptor = forClass(Milestone.class);
verify(this.gitHubApi).getMilestone(repositoryCaptor.capture(), eq(version));

var repository = repositoryCaptor.getValue();
assertThat(repository.owner()).isEqualTo(OWNER);
assertThat(repository.name()).isEqualTo(REPO);
verify(this.gitHubApi).createMilestone(eq(repository), milestoneCaptor.capture());

var releaseTrainSpec = SpringReleaseTrainSpec.builder()
.nextTrain()
.version(version)
.weekOfMonth(WEEK_OF_MONTH)
.dayOfWeek(DAY_OF_WEEK)
.build();
var releaseTrain = new SpringReleaseTrain(releaseTrainSpec);
var nextReleaseDate = releaseTrain.getNextReleaseDate(LocalDate.now());
var dueOn = nextReleaseDate.atTime(LocalTime.NOON).toInstant(ZoneOffset.UTC);
var milestone = milestoneCaptor.getValue();
assertThat(milestone.title()).isEqualTo(version);
assertThat(milestone.dueOn()).isEqualTo(dueOn);
}

private static Instant toInstant(String date) {
return LocalDate.parse(date).atStartOfDay().toInstant(ZoneOffset.UTC);
}
Expand Down

0 comments on commit 06cda9e

Please sign in to comment.