diff --git a/README.md b/README.md index ed1fe22..d52cc5b 100644 --- a/README.md +++ b/README.md @@ -170,3 +170,23 @@ optional: (in any order) Does: Display a "table" of each repo and the optional extras requested. + +## git-update-release-in-one-repo.sh +Update the release (draft/prerelease/release) +git-update-release-in-one-repo.sh [ | ] [draft|prerelease|release] [local] [debug] + +* \ can be any organisation or user on the remote or local GITEA instance +* \ name of the repo (package) +* \ Full tag of the release (inc SME if applicable) +* \ +* draft|prerelease|release + + +optional: (in any order) + +* \ used with org= and will use local GITEA instance, default remote - will be passed to \ +* \ run in debug mode + +Does: + +Resets the release specified to the type specified. diff --git a/git-delete-release-in-one-rep.sh b/git-delete-release-in-one-rep.sh new file mode 100755 index 0000000..5bd536d --- /dev/null +++ b/git-delete-release-in-one-rep.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# git-delete-release-in-one-rep.sh [ | ] +# +# 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-delete-release-in-one-rep.sh [ | ] [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-delete-release-in-one-rep.sh [ | ] [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 + # - find the id from the info provided + ID=999; + # TBD +else + ID=$3; +fi + +if [ $DEBUG ]; then echo "I:$ID"; fi + +# And then delete it by id. +RESPONSE=$(curl -s -X 'DELETE' \ + "$GITEAHOST/api/v1/repos/$2/$1/releases/$ID" \ + -H 'accept: application/json' \ + -H "Authorization: token $GITEAACCESSTOKEN") +if [ $DEBUG ]; then echo "$RESPONSE"; fi +exit 0 diff --git a/git-update-release-in-one-repo.sh b/git-update-release-in-one-repo.sh new file mode 100755 index 0000000..9b6644b --- /dev/null +++ b/git-update-release-in-one-repo.sh @@ -0,0 +1,121 @@ +#!/bin/bash +# +# git-update-release-in-one-repo.sh [ | ] [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 [ | ] [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 [ | ] [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 [ | ] [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 + # - 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 + +