Add BadgeController and FaviconController, integrate Javadoc badge display in index page
Build and Push Docker Image / build-and-push (push) Successful in 26s
Build and Push Docker Image / build-and-push (push) Successful in 26s
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package codes.thischwa.jdvs.web;
|
||||
|
||||
import codes.thischwa.jdvs.jpa.GitRepositoryRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class BadgeController {
|
||||
|
||||
private static final String BADGE_URL_PREFIX =
|
||||
"https://img.shields.io/badge/javadoc%40JdVS-";
|
||||
|
||||
private static final String BADGE_URL_SUFFIX = "-green";
|
||||
|
||||
private final GitRepositoryRepository repository;
|
||||
|
||||
@GetMapping("/badge/{repositoryName}")
|
||||
public String badge(@PathVariable String repositoryName) {
|
||||
String tag =
|
||||
repository
|
||||
.findByName(repositoryName)
|
||||
.map(r -> r.getLastTag() != null ? r.getLastTag() : "unknown")
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Repository not found: " + repositoryName));
|
||||
return "redirect:" + BADGE_URL_PREFIX + tag + BADGE_URL_SUFFIX;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package codes.thischwa.jdvs.web;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Controller for favicon.ico, just for reducing 404 errors in the logs.
|
||||
*/
|
||||
@RestController
|
||||
public class FaviconController {
|
||||
|
||||
@GetMapping("favicon.ico")
|
||||
void returnNoFavicon() {
|
||||
// see class comment
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
<th>Name</th>
|
||||
<th>Latest Version</th>
|
||||
<th>Last Update</th>
|
||||
<th>Action</th>
|
||||
<th>Javadoc link</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -22,7 +22,9 @@
|
||||
<td th:text="${repo.lastTag}">-</td>
|
||||
<td th:text="${#temporals.format(repo.updated, 'dd.MM.yyyy HH:mm')}">-</td>
|
||||
<td>
|
||||
<a th:if="${repo.lastTag != null}" th:href="@{/{name}/index.html(name=${repo.name})}" class="btn btn-primary btn-sm">Open Javadoc</a>
|
||||
<a th:if="${repo.lastTag != null}" th:href="@{/{name}/index.html(name=${repo.name})}">
|
||||
<img th:src="@{/badge/{name}(name=${repo.name})}" alt="javadoc badge">
|
||||
</a>
|
||||
<span th:if="${repo.lastTag == null}" class="badge bg-secondary">Not yet generated</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user