Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
refactor: switch to bluebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
xynydev committed Feb 4, 2024
1 parent f2195c8 commit 806dacd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 52 deletions.
4 changes: 2 additions & 2 deletions content/hero.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Custom Operating System images based on Fedora
title: BlueBuild repo creator wizard
---

This is a collection of container images using Fedora's support for OCI/Docker containers as a [transport and delivery mechanism for operating system content.](https://fedoraproject.org/wiki/Changes/OstreeNativeContainerStable) That's nerdspeak for the ultimate Linux client: _the reliability of a Chromebook, but with the flexibility and power of a traditional Linux desktop._ At long last, we've ascended.
This site served many [Universal Blue](https://universal-blue.org/)-related functions previously, but never in an official capacity. It has now been adapted to generate a custom image repository based on [blue-build/template](https://github.com/blue-build/template) to be used as a placeholder until the functionality is ported over to the [BlueBuild website](https://blue-build.org/) or some other better structured BlueBuild project.
103 changes: 53 additions & 50 deletions src/components/ImageChooser/CreateRepo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let custom: CustomImage;
let forked: Promise<boolean>;
let again = false;
let useTemplate = false;
let useTemplate = true;
let log = "";
Expand All @@ -22,13 +22,13 @@
async function isForked() {
const res = await fetch(
`https://api.github.com/repos/ublue-os/startingpoint/forks`,
`https://api.github.com/repos/blue-build/template/forks`,
{
headers: { Authorization: `Bearer ${custom.auth}` },
}
);
const forks = await res.json();
// checks if the array containing all forks of startingpoint by custom.login is longer than 0
// checks if the array containing all forks of template by custom.login is longer than 0
return (
forks.filter((f: { owner: { login: string } }) => {
return f.owner.login == custom.login;
Expand All @@ -42,7 +42,7 @@
let repo: { owner: { login: string }; name: string };
if (useTemplate) {
const res = await fetch(
`https://api.github.com/repos/ublue-os/startingpoint/generate`,
`https://api.github.com/repos/blue-build/template/generate`,
{
method: "post",
headers: { Authorization: `Bearer ${custom.auth}` },
Expand All @@ -62,7 +62,7 @@
}
} else {
const res = await fetch(
`https://api.github.com/repos/ublue-os/startingpoint/forks`,
`https://api.github.com/repos/blue-build/template/forks`,
{
method: "post",
headers: { Authorization: `Bearer ${custom.auth}` },
Expand Down Expand Up @@ -93,48 +93,48 @@
};
});
// get sha of latest commit in `template`
let templateBranchRes = await fetch(
`https://api.github.com/repos/${custom.repo}/branches/template`,
{
method: "get",
headers: { Authorization: `Bearer ${custom.auth}` },
}
);
// when creating a fork it might take a while for the branch to exist, so we retry every second
while (templateBranchRes.status != 200) {
log += "Getting info for branch 'template' failed, retrying...\n";
await new Promise((r) => setTimeout(r, 1000));
templateBranchRes = await fetch(
`https://api.github.com/repos/${custom.repo}/branches/template`,
{
method: "get",
headers: { Authorization: `Bearer ${custom.auth}` },
}
);
}
const templateBranch = await templateBranchRes.json();
log += "Info for branch 'template' got succesfully! \n";
// // get sha of latest commit in `template`
// let templateBranchRes = await fetch(
// `https://api.github.com/repos/${custom.repo}/branches/template`,
// {
// method: "get",
// headers: { Authorization: `Bearer ${custom.auth}` },
// }
// );
// // when creating a fork it might take a while for the branch to exist, so we retry every second
// while (templateBranchRes.status != 200) {
// log += "Getting info for branch 'template' failed, retrying...\n";
// await new Promise((r) => setTimeout(r, 1000));
// templateBranchRes = await fetch(
// `https://api.github.com/repos/${custom.repo}/branches/template`,
// {
// method: "get",
// headers: { Authorization: `Bearer ${custom.auth}` },
// }
// );
// }
// const templateBranch = await templateBranchRes.json();
// log += "Info for branch 'template' got succesfully! \n";
// create branch called `live`
const newBranchRes = await fetch(
`https://api.github.com/repos/${custom.repo}/git/refs`,
{
method: "post",
headers: { Authorization: `Bearer ${custom.auth}` },
body: JSON.stringify({
ref: "refs/heads/live",
// this is a required parameter, the new branch is created from the sha
sha: templateBranch.commit.sha,
}),
}
);
if (!newBranchRes.ok) {
log += "Creating branch 'live' failed. \n";
throw new Error();
} else {
log += "New branch 'live' created succesfully! \n";
}
// // create branch called `live`
// const newBranchRes = await fetch(
// `https://api.github.com/repos/${custom.repo}/git/refs`,
// {
// method: "post",
// headers: { Authorization: `Bearer ${custom.auth}` },
// body: JSON.stringify({
// ref: "refs/heads/live",
// // this is a required parameter, the new branch is created from the sha
// sha: templateBranch.commit.sha,
// }),
// }
// );
// if (!newBranchRes.ok) {
// log += "Creating branch 'live' failed. \n";
// throw new Error();
// } else {
// log += "New branch 'live' created succesfully! \n";
// }
// update the default branch to "live" and set the description
const updateRes = await fetch(
Expand All @@ -143,7 +143,7 @@
method: "post",
headers: { Authorization: `Bearer ${custom.auth}` },
body: JSON.stringify({
default_branch: "live",
// default_branch: "live",
description:
custom.description != undefined
? custom.description
Expand All @@ -158,6 +158,9 @@
log += "Updated repo information successfully! \n";
}
// hacky fix for issues caused by repository being empty right after generation
await new Promise(r => setTimeout(r, 2000));
const readmeRes = await fetch(
`https://api.github.com/repos/${custom.repo}/contents/README.md`,
{
Expand All @@ -174,7 +177,7 @@
log += "README got successfully! \n";
}
let readme = String(atob(readmeJson.content));
readme = readme.replaceAll("ublue-os/startingpoint", custom.repo?.toLowerCase());
readme = readme.replaceAll("blue-build/template", custom.repo?.toLowerCase());
const readmeLines = readme.split("\n");
readmeLines[0] = `# ${custom.name}`;
readme = readmeLines.join("\n");
Expand All @@ -185,7 +188,7 @@
headers: { Authorization: `Bearer ${custom.auth}` },
body: JSON.stringify({
message:
"chore(automatic): replace all references to 'startingpoint'",
"chore(automatic): replace all references to 'template'",
content: btoa(readme),
sha: readmeJson.sha,
}),
Expand Down Expand Up @@ -337,7 +340,7 @@ Remember to include logs, both from the console (enable XHR) and here.";
{:else if authorized}
{#await forked then forked}
{#if forked && !useTemplate && log == ""}
It appears that you already have a fork of ublue-os/startingpoint. <br
It appears that you already have a fork of blue-build/template. <br
/>
Do you want to continue by creating a repository that is not a fork? (using
the template)
Expand Down

0 comments on commit 806dacd

Please sign in to comment.