diff --git a/scripts/tagExists.mjs b/scripts/tagExists.mjs index 2a266b5..f9e1206 100644 --- a/scripts/tagExists.mjs +++ b/scripts/tagExists.mjs @@ -1,11 +1,28 @@ +import axios from "axios"; + const { TAG_NAME, - FORGEJO_API_URL, - FORGEJO_REPOSITORY, - FORGEJO_REPOSITORY_OWNER, + FORGEJO_API_URL: API_URL, + FORGEJO_REPOSITORY: REPO, + FORGEJO_TOKEN: TOKEN, } = process.env; +async function main() { + const requestURL = `${API_URL}/repos/${REPO}/tags/${TAG_NAME}`; -console.log(process.env) + const response = await axios.get( + requestURL, + { + headers: { Authorization: `token ${TOKEN}` }, + validateStatus: () => true, + }, + ); -process.exit(1); + // We actually *want* an error when the tag exists, instead of when + // it doesn't + if (response.status === 200) { + process.exit(1); + }; +}; + +main();