Skip to content

@timheuer /gistdiff.ps1
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
My hack start at creating a script for auto-submitting a diff to gist.github.com
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.