2024-12-14 10:49:35 +00:00
|
|
|
"use server";
|
|
|
|
|
2024-12-14 09:52:15 +00:00
|
|
|
import api from "@/lib/gitea";
|
|
|
|
import { GitEntry, APIError } from "gitea-js";
|
|
|
|
|
|
|
|
export async function retrieveTreeStructure(
|
|
|
|
owner: string,
|
|
|
|
repo: string,
|
|
|
|
sha: string
|
|
|
|
): Promise<GitEntry[]> {
|
|
|
|
try {
|
|
|
|
const response = await api.repos.getTree(owner, repo, sha, {
|
|
|
|
recursive: true,
|
|
|
|
});
|
|
|
|
return response.data.tree || [];
|
|
|
|
} catch (error) {
|
|
|
|
if ((error as APIError).message) {
|
2024-12-15 04:33:39 +00:00
|
|
|
console.error("Gitea API [getTree] Error", error);
|
2024-12-14 09:52:15 +00:00
|
|
|
} else {
|
|
|
|
console.error("Unexpected Error", error);
|
|
|
|
}
|
|
|
|
throw new Error("Failed to retrieve tree structure");
|
|
|
|
}
|
|
|
|
}
|
2024-12-15 04:33:39 +00:00
|
|
|
|
|
|
|
export async function retrieveFileContent(
|
|
|
|
owner: string,
|
|
|
|
repo: string,
|
|
|
|
path: string
|
|
|
|
): Promise<{ encoding: string; content: string }> {
|
|
|
|
try {
|
|
|
|
const response = await api.repos.repoGetContents(owner, repo, path);
|
|
|
|
const { encoding, content } = response.data;
|
|
|
|
return { encoding: encoding || "", content: content || "" };
|
|
|
|
} catch (error) {
|
|
|
|
if ((error as APIError).message) {
|
|
|
|
console.error("Gitea API [repoGetContents] Error", error);
|
|
|
|
} else {
|
|
|
|
console.error("Unexpected Error", error);
|
|
|
|
}
|
|
|
|
throw new Error("Failed to retrieve file contents");
|
|
|
|
}
|
|
|
|
}
|