Skip to content

Commit

Permalink
chore: remove unused fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Nov 29, 2024
1 parent 777beb1 commit b780a46
Showing 1 changed file with 0 additions and 69 deletions.
69 changes: 0 additions & 69 deletions static/scripts/config-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,73 +202,4 @@ export class ConfigParser {
this.newConfigYml = YAML.stringify({ plugins: [] });
this.saveConfig();
}

async handleMissingStorageBranchOrFile(octokit: Octokit, owner: string, repo: string | null) {
let mostRecentDefaultHeadCommitSha;

try {
const { data: defaultBranchData } = await octokit.rest.repos.getCommit({
owner,
repo: repo ? repo : UBIQUITY_OS,
ref: repo ? "development" : "main",
});
mostRecentDefaultHeadCommitSha = defaultBranchData.sha;
} catch (er) {
throw new Error(`Failed to get default branch commit sha:\n ${String(er)}`);
}

// Check if the branch exists
try {
await octokit.rest.repos.getBranch({
owner,
repo: repo ? repo : UBIQUITY_OS,
branch: repo ? "development" : "main",
});
} catch (branchError) {
if (branchError instanceof RequestError || branchError instanceof Error) {
const { message } = branchError;
if (message.toLowerCase().includes(`branch not found`)) {
// Branch doesn't exist, create the branch
try {
await octokit.rest.git.createRef({
owner,
repo: repo ? repo : UBIQUITY_OS,
ref: `refs/heads/${repo ? "development" : "main"}`,
sha: mostRecentDefaultHeadCommitSha,
});
} catch (err) {
throw new Error(`Failed to create branch:\n ${String(err)}`);
}
} else {
throw new Error(`Failed to handle missing storage branch or file:\n ${String(branchError)}`);
}
} else {
throw new Error(`Failed to handle missing storage branch or file:\n ${String(branchError)}`);
}
}

try {
// Create or update the file
await octokit.rest.repos.createOrUpdateFileContents({
owner,
repo: repo ? repo : UBIQUITY_OS,
path: CONFIG_PATH,
branch: repo ? "development" : "main",
message: `chore: create ${CONFIG_PATH.replace(/([A-Z])/g, " $1").toLowerCase()}`,
content: btoa("{\n}"),
sha: mostRecentDefaultHeadCommitSha,
});
} catch (err) {
throw new Error(`Failed to create new config file:\n ${String(err)}`);
}

const config = localStorage.getItem("selectedConfig");

const msgParts = ["Created an empty", config, "config in", repo ? repo : `your org: ${owner}`];

toastNotification(msgParts.join(" "), {
type: "success",
actionText: "Continue",
});
}
}

0 comments on commit b780a46

Please sign in to comment.