From 7e6c5cc1897598de8ff005b12140e66c4e07bd11 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Sun, 22 Mar 2026 22:14:17 +0100 Subject: [PATCH] Fix Changelog --- backend/src/routes/functions.ts | 51 +++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/backend/src/routes/functions.ts b/backend/src/routes/functions.ts index 47943d8..35f726b 100644 --- a/backend/src/routes/functions.ts +++ b/backend/src/routes/functions.ts @@ -3,7 +3,7 @@ import {createInvoicePDF, createTimeSheetPDF} from "../utils/pdf"; import {encodeBase64ToNiimbot, generateLabel, useNextNumberRangeNumber} from "../utils/functions"; import { GetObjectCommand } from "@aws-sdk/client-s3"; import { execFile } from "node:child_process"; -import { existsSync } from "node:fs"; +import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { promisify } from "node:util"; import dayjs from "dayjs"; @@ -57,6 +57,42 @@ function resolveGitRoot() { 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) { const streamToBuffer = async (stream: any): Promise => new Promise((resolve, reject) => { @@ -201,7 +237,11 @@ export default async function functionRoutes(server: FastifyInstance) { const gitRoot = resolveGitRoot() 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 { @@ -232,11 +272,16 @@ export default async function functionRoutes(server: FastifyInstance) { return reply.send({ repositoryRoot: gitRoot, + source: 'git', entries }) } catch (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) + }) } })