Last active
February 23, 2016 16:52
-
-
Save JamesWoolfenden/c22078f0710a42cf7006 to your computer and use it in GitHub Desktop.
checks for new gists from a github user
This file contains 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
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