Skip to content

Instantly share code, notes, and snippets.

@PurpleBooth
Created February 15, 2023 10:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PurpleBooth/8c974332e16f5f03aa82949c9e4f930d to your computer and use it in GitHub Desktop.
Save PurpleBooth/8c974332e16f5f03aa82949c9e4f930d to your computer and use it in GitHub Desktop.
Copy labels between repos on github
#!/usr/bin/env bash
set -xeuo pipefail
# Set the source repository
SOURCE_REPO=org-name/source-repo
# Set the target repository
TARGET_REPO=org-name/dest-repo
# Get a list of labels from the source repo
LABELS=$(curl -H "Authorization: token $GITHUB_TOKEN" -s https://api.github.com/repos/$SOURCE_REPO/labels)
# Iterate over each label
echo "$LABELS" | jq -r --compact-output '.[]' | while read LABEL; do
# Extract the label name and color
NAME=$(echo "$LABEL" | jq -r ".name")
COLOR=$(echo "$LABEL" | jq -r ".color")
# Create the label on the target repo
curl -s -XPOST -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/$TARGET_REPO/labels -d "{\"name\":\"$NAME\",\"color\":\"$COLOR\"}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment