From 6899b96ff6b1c3a168814fd6f4e6bce0d1342386 Mon Sep 17 00:00:00 2001 From: xynydev Date: Sun, 17 Dec 2023 20:37:19 +0200 Subject: [PATCH] feat: edit boot menu yml --- src/components/ImageChooser/CreateRepo.svelte | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/components/ImageChooser/CreateRepo.svelte b/src/components/ImageChooser/CreateRepo.svelte index ca6dd05..c96678a 100644 --- a/src/components/ImageChooser/CreateRepo.svelte +++ b/src/components/ImageChooser/CreateRepo.svelte @@ -246,6 +246,46 @@ log += "Recipe updated successfully! \n"; } + const bootMenuRes = await fetch( + `https://api.github.com/repos/${custom.repo}/contents/boot_menu.yml`, + { + method: "get", + headers: { Authorization: `Bearer ${custom.auth}` }, + } + ); + const bootMenuJson = await bootMenuRes.json(); + if (!bootMenuRes.ok) { + log += "Error getting boot menu: \n"; + log += JSON.stringify(bootMenuJson); + log += "\n"; + } else { + log += "Boot menu got successfully! \n"; + } + const bootMenu = String(atob(bootMenuJson.content)); + + const bootMenuYml = YAML.parseDocument(bootMenu); + bootMenuYml.contents.deleteIn(['ublue_variants', 0]) + bootMenuYml.contents.addIn(['ublue_variants'], { label: custom.repo?.toLowerCase(), ks: '/kickstart/ublue-os.ks', flavors: [{ label: custom.name }] }) + + const bootMenuUpdateRes = await fetch( + `https://api.github.com/repos/${custom.repo}/contents/boot_menu.yml`, + { + method: "put", + headers: { Authorization: `Bearer ${custom.auth}` }, + body: JSON.stringify({ + message: + "chore(automatic): update boot_menu to match image", + content: btoa(YAML.stringify(bootMenuYml)), + sha: bootMenuJson.sha, + }), + } + ); + if (!bootMenuUpdateRes.ok) { + log += "Error updating boot menu. \n"; + } else { + log += "Boot menu updated successfully! \n"; + } + const workflowRes = await fetch( `https://api.github.com/repos/${custom.repo}/actions/permissions`, {