Skip to content

Instantly share code, notes, and snippets.

@caoer
Created June 19, 2020 08:14
Show Gist options
  • Save caoer/2f3fab1bf3cc90f60bf0ee4ed16ac245 to your computer and use it in GitHub Desktop.
Save caoer/2f3fab1bf3cc90f60bf0ee4ed16ac245 to your computer and use it in GitHub Desktop.
github-utils.zsh
github_current_repo() {
local REPO=`git remote -v show | awk 'NR==1 {print $2}' | sed 's/[email protected]://' | sed 's/\.git$//'`
echo $REPO
}
github_deployment_create() {
REPO=`github_current_repo`
if [ -z "${2-}" ]
then
echo github_deployment_create TASK ENV [BRANCH]
return
fi
if [ -z "${3-}" ]; then
REF=master
else
REF=$3
fi
TASK=$1
ENV=$2
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.ant-man-preview+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/$REPO/deployments \
--data '{"ref": '\""${REF}"\"', "environment": '\""$ENV"\"', "task":'\""${TASK}"\"', "required_contexts": []}'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment