Created
February 15, 2023 10:37
-
-
Save PurpleBooth/8c974332e16f5f03aa82949c9e4f930d to your computer and use it in GitHub Desktop.
Copy labels between repos on github
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
#!/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