From 13d705639cdc5ccedfb4eb4ecd4607bd7f24248f Mon Sep 17 00:00:00 2001 From: Brian Read Date: Tue, 12 Mar 2024 20:38:19 +0000 Subject: [PATCH] Add git-get-latest-tag.sh --- git-get-latest-tag.sh | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 git-get-latest-tag.sh diff --git a/git-get-latest-tag.sh b/git-get-latest-tag.sh new file mode 100755 index 0000000..72b21b7 --- /dev/null +++ b/git-get-latest-tag.sh @@ -0,0 +1,57 @@ +#!/bin/bash +if [[ $# -ne 2 ]]; then + echo "git-get-latest-tag.sh " + 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 []" + 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"