From 4e8fe79e2b34465840423eea4a34a50c5717f227 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 23 Mar 2022 11:49:40 +0100 Subject: [PATCH] feat: Be able to redeploy PRs --- src/routes/applications/[id]/deploy.json.ts | 13 +++++++++++- .../applications/[id]/previews/index.svelte | 20 ++++++++++++++++++- .../applications/[id]/storage/index.svelte | 7 +++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/routes/applications/[id]/deploy.json.ts b/src/routes/applications/[id]/deploy.json.ts index 0e33c7ce0..59bd7d001 100644 --- a/src/routes/applications/[id]/deploy.json.ts +++ b/src/routes/applications/[id]/deploy.json.ts @@ -11,6 +11,7 @@ export const post: RequestHandler = async (event) => { if (status === 401) return { status, body }; const { id } = event.params; + const { pullmergeRequestId = null, branch } = await event.request.json(); try { const buildId = cuid(); const applicationFound = await db.getApplication({ id, teamId }); @@ -42,7 +43,17 @@ export const post: RequestHandler = async (event) => { type: 'manual' } }); - await buildQueue.add(buildId, { build_id: buildId, type: 'manual', ...applicationFound }); + if (pullmergeRequestId) { + await buildQueue.add(buildId, { + build_id: buildId, + type: 'manual', + ...applicationFound, + sourceBranch: branch, + pullmergeRequestId + }); + } else { + await buildQueue.add(buildId, { build_id: buildId, type: 'manual', ...applicationFound }); + } return { status: 200, body: { diff --git a/src/routes/applications/[id]/previews/index.svelte b/src/routes/applications/[id]/previews/index.svelte index 632dafb62..e78e46efd 100644 --- a/src/routes/applications/[id]/previews/index.svelte +++ b/src/routes/applications/[id]/previews/index.svelte @@ -26,15 +26,28 @@ export let applicationSecrets; import { getDomain } from '$lib/components/common'; import Secret from '../secrets/_Secret.svelte'; - import { get } from '$lib/api'; + import { get, post } from '$lib/api'; import { page } from '$app/stores'; import Explainer from '$lib/components/Explainer.svelte'; + import { errorNotification } from '$lib/form'; + import { toast } from '@zerodevx/svelte-toast'; const { id } = $page.params; async function refreshSecrets() { const data = await get(`/applications/${id}/secrets.json`); PRMRSecrets = [...data.secrets]; } + async function redeploy(container) { + try { + await post(`/applications/${id}/deploy.json`, { + pullmergeRequestId: container.pullmergeRequestId, + branch: container.branch + }); + toast.push('Application redeployed queued.'); + } catch ({ error }) { + return errorNotification(error); + } + }
@@ -90,6 +103,11 @@
{getDomain(container.fqdn)}
+
+ +
{/each} {:else}
diff --git a/src/routes/applications/[id]/storage/index.svelte b/src/routes/applications/[id]/storage/index.svelte index 88d0ac231..75b129d68 100644 --- a/src/routes/applications/[id]/storage/index.svelte +++ b/src/routes/applications/[id]/storage/index.svelte @@ -27,6 +27,7 @@ import { page } from '$app/stores'; import Storage from './_Storage.svelte'; import { get } from '$lib/api'; + import Explainer from '$lib/components/Explainer.svelte'; const { id } = $page.params; async function refreshStorage() { @@ -44,6 +45,12 @@
+
+ This is useful for storing data such as a database (SQLite) or a cache.'} + /> +