import { __exportAll } from "../../../_virtual/_rolldown/runtime.js";
import { logger } from "../../../logger/index.js";
import { ExternalHostError } from "../../../types/errors/external-host-error.js";
import { PRESET_DEP_NOT_FOUND, fetchPreset, parsePreset } from "../util.js";
import { getRepoContents } from "../../../modules/platform/gitea/gitea-helper.js";

//#region lib/config/presets/gitea/index.ts
var gitea_exports = /* @__PURE__ */ __exportAll({
	Endpoint: () => Endpoint,
	fetchJSONFile: () => fetchJSONFile,
	getPreset: () => getPreset,
	getPresetFromEndpoint: () => getPresetFromEndpoint
});
const Endpoint = "https://gitea.com/";
async function fetchJSONFile(repo, fileName, endpoint, tag) {
	let res;
	try {
		res = await getRepoContents(repo, fileName, tag, { baseUrl: endpoint });
	} catch (err) {
		if (err instanceof ExternalHostError) throw err;
		logger.debug(`Preset file ${fileName} not found in ${repo}: ${err.message}`);
		throw new Error(PRESET_DEP_NOT_FOUND);
	}
	return parsePreset(res.contentString, fileName);
}
function getPresetFromEndpoint(repo, filePreset, presetPath, endpoint = Endpoint, tag) {
	return fetchPreset({
		repo,
		filePreset,
		presetPath,
		endpoint,
		tag,
		fetch: fetchJSONFile
	});
}
function getPreset({ repo, presetName = "default", presetPath, tag = void 0 }) {
	return getPresetFromEndpoint(repo, presetName, presetPath, Endpoint, tag);
}

//#endregion
export { gitea_exports };
//# sourceMappingURL=index.js.map