Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
My hack start at creating a script for auto-submitting a diff to
# ask the user for a gist name
param (
[string]$gistname = "$(Read-Host 'Enter a name for the gist')"
# constant
$gistapi = ""
$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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment