aboutsummaryrefslogtreecommitdiff
path: root/test/setup.ts
blob: 764c07a6316937834a6cb1d235475d1c721fb129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { access, mkdir, remove, writeFile } from "fs-extra";
import { config } from "dotenv";
import { EnvironmentVariables } from "./util";
import { Clone } from "nodegit";

config({ path: "test/test.env" });

const env = process.env as EnvironmentVariables;

export default async function(): Promise<void> {
	const can_access = await access(env.GIT_DIR)
		.then(() => true)
		.catch(() => false);

	if(can_access) {
		await remove(env.GIT_DIR);
	}

	await mkdir(env.GIT_DIR);

	const repository = await Clone.clone(env.AVAIL_REPO_URL, `${env.GIT_DIR}/${env.AVAIL_REPO}`, { bare: 1 });

	const config = await repository.config();
	await config.setString("user.name", "BobDylan");
	await config.setString("user.email", "bob@example.com");

	await repository.fetchAll();
	await repository.createTag((await repository.getMasterCommit()).id(), "1.2", "Fixed stuff");

	await writeFile(`${env.GIT_DIR}/${env.AVAIL_REPO}/owner`, "Bob");
}