# The forges tempo is mirrored to, read from forges.toml.use convert;
use fs;
use os;
use toml;
import"@deckyard/codehost/"as codehost;
/** A forge and the repository on it. */exportdefstruct Site {
forge ascodehost.Forge,
repo asstring
};
/**
* Connect to every forge in the configuration: the TOML file `FORGES`
* names, by default `forges.toml`.
*
* @return {list of Site} the forges, in the file's order
*/exportfuncload() {
def file asstringinit"forges.toml";
if (os.getEnv("FORGES") != "") {
$file = os.getEnv("FORGES");
}
def doc astoml.Value inittoml.decode(fs.readString($file));
def out aslistof Site init [];
for (def i in0..toml.length($doc, "/forge")) {
def p asstringinit"/forge/" + convert.toString($i);
def f ascodehost.Forge initcodehost.connect(
toml.asString($doc, $p + "/backend"),
toml.asString($doc, $p + "/host"),
os.getEnv(toml.asString($doc, $p + "/token")));
$out[] = Site{forge: $f, repo: toml.asString($doc, $p + "/repo")};
}
return$out;
}