Add git-get-latest-tag.sh

This commit is contained in:
Brian Read 2024-03-12 20:38:19 +00:00
parent c690004aca
commit 13d705639c

57
git-get-latest-tag.sh Executable file
View File

@ -0,0 +1,57 @@
#!/bin/bash
if [[ $# -ne 2 ]]; then
echo "git-get-latest-tag.sh <modulename> <organisation>"
exit 1
fi
inifilename=$(echo ~)"/.smegit/config"
if [ ! -e $inifilename ] ; then
# Not here, look at system default
if [ ! -e /etc/smegit.ini ] ; then
echo "No ini file found $inifiename or /etc/smegit.ini"
echo "git-cvs2git.sh <modulename> <organization> [<local>]"
exit 1
else
initfilename="/etc/smegit.ini"
fi
fi
while read -r line || [[ -n "$line" ]]; do
if [[ $line =~ ^\[.*\]$ ]]
then
section=${line#*[}
section=${section%]*}
else
if [[ $line =~ ^[^#]*= ]]
then
key=${line%=*}
value=${line#*=}
declare "${section}_${key}=$value"
fi
fi
done < "$inifilename"
DEBUG=
if [ ${smegit_DEBUG} == "true" ] ; then DEBUG=true ; fi
# Check that jq is installed
if command -v jq -V > /dev/null; then
if [ $DEBUG ] ; then echo "************Jq is installed" ; fi
else
echo "ERROR********************** jq is not installed (try EPEL)**************"
exit 1
fi
GITEAUser=${remote_USER}
GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN}
GITEAHOST=${remote_GITEAHOST}
REPO_OWNER="$2"
REPO_NAME="$1"
# Send request to Gitea API to get the list of tags
LATEST_TAG=$(curl -H "Authorization: token $GITEAACCESSTOKEN" -s $GITEAHOST/api/v1/repos/$REPO_OWNER/$REPO_NAME/tags | jq -r '.[0].name')
# Print the latest tag
echo "Latest tag for the repository $REPO_NAME is: $LATEST_TAG"