Skip to content

Instantly share code, notes, and snippets.

@ghostwriter
Created June 12, 2024 15:21
Show Gist options
  • Save ghostwriter/b8e388565712ca2f836cf8c4a67a1934 to your computer and use it in GitHub Desktop.
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.
#!/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