Created
February 13, 2026 08:24
-
-
Save alexrashed/b201aba03e146ce3f3e3ed0a88e9d0bb to your computer and use it in GitHub Desktop.
Script to sync autolink references from one repository to another
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
| #!/bin/bash | |
| # Script to sync GitHub autolink references from one repository to another | |
| # Usage: ./sync-autolinks.sh SOURCE_REPO DEST_REPO | |
| # Example: ./sync-autolinks.sh owner/source-repo owner/dest-repo | |
| set -e | |
| if [ $# -ne 2 ]; then | |
| echo "Usage: $0 SOURCE_REPO DEST_REPO" | |
| echo "Example: $0 owner/source-repo owner/dest-repo" | |
| exit 1 | |
| fi | |
| SOURCE_REPO=$1 | |
| DEST_REPO=$2 | |
| echo "Fetching autolink references from $SOURCE_REPO..." | |
| # Get autolinks from source repo | |
| autolinks=$(gh api "repos/$SOURCE_REPO/autolinks" --paginate) | |
| # Check if there are any autolinks | |
| if [ "$autolinks" = "[]" ]; then | |
| echo "No autolink references found in $SOURCE_REPO" | |
| exit 0 | |
| fi | |
| # Parse and create each autolink in destination repo | |
| echo "$autolinks" | jq -c '.[]' | while read -r autolink; do | |
| key_prefix=$(echo "$autolink" | jq -r '.key_prefix') | |
| url_template=$(echo "$autolink" | jq -r '.url_template') | |
| is_alphanumeric=$(echo "$autolink" | jq -r '.is_alphanumeric') | |
| echo "Creating autolink: $key_prefix -> $url_template" | |
| gh api "repos/$DEST_REPO/autolinks" \ | |
| -X POST \ | |
| -f key_prefix="$key_prefix" \ | |
| -f url_template="$url_template" \ | |
| -F is_alphanumeric="$is_alphanumeric" \ | |
| > /dev/null | |
| echo " ✓ Created" | |
| done | |
| echo "" | |
| echo "Successfully synced autolink references from $SOURCE_REPO to $DEST_REPO" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment