Skip to content

Instantly share code, notes, and snippets.

@KyMidd

KyMidd/asf.sh Secret

Created February 19, 2023 17:48
Show Gist options
  • Save KyMidd/0a6b3599787fcd2f0c68a43302a484ee to your computer and use it in GitHub Desktop.
Save KyMidd/0a6b3599787fcd2f0c68a43302a484ee to your computer and use it in GitHub Desktop.
# Check which branches exist
BRANCHES=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
https://api.github.com/repos/$GH_ORG/$GH_REPO/branches | jq -r '.[].name')
# If branch exists, set as default
if [[ $(echo "$BRANCHES" | grep -E "develop") ]]; then
echo "The develop branch exists"
# Check current default branch
REPO_DEFAULT_BRANCH=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GH_ORG/$GH_REPO | jq -r '.default_branch')
if [[ "$REPO_DEFAULT_BRANCH" == 'develop' ]]; then
echo "Develop is already the default branch, making no changes"
else
echo "Develop isn't the default branch, updating"
UPDATE_DEFAULT_BRANCH=$(curl -s \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GH_ORG/$GH_REPO \
-d '{"default_branch":"develop"}')
fi
else
echo "Develop doesn't exist, skip updating default branch"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment