public
Created

My hack start at creating a script for auto-submitting a diff to gist.github.com

  • Download Gist
gistdiff.ps1
PowerShell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
# ask the user for a gist name
param (
[string]$gistname = "$(Read-Host 'Enter a name for the gist')"
)
 
# constant
$gistapi = "https://api.github.com/gists"
$filename = $gistname + '.diff'
$teststring = "`{`"description`": `"the description for this gist`",`"public`": true,`"files`": `{`"file1.txt`": `{`"content`": `"String file contents`"`}`}`}"
# get the diff from the current session
$diff = git diff
 
# build up the json object data
$data = (New-Object PSObject |
Add-Member -PassThru NoteProperty description $gistname |
Add-Member -PassThru NoteProperty public true |
Add-Member -PassThru NoteProperty files (New-Object PSObject |
Add-Member -PassThru NoteProperty $filename (New-Object PSObject |
Add-Member -PassThru NoteProperty content "testing"
) | ConvertTo-Json -Compress
) | ConvertTo-Json -Compress
) | ConvertTo-Json -Compress
 
# get the byte[] for the POST
#$bytes = [System.Text.Encoding]::ASCII.GetBytes($data)
Write-Host $data
 
# create the web client to post
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Content-Type", "application/vnd.github.beta+json")
$resp = $wc.UploadString($gistapi, $data)
 
# temp: write out the response
# ideally this would parse response, write out the resulting URI to the gist
Write-Host ([System.Text.Encoding]::ASCII).GetString($resp)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.