From 3fa0aa7873598c2f82e1a4184086c03c6d144458 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 13 Jan 2026 22:58:54 -0700 Subject: [PATCH] Add script to check for the existance of a tag in a Forgejo repo --- src/tagExists.mjs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/tagExists.mjs diff --git a/src/tagExists.mjs b/src/tagExists.mjs new file mode 100644 index 0000000..ee09813 --- /dev/null +++ b/src/tagExists.mjs @@ -0,0 +1,33 @@ +import axios from "axios"; + +const { + TAG_NAME, + FORGEJO_API_URL: API_URL, + FORGEJO_REPOSITORY: REPO, + FORGEJO_TOKEN: TOKEN, +} = process.env; + + +if (!TAG_NAME) { + console.log(`Tag name must not be blank`); + process.exit(1); +}; + +const requestURL = `${API_URL}/repos/${REPO}/tags/${TAG_NAME}`; + +const response = await axios.get( + requestURL, + { + headers: { Authorization: `token ${TOKEN}` }, + validateStatus: () => true, + }, +); + +// We actually *want* an error when the tag exists, instead of when +// it doesn't +if (response.status === 200) { + console.log(`Tag with name "${TAG_NAME}" already exists`); + process.exit(1); +}; + +console.log(`Tag with name "${TAG_NAME}" not found, proceeding`);