Skip to content

Instantly share code, notes, and snippets.

@elvarb
Created November 7, 2017 10:37
Show Gist options
  • Save elvarb/c680e52b83f069cc5e4cd2e8033999d3 to your computer and use it in GitHub Desktop.
Save elvarb/c680e52b83f069cc5e4cd2e8033999d3 to your computer and use it in GitHub Desktop.
Powershell script to list all dependencies in a Go project, if a dependency is found on Github the Github API is queried for the license
$username = "" # Github Username
$key = "" # Github API key
$goapp = "" # Go Project Name
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$key)))
$deps = ((go list -f '{{ .Deps }}' $goapp).Trim('[',']')).split(' ')
$deps | %{
write-host $_
if($_.StartsWith("github.com")) {
$licenseurl = ("https://api.github.com/repos"+$_.trim("github.com")+"/license").trim(" ")
try {
$license = invoke-restmethod $licenseurl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ErrorAction "SilentlyContinue"
$licensename = $license.license.name
} catch {
$licensename = "No license found"
}
write-host "-> License: " $licensename
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment