Created
June 12, 2024 15:21
-
-
Save ghostwriter/b8e388565712ca2f836cf8c4a67a1934 to your computer and use it in GitHub Desktop.
Using the `gh` to query repositories and set secrets for each non-fork repository.
This file contains hidden or 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 | |
# GitHub username/organization | |
USERNAME="ghostwriter" | |
# Secret name and value | |
SECRET_KEY="CODECOV_TOKEN" | |
SECRET_VALUE="global-upload-token" | |
# Get the list of repositories for the user | |
repos=$(gh repo list "$USERNAME" --json nameWithOwner,isFork --jq '.[] | select(.isFork == false) | .nameWithOwner') | |
# Loop through each repository and set the secret | |
while IFS= read -r repo; do | |
echo "Setting secret for repository: $repo" | |
gh secret set "$SECRET_KEY" -b"$SECRET_VALUE" -R "$repo" | |
done <<< "$repos" | |
echo "Secret set for all non-fork repositories." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment