Last active
August 1, 2017 17:37
-
-
Save benjamine/8348022 to your computer and use it in GitHub Desktop.
move a git tag remotely using github API (avoiding any clone or fetch)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# moves a tag in a github repo | |
# | |
# Usage: github-tag <tag-name> <ref> <apirepourl> | |
# | |
# Examples: | |
# github-tag env-staging heads/release https://[email protected]/repos/user/reponame | |
# github-tag env-production tags/env-staging https://[email protected]/repos/user/reponame | |
if [ $# -lt 3 ] | |
then | |
echo "usage: github-tag <tag-name> <ref> <apirepourl> | |
examples: | |
github-tag env-staging heads/release https://[email protected]/repos/user/reponame | |
github-tag env-production tags/env-staging https://[email protected]/repos/user/reponame" | |
exit 1 | |
fi | |
echo "moving tag $1" | |
current_sha=$(curl -fs $3/git/refs/tags/$1 | awk '/sha/ { print $2 }' | sed s/[^a-z0-9]//g) | |
if [ $? -ne 0 ] | |
then | |
echo ' error getting tag $1' | |
exit $? | |
fi | |
echo " from $current_sha" | |
sha=$(curl -fs $3/git/refs/$2 | awk '/sha/ { print $2 }' | sed s/[^a-z0-9]//g) | |
if [ $? -ne 0 ] | |
then | |
echo ' error getting ref $2' | |
exit $? | |
fi | |
echo " to $sha" | |
curl -fs -X PATCH -H "Content-Type: application/json" -d '{"sha":"'$sha'","force":"true"}' $3/git/refs/tags/$1 | |
if [ $? -ne 0 ] | |
then | |
echo ' error moving tag' | |
exit $? | |
else | |
echo ' done!' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment