Skip to content

Instantly share code, notes, and snippets.

@JamesWoolfenden
Last active February 23, 2016 16:52
Show Gist options
  • Save JamesWoolfenden/c22078f0710a42cf7006 to your computer and use it in GitHub Desktop.
Save JamesWoolfenden/c22078f0710a42cf7006 to your computer and use it in GitHub Desktop.
checks for new gists from a github user
param(
[string]$user="andrewh")
function show-recentgists
{
param(
[string]$user,
[int]$count)
$url ="https://api.github.com/users/$user/gists"
$data=(Invoke-webrequest $url).content|convertfrom-Json
$newgists=$data|sort-object created_at| select-object -last $count
$newgists.url
}
$url="https://api.github.com/users/$user"
$data=Invoke-webrequest $url
$previousfile="previous-$user.json"
$convert=$data.content|ConvertFrom-Json
if (!(test-path -path $previousfile))
{
write-error "First time run $previousfile not found"
$convert|ConvertTo-Json| Out-File $previousfile
write-warning "$previousfile written"
exit 1
}
else
{
$previous=(Get-Content "previous-$user.json") -join "`n" | ConvertFrom-Json
}
if(!($previous.public_gists -le $convert.public_gists))
{
write-host "Nothing to see"
}else{
$diffgists=$convert.public_gists-$previous.public_gists
Write-host "Found $diffgists new Gists"
show-recentgists -user $user -count $diffgists
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment