Fix Changelog
This commit is contained in:
@@ -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<Buffer> =>
|
||||
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)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user