Skip to content

Instantly share code, notes, and snippets.

@mislav
Last active February 15, 2021 14:19
Show Gist options
  • Save mislav/fec2059a1b3e02e6eea9965392ddd39a to your computer and use it in GitHub Desktop.
Save mislav/fec2059a1b3e02e6eea9965392ddd39a to your computer and use it in GitHub Desktop.
# Usage: bash label-copy.sh <source-repo> <destination-repo> <label-names>...
#
# Requirements: GitHub CLI, jq
#
# Example:
# brew install gh jq
# bash label-copy.sh owner/repo1 owner/repo2 "bug" "help wanted" "feature"
#
set -e
source_repo="${1?}"
destination_repo="${2?}"
shift 2
ascii_downcase() {
tr 'A-Z' 'a-z'
}
selected=()
for label_name; do
selected+=("$(ascii_downcase <<<"$label_name")")
done
post_args=()
IFS=$'\t'
gh api "repos/$source_repo/labels" | jq -r '.[] | [.name,.color,.description] | @tsv' | while read name color description; do
for s in "${selected[@]}"; do
if [ "$s" == "$(ascii_downcase <<<"$name")" ]; then
gh api --silent "repos/$destination_repo/labels" -f name="$name" -f color="$color" -f description="$description"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment