Created
February 13, 2026 09:17
-
-
Save alexrashed/c39af22560c27ed56b6af6816f8f649f to your computer and use it in GitHub Desktop.
Script to sync linear teams with GitHub autolink references
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 Linear team autolink references to a GitHub repository | |
| # Usage: ./sync-autolinks.sh LINEAR_WORKSPACE DEST_REPO | |
| # Example: ./sync-autolinks.sh myworkspace owner/dest-repo | |
| # Requires: LINEAR_API_KEY environment variable to be set | |
| set -e | |
| if [ $# -ne 2 ]; then | |
| echo "Usage: $0 LINEAR_WORKSPACE DEST_REPO" | |
| echo "Example: $0 myworkspace owner/dest-repo" | |
| echo "" | |
| echo "Required: LINEAR_API_KEY environment variable must be set" | |
| exit 1 | |
| fi | |
| if [ -z "$LINEAR_API_KEY" ]; then | |
| echo "Error: LINEAR_API_KEY environment variable is not set" | |
| echo "Please set it with: export LINEAR_API_KEY=your_api_key" | |
| exit 1 | |
| fi | |
| LINEAR_WORKSPACE=$1 | |
| DEST_REPO=$2 | |
| echo "Fetching teams from Linear workspace: $LINEAR_WORKSPACE..." | |
| # GraphQL query to fetch all teams | |
| query='{ | |
| "query": "query { teams { nodes { id key name } } }" | |
| }' | |
| # Fetch teams from Linear API | |
| teams_response=$(curl -s -X POST https://api.linear.app/graphql \ | |
| -H "Content-Type: application/json" \ | |
| -H "Authorization: $LINEAR_API_KEY" \ | |
| -d "$query") | |
| # Extract teams array | |
| teams=$(echo "$teams_response" | jq -r '.data.teams.nodes') | |
| # Check if there are any teams | |
| if [ "$teams" = "[]" ] || [ "$teams" = "null" ]; then | |
| echo "No teams found in Linear workspace" | |
| exit 0 | |
| fi | |
| # Count teams | |
| team_count=$(echo "$teams" | jq 'length') | |
| echo "Found $team_count team(s)" | |
| echo "" | |
| # List all teams | |
| echo "Teams:" | |
| echo "$teams" | jq -r '.[] | " - \(.key): \(.name)"' | |
| echo "" | |
| # Fetch existing autolinks from destination repo | |
| echo "Fetching existing autolinks from $DEST_REPO..." | |
| existing_autolinks=$(gh api "repos/$DEST_REPO/autolinks" --paginate) | |
| echo "" | |
| # Parse and create each autolink in destination repo | |
| echo "$teams" | jq -c '.[]' | while read -r team; do | |
| team_key=$(echo "$team" | jq -r '.key') | |
| team_name=$(echo "$team" | jq -r '.name') | |
| key_prefix="${team_key}-" | |
| url_template="https://linear.app/$LINEAR_WORKSPACE/issue/${team_key}-<num>" | |
| # Check if autolink already exists | |
| exists=$(echo "$existing_autolinks" | jq --arg prefix "$key_prefix" '[.[] | select(.key_prefix == $prefix)] | length > 0') | |
| if [ "$exists" = "true" ]; then | |
| echo "Skipping team '$team_name': $key_prefix (already exists)" | |
| continue | |
| fi | |
| echo "Creating autolink for team '$team_name': $key_prefix -> $url_template" | |
| response=$(gh api "repos/$DEST_REPO/autolinks" \ | |
| -X POST \ | |
| -f key_prefix="$key_prefix" \ | |
| -f url_template="$url_template" \ | |
| -F is_alphanumeric=false 2>&1) || { | |
| echo " ✗ Failed to create autolink" | |
| echo " Error: $response" | |
| continue | |
| } | |
| echo " ✓ Created" | |
| done | |
| echo "" | |
| echo "Successfully created autolink references for all Linear teams in $DEST_REPO" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment