Skip to content

Commit

Permalink
Fix NPE when milestone does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
sjohnr committed Oct 11, 2023
1 parent afc0530 commit 4b8f63d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/src/main/java/io/spring/release/SpringReleases.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,13 @@ public boolean hasNoOpenIssues(String owner, String repo, String version) {
public boolean isDueToday(String owner, String repo, String version) {
var repository = new Repository(owner, repo);
var milestone = this.gitHubApi.getMilestone(repository, version);
if (milestone == null || milestone.dueOn() == null) {
return false;
}

var today = LocalDate.now();
var dueOn = (milestone.dueOn() != null) ? milestone.dueOn().atZone(ZoneOffset.UTC).toLocalDate() : null;
return (dueOn != null && today.compareTo(dueOn) >= 0);
var dueOn = milestone.dueOn().atZone(ZoneOffset.UTC).toLocalDate();
return !today.isBefore(dueOn);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions core/src/test/java/io/spring/release/SpringReleasesTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,23 @@ public void isDueTodayWhenDueTomorrowThenFalse() {
assertThat(repository.name()).isEqualTo(REPO);
}

@Test
public void isDueTodayWhenMilestoneDoesNotExistThenFalse() {
var version = "6.1.0";
when(this.gitHubApi.getMilestone(any(Repository.class), anyString())).thenReturn(null);

var isDueToday = this.springReleases.isDueToday(OWNER, REPO, version);
assertThat(isDueToday).isFalse();

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

var repository = repositoryCaptor.getValue();
assertThat(repository.owner()).isEqualTo(OWNER);
assertThat(repository.name()).isEqualTo(REPO);
}

@Test
public void hasNoOpenIssuesWhenNoOpenIssuesThenTrue() {
var version = "6.1.0";
Expand Down

0 comments on commit 4b8f63d

Please sign in to comment.