Created
October 22, 2021 22:21
-
-
Save gaikaz/822792f017011e27c02c74f3f2f7380c to your computer and use it in GitHub Desktop.
Updates the default branch on all repositories on Codecov using the API
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/bash | |
# !! Script depends on jq !! | |
# https://stedolan.github.io/jq/ | |
# Updates the default branch on all repositories on Codecov using the API (v4.6) | |
# https://docs.codecov.com/reference/authorization | |
token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # Your API token here | |
platform=gh # { gh - Github | gl - Gitlab | bb - Bitbucket } | |
owner=xxxxxx # Replace with your org. or user name that holds the repos | |
branch=xxxxxx # Replace with the new branch to set | |
# Stop on first error | |
set -e | |
# Get and parse all repositories to a list. | |
# Notice that the limit is set to 100. The default is 20. Update as needed. | |
repos=$(curl -s -X GET https://codecov.io/api/${platform}/${owner}?limit=100 \ | |
-H "Authorization: ${token}" | jq -r '.repos | .[] | .name') | |
# Loop through the repositories and set the new branch to track | |
for repo in $repos; do | |
echo "📝 ${repo}" | |
curl -X POST https://codecov.io/api/pub/${platform}/${owner}/${repo}/settings \ | |
-d "{\"action\": \"branch\", \"branch\": \"${branch}\"}" \ | |
-H "Authorization: ${token}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment