Fix Changelog
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 21s
Build and Push Docker Images / build-frontend (push) Successful in 14s

This commit is contained in:
2026-03-22 22:14:17 +01:00
parent 7c644c941a
commit 7e6c5cc189

View File

@@ -3,7 +3,7 @@ import {createInvoicePDF, createTimeSheetPDF} from "../utils/pdf";
import {encodeBase64ToNiimbot, generateLabel, useNextNumberRangeNumber} from "../utils/functions"; import {encodeBase64ToNiimbot, generateLabel, useNextNumberRangeNumber} from "../utils/functions";
import { GetObjectCommand } from "@aws-sdk/client-s3"; import { GetObjectCommand } from "@aws-sdk/client-s3";
import { execFile } from "node:child_process"; import { execFile } from "node:child_process";
import { existsSync } from "node:fs"; import { existsSync, readFileSync } from "node:fs";
import path from "node:path"; import path from "node:path";
import { promisify } from "node:util"; import { promisify } from "node:util";
import dayjs from "dayjs"; import dayjs from "dayjs";
@@ -57,6 +57,42 @@ function resolveGitRoot() {
return null return null
} }
function getDeploymentChangelogFallback() {
const backendPackagePath = path.resolve(process.cwd(), "package.json")
let version = "unbekannt"
if (existsSync(backendPackagePath)) {
try {
const packageJson = JSON.parse(readFileSync(backendPackagePath, "utf-8"))
version = packageJson?.version || version
} catch (err) {
console.error("Could not read backend package.json for changelog fallback", err)
}
}
const commitHash =
process.env.RAILWAY_GIT_COMMIT_SHA ||
process.env.VERCEL_GIT_COMMIT_SHA ||
process.env.GITHUB_SHA ||
process.env.COMMIT_SHA ||
process.env.SOURCE_COMMIT ||
null
const committedAt =
process.env.BUILD_DATE ||
process.env.RENDER_GIT_COMMIT_DATE ||
process.env.VERCEL_GIT_COMMIT_DATE ||
new Date().toISOString()
return [{
hash: commitHash || `version-${version}`,
shortHash: commitHash ? commitHash.slice(0, 7) : `v${version}`,
subject: `Bereitgestellte Version ${version}`,
authorName: "Deployment",
committedAt
}]
}
export default async function functionRoutes(server: FastifyInstance) { export default async function functionRoutes(server: FastifyInstance) {
const streamToBuffer = async (stream: any): Promise<Buffer> => const streamToBuffer = async (stream: any): Promise<Buffer> =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
@@ -201,7 +237,11 @@ export default async function functionRoutes(server: FastifyInstance) {
const gitRoot = resolveGitRoot() const gitRoot = resolveGitRoot()
if (!gitRoot) { if (!gitRoot) {
return reply.code(500).send({ error: 'Git repository not found' }) return reply.send({
repositoryRoot: null,
source: 'deployment',
entries: getDeploymentChangelogFallback().slice(0, safeLimit)
})
} }
try { try {
@@ -232,11 +272,16 @@ export default async function functionRoutes(server: FastifyInstance) {
return reply.send({ return reply.send({
repositoryRoot: gitRoot, repositoryRoot: gitRoot,
source: 'git',
entries entries
}) })
} catch (err) { } catch (err) {
req.log.error(err) req.log.error(err)
return reply.code(500).send({ error: 'Failed to load changelog' }) return reply.send({
repositoryRoot: gitRoot,
source: 'deployment',
entries: getDeploymentChangelogFallback().slice(0, safeLimit)
})
} }
}) })