122 lines
3.0 KiB
Bash
Executable File
122 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# git-update-release-in-one-repo.sh <organisation> <repo> [ <releasetag> | <id> ] [draft|prerelease|release]
|
|
#
|
|
# Create the release (deleting one that is the same tag),
|
|
# then uploads the .src.rpm and .rpm as an attachment (deleting any one of the same name)
|
|
#
|
|
#
|
|
if [[ -z $1 ]] ; then
|
|
echo "git-update-release-in-one-repo.sh <organisation> <repo> [ <releasetag> | <id> ] [draft|prerelease|release] [local] [debug]"
|
|
exit 0
|
|
fi
|
|
|
|
if [[ -z $4 ]] ; then
|
|
echo "Must provide release type"
|
|
echo "git-update-release-in-one-repo.sh <organisation> <repo> [ <releasetag> | <id> ] [draft|prerelease|release] [local] [debug]"
|
|
exit 0
|
|
fi
|
|
|
|
|
|
#
|
|
# Pull in parameters from a config file ~/.smegit/config
|
|
#
|
|
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-update-release-in-one-repo.sh <organisation> <repo> [ <releasetag> | <id> ] [draft|prerelease|release] [local] [debug]"
|
|
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
|
|
GITEAUser=${remote_USER}
|
|
GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
|
GITEAHOST=${remote_GITEAHOST}
|
|
for param in $2 $3 $4 $5 $6 $7; do
|
|
if [ $param ] ; then
|
|
case $param in
|
|
local )
|
|
GITEAUser=${local_USER}
|
|
GITEAACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
|
GITEAHOST=${local_GITEAHOST}
|
|
;;
|
|
debug )
|
|
DEBUG=true ;;
|
|
* )
|
|
EXTRAPARAMS=$EXTRAPARAMS" "$param ;;
|
|
esac
|
|
else
|
|
break
|
|
fi
|
|
done
|
|
|
|
# Uses if ist char is numeric to see if an id or tag is provided
|
|
if [[ ! "${3:0:1}" =~ [0-9] ]]; then
|
|
# <organisation> <repo> <releasetag> - find the id from the info provided
|
|
ID=999;
|
|
# TBD
|
|
else
|
|
ID=$3;
|
|
fi
|
|
|
|
if [ $DEBUG ]; then echo "I:$ID"; fi
|
|
|
|
# And then edit it by id.
|
|
|
|
if [ $4 = "draft" ]; then
|
|
RESPONSE=$(curl -s -X 'PATCH' \
|
|
"$GITEAHOST/api/v1/repos/$2/$1/releases/$ID" \
|
|
-H 'accept: application/json' \
|
|
-H "Authorization: token $GITEAACCESSTOKEN" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"draft": true,
|
|
"prerelease": false
|
|
}')
|
|
elif [ $4 = "prerelease" ]; then
|
|
RESPONSE=$(curl -s -X 'PATCH' \
|
|
"$GITEAHOST/api/v1/repos/$2/$1/releases/$ID" \
|
|
-H 'accept: application/json' \
|
|
-H "Authorization: token $GITEAACCESSTOKEN" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"draft": false,
|
|
"prerelease": true
|
|
}')
|
|
else
|
|
RESPONSE=$(curl -s -X 'PATCH' \
|
|
"$GITEAHOST/api/v1/repos/$2/$1/releases/$ID" \
|
|
-H 'accept: application/json' \
|
|
-H "Authorization: token $GITEAACCESSTOKEN" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"draft": false,
|
|
"prerelease": false
|
|
}')
|
|
fi
|
|
if [ $DEBUG ]; then echo "$RESPONSE"; fi
|
|
exit 0
|
|
|
|
|