Skip to content

Instantly share code, notes, and snippets.

@PurpleBooth
Created February 15, 2023 10:37
Show Gist options
  • Select an option

  • Save PurpleBooth/8c974332e16f5f03aa82949c9e4f930d to your computer and use it in GitHub Desktop.

Select an option

Save PurpleBooth/8c974332e16f5f03aa82949c9e4f930d to your computer and use it in GitHub Desktop.

Revisions

  1. PurpleBooth created this gist Feb 15, 2023.
    22 changes: 22 additions & 0 deletions copy-labels.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/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