import { fetch } from "https://esm.town/v/std/fetch";
import { getTagForNextRelease } from "https://esm.town/v/vinspee/getTagForNextRelease";
import process from "node:process";
export async function createRelease(
req: express.Request,
res: express.Response
) {
if (
req.query.authentication === process.env.VERSITY_RELEASE_API_KEY
) {
const tag = await getTagForNextRelease();
const releaseRes = await fetch(
`https://api.github.com/repos/Endeavor-Digital/versity/releases`,
{
method: "POST",
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.VERSITY_RELEASE_GITHUB_TOKEN}`,
"X-GitHub-Api-Version": "2022-11-28",
},
body: JSON.stringify({
owner: "Endeavor-Digital",
repo: "versity",
tag_name: tag,
target_commitish: "main",
name: tag,
body: req.params.body ?? "",
draft: true,
prerelease: true,
generate_release_notes: true,
}),
}
).then((resp) => resp.json());
console.log({ releaseRes });
return res.redirect(302, releaseRes.html_url);
} else {
return res.status(403).json({
error: {
message: "No Auth",
},
});
}
}