feat(caprover): allow human to mark an app as successfully updated
This commit is contained in:
@@ -2,6 +2,7 @@ import AppQueries from "../domain/AppQueries";
|
||||
import { UpdateDefinition } from "../domain/projections/ApplicationUpdates";
|
||||
import Caprover, { Application } from "../services/Caprover";
|
||||
import DockerHub from "../services/DockerHub";
|
||||
import Human from "../services/Human";
|
||||
import Layout, { html } from "../ui/Layout";
|
||||
|
||||
const UpdateForm = (application: Application, latestVersions: string[]) => {
|
||||
@@ -17,7 +18,7 @@ const UpdateForm = (application: Application, latestVersions: string[]) => {
|
||||
return html`<option value="${version}">${version}</option>`;
|
||||
})}
|
||||
</select>
|
||||
<button type="submit">Update</button>
|
||||
<button type="submit" name="action" value="update">Update</button>
|
||||
</form>`;
|
||||
};
|
||||
|
||||
@@ -28,11 +29,15 @@ const FreeUpdateForm = (application: Application) => {
|
||||
Manual version
|
||||
<input name="version" placeholder="hello-world:latest" type="text" />
|
||||
</label>
|
||||
<button type="submit">Update</button>
|
||||
<button type="submit" name="action" value="update">Update</button>
|
||||
</form>`;
|
||||
};
|
||||
|
||||
const PendingUpdates = (pendingUpdates: UpdateDefinition[], logs: string) => {
|
||||
const PendingUpdates = (
|
||||
application: Application,
|
||||
pendingUpdates: UpdateDefinition[],
|
||||
logs: string
|
||||
) => {
|
||||
if (pendingUpdates.length === 0) {
|
||||
return "";
|
||||
}
|
||||
@@ -47,13 +52,19 @@ const PendingUpdates = (pendingUpdates: UpdateDefinition[], logs: string) => {
|
||||
.join("")}
|
||||
</ul>
|
||||
|
||||
<pre>${logs}</pre>
|
||||
<pre class="logs">${logs}</pre>
|
||||
<button
|
||||
id="refresh"
|
||||
onclick="window.location.replace('#refresh'); window.location.reload();"
|
||||
>
|
||||
Refresh
|
||||
</button>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="appName" value="${application.name}" />
|
||||
<button type="submit" name="action" value="mark-as-updated">
|
||||
Mark as successfully updated!
|
||||
</button>
|
||||
</form>
|
||||
</section>`;
|
||||
};
|
||||
|
||||
@@ -66,7 +77,7 @@ const Page = (
|
||||
return html`<div>
|
||||
<h1>Updating ${application.name}</h1>
|
||||
|
||||
${PendingUpdates(pendingUpdates, logs)}
|
||||
${PendingUpdates(application, pendingUpdates, logs)}
|
||||
|
||||
<section>
|
||||
<dl>
|
||||
@@ -99,14 +110,34 @@ export default async (
|
||||
req: Request,
|
||||
caprover: Caprover,
|
||||
dockerHub: DockerHub,
|
||||
human: Human,
|
||||
queries: AppQueries
|
||||
): Promise<Response> => {
|
||||
if (req.method === "POST") {
|
||||
const body = await req.formData();
|
||||
await caprover.updateApplication(
|
||||
body.get("appName") as string,
|
||||
body.get("version") as string
|
||||
);
|
||||
switch (body.get("action")) {
|
||||
case "update":
|
||||
const appName = body.get("appName") as string;
|
||||
await caprover.updateApplication(
|
||||
appName,
|
||||
body.get("version") as string
|
||||
);
|
||||
|
||||
const url = new URL(req.url);
|
||||
url.searchParams.set("name", appName);
|
||||
return new Response(null, {
|
||||
status: 301,
|
||||
headers: { Location: url.toString() },
|
||||
});
|
||||
case "mark-as-updated":
|
||||
human.markApplicationAsUpdated(body.get("appName") as string);
|
||||
return new Response(null, {
|
||||
status: 301,
|
||||
headers: { Location: "/applications" },
|
||||
});
|
||||
default:
|
||||
throw new Error(`Unsupported action ${body.get("action")}`);
|
||||
}
|
||||
}
|
||||
|
||||
const applications = await caprover.getApps();
|
||||
|
||||
Reference in New Issue
Block a user