fix: update PR/MRs with new previewSeparator

This commit is contained in:
Andras Bacsai
2022-11-30 11:36:05 +01:00
parent 3d5ea8629c
commit 28ec164bc2
3 changed files with 24 additions and 4 deletions

View File

@@ -715,7 +715,7 @@ export async function stopTraefikProxy(
} }
export async function listSettings(): Promise<any> { export async function listSettings(): Promise<any> {
return await prisma.setting.findFirst({}); return await prisma.setting.findUnique({ where: { id: '0' } });
} }
export function generateToken() { export function generateToken() {

View File

@@ -2,7 +2,7 @@ import { promises as dns } from 'dns';
import { X509Certificate } from 'node:crypto'; import { X509Certificate } from 'node:crypto';
import * as Sentry from '@sentry/node'; import * as Sentry from '@sentry/node';
import type { FastifyReply, FastifyRequest } from 'fastify'; import type { FastifyReply, FastifyRequest } from 'fastify';
import { asyncExecShell, checkDomainsIsValidInDNS, decrypt, encrypt, errorHandler, isDev, isDNSValid, isDomainConfigured, listSettings, prisma, sentryDSN, version } from '../../../../lib/common'; import { asyncExecShell, checkDomainsIsValidInDNS, decrypt, encrypt, errorHandler, getDomain, isDev, isDNSValid, isDomainConfigured, listSettings, prisma, sentryDSN, version } from '../../../../lib/common';
import { AddDefaultRegistry, CheckDNS, CheckDomain, DeleteDomain, OnlyIdInBody, SaveSettings, SaveSSHKey, SetDefaultRegistry } from './types'; import { AddDefaultRegistry, CheckDNS, CheckDomain, DeleteDomain, OnlyIdInBody, SaveSettings, SaveSSHKey, SetDefaultRegistry } from './types';
@@ -68,10 +68,26 @@ export async function saveSettings(request: FastifyRequest<SaveSettings>, reply:
DNSServers, DNSServers,
proxyDefaultRedirect proxyDefaultRedirect
} = request.body } = request.body
const { id } = await listSettings(); const { id, previewSeparator: SetPreviewSeparator } = await listSettings();
if (numberOfDockerImagesKeptLocally) { if (numberOfDockerImagesKeptLocally) {
numberOfDockerImagesKeptLocally = Number(numberOfDockerImagesKeptLocally) numberOfDockerImagesKeptLocally = Number(numberOfDockerImagesKeptLocally)
} }
if (previewSeparator == '') {
previewSeparator = '.'
}
if (SetPreviewSeparator != previewSeparator) {
const applications = await prisma.application.findMany({ where: { previewApplication: { some: { id: { not: undefined } } } }, include: { previewApplication: true } })
for (const application of applications) {
for (const preview of application.previewApplication) {
const { protocol } = new URL(preview.customDomain)
const { pullmergeRequestId } = preview
const { fqdn } = application
const newPreviewDomain = `${protocol}//${pullmergeRequestId}${previewSeparator}${getDomain(fqdn)}`
await prisma.previewApplication.update({ where: { id: preview.id }, data: { customDomain: newPreviewDomain } })
}
}
}
await prisma.setting.update({ await prisma.setting.update({
where: { id }, where: { id },
data: { previewSeparator, numberOfDockerImagesKeptLocally, doNotTrack, isRegistrationEnabled, dualCerts, isAutoUpdateEnabled, isDNSCheckEnabled, DNSServers, isAPIDebuggingEnabled } data: { previewSeparator, numberOfDockerImagesKeptLocally, doNotTrack, isRegistrationEnabled, dualCerts, isAutoUpdateEnabled, isDNSCheckEnabled, DNSServers, isAPIDebuggingEnabled }

View File

@@ -166,12 +166,15 @@
} }
if (proxyDefaultRedirect !== settings.proxyDefaultRedirect) { if (proxyDefaultRedirect !== settings.proxyDefaultRedirect) {
await post(`/settings`, { proxyDefaultRedirect }); await post(`/settings`, { proxyDefaultRedirect });
settings.proxyDefaultRedirect = proxyDefaultRedirect;
} }
if (numberOfDockerImagesKeptLocally !== settings.numberOfDockerImagesKeptLocally) { if (numberOfDockerImagesKeptLocally !== settings.numberOfDockerImagesKeptLocally) {
await post(`/settings`, { numberOfDockerImagesKeptLocally }); await post(`/settings`, { numberOfDockerImagesKeptLocally });
settings.numberOfDockerImagesKeptLocally = numberOfDockerImagesKeptLocally;
} }
if (previewSeparator !== settings.previewSeparator) { if (previewSeparator !== settings.previewSeparator) {
await post(`/settings`, { previewSeparator }); await post(`/settings`, { previewSeparator });
settings.previewSeparator = previewSeparator;
} }
if (minPort !== settings.minPort || maxPort !== settings.maxPort) { if (minPort !== settings.minPort || maxPort !== settings.maxPort) {
await post(`/settings`, { minPort, maxPort }); await post(`/settings`, { minPort, maxPort });
@@ -422,7 +425,7 @@
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<div> <div>
Preview Domain Seprator Preview Domain Separator
<Explainer <Explainer
position="dropdown-bottom" position="dropdown-bottom"
explanation="The separator used in the PR/MR previews.<br><br>For example if you set it to: <span class='text-yellow-400 font-bold'>-</span><br> the preview domain will be like this: <br><br><span class='text-yellow-400 font-bold'>PRMRNumber-yourdomain.com</span><br><br>The default is: <span class='text-yellow-400 font-bold'>.</span><br>so the preview domain will be like this: <br><br><span class='text-yellow-400 font-bold'>PRMRNumber.yourdomain.com</span>" explanation="The separator used in the PR/MR previews.<br><br>For example if you set it to: <span class='text-yellow-400 font-bold'>-</span><br> the preview domain will be like this: <br><br><span class='text-yellow-400 font-bold'>PRMRNumber-yourdomain.com</span><br><br>The default is: <span class='text-yellow-400 font-bold'>.</span><br>so the preview domain will be like this: <br><br><span class='text-yellow-400 font-bold'>PRMRNumber.yourdomain.com</span>"
@@ -430,6 +433,7 @@
</div> </div>
<input <input
class="w-full" class="w-full"
required
bind:value={previewSeparator} bind:value={previewSeparator}
readonly={!$appSession.isAdmin} readonly={!$appSession.isAdmin}
disabled={!$appSession.isAdmin} disabled={!$appSession.isAdmin}