Get a GitHub User's BlueSky Profile with PowerShell
GitHubBlueSky.ps1
43 lines 1.3 kB view raw
1<# 2.SYNOPSIS 3 Get a GitHub user's BlueSky 4.DESCRIPTION 5 Gets an At Protocol Handle / BlueSky profile link for a GitHub user 6.EXAMPLE 7 ./GitHubBlueSky StartAutomating 8#> 9param([string]$UserName) 10 11# Globally cache to avoid repeat request (use script: inside of a function or module) 12if (-not $global:GitHubProfileCache) { 13 $global:GitHubProfileCache = [Ordered]@{} 14} 15 16# Get the user profile 17if (-not $global:GitHubProfileCache[$UserName]) { 18 $global:GitHubProfileCache[$UserName] = Invoke-WebRequest "https://github.com/$UserName" 19} 20 21# Skip empty entries 22if (-not $global:GitHubProfileCache[$UserName]) { return } 23 24$blueSkyProfile = ($global:GitHubProfileCache[$UserName].Links -match 'bsky' | Select-Object -ExpandProperty Href) 25 26# If we have a bluesky profile 27if ($blueSkyProfile) { 28 # output an object linking the profiles 29 [PSCustomObject]@{ 30 GitUserName = $UserName 31 GitHubProfile = "https://github.com/$UserName" 32 # and extract the username from the last segment 33 AtUserName = ($blueSkyProfile -as [uri]).Segments[-1] -replace '/' 34 BlueSkyProfile = $blueSkyProfile 35 } 36} else { 37 # Otherwise, just output the git info 38 [PSCustomObject]@{ 39 GitUserName = $UserName 40 GitHubProfile = "https://github.com/$UserName" 41 } 42} 43