Skip to content

Commit

Permalink
Merge pull request #599 from micronaut-projects/fix-createReleasesDro…
Browse files Browse the repository at this point in the history
…pdown

Fix create releases dropdown
  • Loading branch information
timyates authored Aug 9, 2023
2 parents 0937d6a + ebc0394 commit 8b2f036
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For testing...
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
introduction:
title: Introduction
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.micronaut.build

import java.nio.file.Files

class ReleasesDropdownFunctionalTest extends AbstractFunctionalTest {

void "version dropdown is populated from github"() {
given:
withSample("test-micronaut-module")

and: 'we override the github slug to use micronaut-crac'
testDirectory.resolve("gradle.properties").toFile() << "githubSlug=micronaut-projects/micronaut-crac"

and: 'we copy the grails-doc-files.jar to the prepareDocsResources directory'
def path = Files.createDirectories(testDirectory.resolve("build/tmp/prepareDocsResources"))
def stream = ReleasesDropdownFunctionalTest.getResourceAsStream("/grails-doc-files.jar")
def target = path.resolve("grails-doc-files.jar")
Files.copy(stream, target)

when: 'we build the docs'
run 'docs'

and: 'we find all the version options in the dropdown'
def html = testDirectory.resolve("build/docs/guide/index.html").text
def versions = html.findAll("<option.+?value='https://micronaut-projects.github.io/micronaut-crac/([^/]+)") { match, version ->
version
}

then: 'there are more than 2, and 2 of them are latest and snapshot'
versions.contains('latest')
versions.contains('snapshot')
versions.size() > 2
}
}
Binary file not shown.
4 changes: 2 additions & 2 deletions src/main/groovy/io/micronaut/build/MicronautDocsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ abstract class MicronautDocsPlugin implements Plugin<Project> {
outputIndex = layout.buildDir.file("working/05-dropdown/index.html")
versionsJson = githubApi.zip(slug) { api, ghSlug ->
try {
byte[] jsonArr = api.fetchTagsFromGitHub(ghslug)
byte[] jsonArr = api.fetchTagsFromGitHub(ghSlug)
return new String(jsonArr, "UTF-8")
} catch (Exception e) {
task.logger.error("Exception fetching github tags for $ghSlug")
task.logger.error("Exception fetching github tags for $ghSlug", e)
return "[]"
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/micronaut/build/utils/GithubApiUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +44,7 @@ static byte[] fetchTagsFromGitHub(Logger logger, String slug) {

private static byte[] fetchFromGithub(Logger logger, String slug, String what) {
String url = System.getProperty(GITHUB_API_BASE_URL_SYSTEM_PROPERTY, GITHUB_BASE_API_URL) + "/repos/" + normalizeSlug(slug) + "/" + what;
logger.lifecycle("Fetching " + what + " from " + url);
try {
return fetchFromGithub(logger, connectionForGithubUrl(logger, url));
} catch (IOException ex) {
Expand Down

0 comments on commit 8b2f036

Please sign in to comment.