Use environment for git sha url

This commit is contained in:
2026-01-09 19:20:18 +01:00
parent 22e6f1ecf4
commit 3cf78d4b04
6 changed files with 20 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ IMGFLOAT_GITHUB_CLIENT_REPO ?= client
IMGFLOAT_GITHUB_CLIENT_VERSION ?= 1.0.0
IMGFLOAT_ASSETS_PATH ?= ./assets
IMGFLOAT_PREVIEWS_PATH ?= ./previews
IMGFLOAT_COMMIT_URL_PREFIX ?= https://github.com/imgfloat/server/commit/
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE ?= 10MB
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE ?= 10MB
WATCHDIR = ./src/main
@@ -17,6 +18,7 @@ RUNTIME_ENV = IMGFLOAT_ASSETS_PATH=$(IMGFLOAT_ASSETS_PATH) \
IMGFLOAT_GITHUB_CLIENT_OWNER=$(IMGFLOAT_GITHUB_CLIENT_OWNER) \
IMGFLOAT_GITHUB_CLIENT_REPO=$(IMGFLOAT_GITHUB_CLIENT_REPO) \
IMGFLOAT_GITHUB_CLIENT_VERSION=$(IMGFLOAT_GITHUB_CLIENT_VERSION) \
IMGFLOAT_COMMIT_URL_PREFIX=$(IMGFLOAT_COMMIT_URL_PREFIX) \
IMGFLOAT_DB_PATH=$(IMGFLOAT_DB_PATH) \
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE=$(SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE) \
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE=$(SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE)

View File

@@ -26,6 +26,7 @@ Optional:
| Variable | Description | Example Value |
|----------|-------------|---------------|
| `IMGFLOAT_COMMIT_URL_PREFIX` | Git commit URL prefix used for the build link badge (unset to hide the badge) | https://github.com/imgfloat/server/commit/ |
| `TWITCH_REDIRECT_URI` | Override default redirect URI | http://localhost:8080/login/oauth2/code/twitch |
During development environment variables can be placed in the `.env` file at the project root to automatically load them. Be aware that these are only loaded when using the [Makefile](./Makefile) command `make run`.

View File

@@ -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());
}

View File

@@ -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() {

View File

@@ -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"

View File

@@ -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"