Created
August 22, 2012 16:23
-
-
Save timheuer/3427189 to your computer and use it in GitHub Desktop.
Change to allow the current diff to be a gist
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
diff --git a/DiffGist.psm1 b/DiffGist.psm1 | |
index 89004da..a57686d 100644 | |
--- a/DiffGist.psm1 | |
+++ b/DiffGist.psm1 | |
@@ -1,11 +1,9 @@ | |
. (join-path $PSScriptRoot "/json 1.7.ps1") | |
- | |
function Get-Github-Credential($username) { | |
$host.ui.PromptForCredential("Github Credential", "Please enter your Github user name and password.", $username, "") | |
} | |
- | |
-function New-Gist { | |
+function New-DiffGist { | |
<# | |
.Synopsis | |
Publishes Github Gists of current git diff. | |
@@ -23,34 +21,31 @@ function New-Gist { | |
The Github username which will own this Gist. | |
.Parameter Private | |
- When specified, the Gist will be made private. Default is public. | |
+ When specified, the Gist will be made private. Default is private. | |
.Example | |
diffgist -Description "Hello.js greets all visitors" | |
- Publishing a public Gist | |
+ Publishing a private Gist | |
.Example | |
- gist -File "Hello.js" -Description "Hello.js greets all visitors" -Private | |
- Publishing a private Gist | |
+ diffgist -Name "Hello" -Description "Hello.js greets all visitors" -Public | |
+ Publishing a public Gist | |
#> | |
Param( | |
[Parameter(Position=0, ValueFromPipeline=$true)] | |
- [string]$Name = $null, | |
+ [string]$Name = "current.diff", | |
[string]$Description = "", | |
[string]$Username = $null, | |
- [switch]$Private = $false | |
+ [switch]$Public = $false | |
) | |
BEGIN { | |
$files = @{} | |
} | |
PROCESS { | |
- if ($Name -eq $null) { | |
- write-host "You need to specify -Name parameter." | |
- return | |
- } | |
- | |
- $content = git diff | |
+ $difffile = git diff | Out-File "_current.diff" | |
+ $content = [IO.File]::ReadAllText("_current.diff") | |
+ [IO.File]::Delete("_current.diff") | |
$content = $content -replace "\\\\", "\\\\\\\\" | |
$content = $content -replace "`t", "\\t" | |
@@ -59,7 +54,7 @@ function New-Gist { | |
$content = $content -replace """", "\\""" | |
$content = $content -replace "/", "\\/" | |
- $files.Add($filename, $content) | |
+ $files.Add($Name, $content) | |
} | |
END { | |
@@ -67,14 +62,14 @@ function New-Gist { | |
$request = [Net.WebRequest]::Create($apiurl) | |
- $credential = $(Get-Github-Credential $Username) | |
+ $credential = $(Get-Github-Credential $Username) | |
if($credential -eq $null) { | |
write-host "Github credentials are required." | |
return | |
} | |
- $username = $credential.Username.Substring(1) | |
+ $username = $credential.Username | |
$password = $credential.Password | |
$bstrpassword= [Runtime.InteropServices.Marshal]::SecureStringToBSTR($password) | |
@@ -96,7 +91,7 @@ function New-Gist { | |
$filesjson = $filesjson.TrimEnd(',') | |
- $isprivate = $Private.ToString().ToLower() | |
+ $ispublic = $Public.ToString().ToLower() | |
$body = "{ | |
""description"": """ + $Description + """, | |
@@ -104,8 +99,6 @@ function New-Gist { | |
""files"": {" + $filesjson + "} | |
}" | |
- write-host $body | |
- | |
$bytes = [text.encoding]::Default.getbytes($body) | |
$request.ContentLength = $bytes.Length | |
@@ -137,9 +130,11 @@ function New-Gist { | |
$url = $result.html_url | |
write-output $url | |
+ | |
+ start $url | |
} | |
} | |
-new-alias diffgist Diff-Gist | |
+new-alias diffgist New-DiffGist | |
-export-modulemember -alias * -function Diff-Gist | |
+export-modulemember -alias * -function New-DiffGist | |
diff --git a/build.ps1 b/build.ps1 | |
index 81affd0..bc9e5e3 100644 | |
--- a/build.ps1 | |
+++ b/build.ps1 | |
@@ -1,2 +1,2 @@ | |
New-ModuleManifest -Path PsGist.psd1 -Author "Ryan Cromwell" -CompanyName "EchelonTouch" -ModuleToProcess .\\PsGist.psm1 -Description "PsGist publishes Github Gists" -Copyright "" | |
- | |
+New-ModuleManifest -Path DiffGist.psd1 -Author "Tim Heuer" -CompanyName "Tim Heuer" -ModuleToProcess .\\DiffGist.psm1 -Description "DiffGist publishes Github Gists based on current git diff" -Copyright "" | |
\\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment