Skip to content

Commit

Permalink
Support Antora versions for project documentation links
Browse files Browse the repository at this point in the history
Closes gh-19
  • Loading branch information
mbhave committed May 14, 2024
1 parent 2a0879f commit 653d6d7
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ProjectDocumentation implements Comparable<ProjectDocumentation> {

private final String version;

private final boolean antora;

private final String api;

private final String ref;
Expand All @@ -39,8 +41,10 @@ public class ProjectDocumentation implements Comparable<ProjectDocumentation> {
private final boolean current;

@JsonCreator(mode = Mode.PROPERTIES)
public ProjectDocumentation(String version, String api, String ref, Status status, boolean current) {
public ProjectDocumentation(String version, boolean antora, String api, String ref, Status status,
boolean current) {
this.version = version;
this.antora = antora;
this.api = api;
this.ref = ref;
this.status = status;
Expand Down Expand Up @@ -76,6 +80,10 @@ public int compareTo(ProjectDocumentation other) {
return -this.version.compareTo(other.version);
}

public boolean isAntora() {
return this.antora;
}

/**
* Project documentation status.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ public class NewRelease {
@URL
private final String apiDocUrl;

private final boolean isAntora;

@JsonCreator
public NewRelease(String version, String referenceDocUrl, String apiDocUrl) {
public NewRelease(String version, String referenceDocUrl, String apiDocUrl, boolean isAntora) {
this.version = version;
this.referenceDocUrl = referenceDocUrl;
this.apiDocUrl = apiDocUrl;
this.isAntora = isAntora;
}

public String getVersion() {
Expand All @@ -55,4 +58,8 @@ public String getApiDocUrl() {
return this.apiDocUrl;
}

public boolean isAntora() {
return this.isAntora;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public ResponseEntity<String> add(@PathVariable String id, @RequestBody NewRelea
return ResponseEntity.badRequest().body(message);
}
Release.Status status = Release.Status.fromVersion(version);
ProjectDocumentation projectDocumentation = new ProjectDocumentation(release.getVersion(),
ProjectDocumentation projectDocumentation = new ProjectDocumentation(release.getVersion(), release.isAntora(),
release.getApiDocUrl(), release.getReferenceDocUrl(),
ProjectDocumentation.Status.valueOf(status.name()), false);
this.contentfulService.addProjectDocumentation(id, projectDocumentation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void addProjectDocumentation() {
assertThat(updatedEntry.size()).isEqualTo(2);
assertThat(updatedEntry).extracting((map) -> map.get("version")).containsExactly("1.0", "2.0");
assertThat(updatedEntry).extracting((map) -> map.get("current")).containsExactly(false, true);
assertThat(updatedEntry).extracting((map) -> map.get("antora")).containsExactly(false, true);
}

@Test
Expand Down Expand Up @@ -287,7 +288,7 @@ private Consumer<List<Map<String, Object>>> addRelease() {

private static Map<String, Object> getRelease(boolean current) {
return Map.of("version", "1.0", "api", "http://api.com", "ref", "http://ref.com", "status",
"GENERAL_AVAILABILITY", "repository", "RELEASE", "current", current);
"GENERAL_AVAILABILITY", "repository", "RELEASE", "current", current, "antora", false);
}

@SuppressWarnings("unchecked")
Expand All @@ -300,7 +301,7 @@ private void setupNonExistentProject() {
}

private ProjectDocumentation getDocumentation(String version, Status status) {
return new ProjectDocumentation(version, "http://api.com", "http://ref.com", status, false);
return new ProjectDocumentation(version, true, "http://api.com", "http://ref.com", status, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class ContentfulServiceTests {

private static final Project PROJECT = new Project("Test Project", "test-project", "github", Status.ACTIVE);

private static final ProjectDocumentation PROJECT_DOCUMENTATION = new ProjectDocumentation("2.0", "http://api.com",
"http://ref.com", ProjectDocumentation.Status.GENERAL_AVAILABILITY, false);
private static final ProjectDocumentation PROJECT_DOCUMENTATION = new ProjectDocumentation("2.0", false,
"http://api.com", "http://ref.com", ProjectDocumentation.Status.GENERAL_AVAILABILITY, false);

private static final ProjectSupport PROJECT_SUPPORT = new ProjectSupport("2.2.x", LocalDate.parse("2020-02-01"),
LocalDate.parse("2020-02-02"), LocalDate.parse("2020-02-03"), LocalDate.parse("2020-02-04"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ProjectDocumentationJsonTests {

@Test
void convertValueToMapReturnsMap() {
ProjectDocumentation documentation = new ProjectDocumentation("ver", "api", "ref",
ProjectDocumentation documentation = new ProjectDocumentation("ver", false, "api", "ref",
ProjectDocumentation.Status.PRERELEASE, true);
Map<?, ?> converted = this.objectMapper.convertValue(documentation, Map.class);
Map<String, Object> expected = new HashMap<>();
Expand All @@ -57,6 +57,7 @@ void convertValueToMapReturnsMap() {
expected.put("ref", documentation.getRef());
expected.put("status", documentation.getStatus().name());
expected.put("current", documentation.isCurrent());
expected.put("antora", documentation.isAntora());
assertThat(converted).isEqualTo(expected);
}

Expand All @@ -69,6 +70,7 @@ void readObjectReadsJson() throws Exception {
.isEqualTo("https://docs.spring.io/spring-boot/docs/{version}/reference/html/");
assertThat(projectDocumentation.getStatus()).isEqualTo(Status.SNAPSHOT);
assertThat(projectDocumentation.isCurrent()).isEqualTo(true);
assertThat(projectDocumentation.isAntora()).isEqualTo(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ private List<ProjectDocumentation> getProjectDocumentations() {
List<ProjectDocumentation> result = new ArrayList<>();
String docsRoot;
docsRoot = "https://docs.spring.io/spring-boot/docs/2.3.0/";
result.add(new ProjectDocumentation("2.3.0", docsRoot + "api/", docsRoot + "reference/html/",
result.add(new ProjectDocumentation("2.3.0", false, docsRoot + "api/", docsRoot + "reference/html/",
Status.GENERAL_AVAILABILITY, true));
docsRoot = "https://docs.spring.io/spring-boot/docs/2.3.1-SNAPSHOT/";
result.add(new ProjectDocumentation("2.3.1-SNAPSHOT", docsRoot + "api/", docsRoot + "reference/html/",
result.add(new ProjectDocumentation("2.3.1-SNAPSHOT", false, docsRoot + "api/", docsRoot + "reference/html/",
Status.SNAPSHOT, false));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,37 @@ void addAddsRelease() throws Exception {
.contentType(MediaType.APPLICATION_JSON)
.content(from("add.json")))
.andExpect(status().isCreated())
.andExpect(header().string("Location", expectedLocation));
ArgumentCaptor<ProjectDocumentation> captor = ArgumentCaptor.forClass(ProjectDocumentation.class);
verify(this.contentfulService).addProjectDocumentation(eq("spring-boot"), captor.capture());
ProjectDocumentation added = captor.getValue();
assertThat(added.getVersion()).isEqualTo("2.8.0");
assertThat(added.getApi()).isEqualTo("https://docs.spring.io/spring-boot/docs/{version}/api/");
assertThat(added.getRef()).isEqualTo("https://docs.spring.io/spring-boot/docs/{version}/reference/html/");
assertThat(added.getStatus()).isEqualTo(ProjectDocumentation.Status.GENERAL_AVAILABILITY);
assertThat(added.isCurrent()).isFalse();
assertThat(added.isAntora()).isFalse();
}

@Test
@WithMockUser(roles = "ADMIN")
void addWithAntoraVersionAddsRelease() throws Exception {
given(this.contentfulService.getProjectDocumentations("spring-boot")).willReturn(getProjectDocumentations());
String expectedLocation = "https://api.spring.io/projects/spring-boot/releases/2.8.0";
ConstrainedFields fields = ConstrainedFields.constraintsOn(NewRelease.class);
this.mvc
.perform(post("/projects/spring-boot/releases").accept(MediaTypes.HAL_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(from("add-with-antora.json")))
.andExpect(status().isCreated())
.andExpect(header().string("Location", expectedLocation))
.andDo(document("create-release", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(fields.withPath("version").description("The Release version"),
requestFields(fields.withPath("version").description("The Release version"), fields
.withPath("isAntora")
.type(JsonFieldType.BOOLEAN)
.optional()
.description(
"Indicates if the documentation for this release is on Antora. Defaults to false if not specified."),
fields.withPath("referenceDocUrl")
.description(
"URL of the reference documentation, {version} template variable is supported"),
Expand All @@ -178,6 +206,7 @@ void addAddsRelease() throws Exception {
assertThat(added.getRef()).isEqualTo("https://docs.spring.io/spring-boot/docs/{version}/reference/html/");
assertThat(added.getStatus()).isEqualTo(ProjectDocumentation.Status.GENERAL_AVAILABILITY);
assertThat(added.isCurrent()).isFalse();
assertThat(added.isAntora()).isTrue();
}

@Test
Expand Down Expand Up @@ -248,10 +277,10 @@ private List<ProjectDocumentation> getProjectDocumentations() {
List<ProjectDocumentation> result = new ArrayList<>();
String docsRoot;
docsRoot = "https://docs.spring.io/spring-boot/docs/2.3.0/";
result.add(new ProjectDocumentation("2.3.0", docsRoot + "api/", docsRoot + "reference/html/",
result.add(new ProjectDocumentation("2.3.0", false, docsRoot + "api/", docsRoot + "reference/html/",
Status.GENERAL_AVAILABILITY, true));
docsRoot = "https://docs.spring.io/spring-boot/docs/2.3.1-SNAPSHOT/";
result.add(new ProjectDocumentation("2.3.1-SNAPSHOT", docsRoot + "api/", docsRoot + "reference/html/",
result.add(new ProjectDocumentation("2.3.1-SNAPSHOT", false, docsRoot + "api/", docsRoot + "reference/html/",
Status.SNAPSHOT, false));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "2.8.0",
"isAntora": true,
"apiDocUrl": "https://docs.spring.io/spring-boot/docs/{version}/api/",
"referenceDocUrl": "https://docs.spring.io/spring-boot/docs/{version}/reference/html/"
}

0 comments on commit 653d6d7

Please sign in to comment.