mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Use environment for git sha url
This commit is contained in:
@@ -156,6 +156,7 @@ public class ViewController {
|
||||
model.addAttribute("version", versionService.getVersion());
|
||||
model.addAttribute("releaseVersion", githubReleaseService.getClientReleaseVersion());
|
||||
model.addAttribute("downloadBaseUrl", githubReleaseService.getDownloadBaseUrl());
|
||||
model.addAttribute("showCommitChip", gitInfoService.shouldShowCommitChip());
|
||||
model.addAttribute("buildCommitShort", gitInfoService.getShortCommitSha());
|
||||
model.addAttribute("buildCommitUrl", gitInfoService.getCommitUrl());
|
||||
}
|
||||
|
||||
@@ -7,19 +7,21 @@ import java.io.InputStreamReader;
|
||||
import java.util.Properties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Component
|
||||
public class GitInfoService {
|
||||
|
||||
private static final String FALLBACK_GIT_SHA = "unknown";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GitInfoService.class);
|
||||
private static final String COMMIT_URL_PREFIX = "https://github.com/Kruhlmann/imgfloat-j/commit/";
|
||||
|
||||
private final String commitSha;
|
||||
private final String shortCommitSha;
|
||||
private final String commitUrlPrefix;
|
||||
|
||||
public GitInfoService() {
|
||||
public GitInfoService(@Value("${IMGFLOAT_COMMIT_URL_PREFIX:}") String commitUrlPrefix) {
|
||||
CommitInfo commitInfo = resolveFromGitProperties();
|
||||
if (commitInfo == null) {
|
||||
commitInfo = resolveFromGitBinary();
|
||||
@@ -36,6 +38,7 @@ public class GitInfoService {
|
||||
|
||||
this.commitSha = defaultValue(full);
|
||||
this.shortCommitSha = defaultValue(abbreviated);
|
||||
this.commitUrlPrefix = normalize(commitUrlPrefix);
|
||||
}
|
||||
|
||||
public String getCommitSha() {
|
||||
@@ -47,10 +50,17 @@ public class GitInfoService {
|
||||
}
|
||||
|
||||
public String getCommitUrl() {
|
||||
if (commitSha == null || commitSha.isBlank() || FALLBACK_GIT_SHA.equalsIgnoreCase(commitSha)) {
|
||||
if (!shouldShowCommitChip()
|
||||
|| commitSha == null
|
||||
|| commitSha.isBlank()
|
||||
|| FALLBACK_GIT_SHA.equalsIgnoreCase(commitSha)) {
|
||||
return null;
|
||||
}
|
||||
return COMMIT_URL_PREFIX + commitSha;
|
||||
return commitUrlPrefix + commitSha;
|
||||
}
|
||||
|
||||
public boolean shouldShowCommitChip() {
|
||||
return StringUtils.hasText(commitUrlPrefix);
|
||||
}
|
||||
|
||||
private CommitInfo resolveFromGitProperties() {
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<span class="muted">Version</span>
|
||||
<span class="version-badge" th:text="${version}">unknown</span>
|
||||
</div>
|
||||
<div class="build-chip">
|
||||
<div class="build-chip" th:if="${showCommitChip}">
|
||||
<span class="muted">Build</span>
|
||||
<a
|
||||
class="version-badge version-link"
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<span class="muted">Version</span>
|
||||
<span class="version-badge" th:text="${version}">unknown</span>
|
||||
</div>
|
||||
<div class="build-chip">
|
||||
<div class="build-chip" th:if="${showCommitChip}">
|
||||
<span class="muted">Build</span>
|
||||
<a
|
||||
class="version-badge version-link"
|
||||
|
||||
Reference in New Issue
Block a user