Guest User

Untitled

a guest
Dec 8th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. diff --git a/DiffGist.psm1 b/DiffGist.psm1
  2. index 89004da..a57686d 100644
  3. --- a/DiffGist.psm1
  4. +++ b/DiffGist.psm1
  5. @@ -1,11 +1,9 @@
  6. . (join-path $PSScriptRoot "/json 1.7.ps1")
  7. -
  8. function Get-Github-Credential($username) {
  9. $host.ui.PromptForCredential("Github Credential", "Please enter your Github user name and password.", $username, "")
  10. }
  11.  
  12. -
  13. -function New-Gist {
  14. +function New-DiffGist {
  15. <#
  16. .Synopsis
  17. Publishes Github Gists of current git diff.
  18. @@ -23,34 +21,31 @@ function New-Gist {
  19. The Github username which will own this Gist.
  20.  
  21. .Parameter Private
  22. - When specified, the Gist will be made private. Default is public.
  23. + When specified, the Gist will be made private. Default is private.
  24.  
  25. .Example
  26. diffgist -Description "Hello.js greets all visitors"
  27. - Publishing a public Gist
  28. + Publishing a private Gist
  29.  
  30. .Example
  31. - gist -File "Hello.js" -Description "Hello.js greets all visitors" -Private
  32. - Publishing a private Gist
  33. + diffgist -Name "Hello" -Description "Hello.js greets all visitors" -Public
  34. + Publishing a public Gist
  35. #>
  36. Param(
  37. [Parameter(Position=0, ValueFromPipeline=$true)]
  38. - [string]$Name = $null,
  39. + [string]$Name = "current.diff",
  40. [string]$Description = "",
  41. [string]$Username = $null,
  42. - [switch]$Private = $false
  43. + [switch]$Public = $false
  44. )
  45. BEGIN {
  46. $files = @{}
  47. }
  48. PROCESS {
  49.  
  50. - if ($Name -eq $null) {
  51. - write-host "You need to specify -Name parameter."
  52. - return
  53. - }
  54. -
  55. - $content = git diff
  56. + $difffile = git diff | Out-File "_current.diff"
  57. + $content = [IO.File]::ReadAllText("_current.diff")
  58. + [IO.File]::Delete("_current.diff")
  59.  
  60. $content = $content -replace "\\\\", "\\\\\\\\"
  61. $content = $content -replace "`t", "\\t"
  62. @@ -59,7 +54,7 @@ function New-Gist {
  63. $content = $content -replace """", "\\"""
  64. $content = $content -replace "/", "\\/"
  65.  
  66. - $files.Add($filename, $content)
  67. + $files.Add($Name, $content)
  68. }
  69. END {
  70.  
  71. @@ -67,14 +62,14 @@ function New-Gist {
  72.  
  73. $request = [Net.WebRequest]::Create($apiurl)
  74.  
  75. - $credential = $(Get-Github-Credential $Username)
  76. + $credential = $(Get-Github-Credential $Username)
  77.  
  78. if($credential -eq $null) {
  79. write-host "Github credentials are required."
  80. return
  81. }
  82.  
  83. - $username = $credential.Username.Substring(1)
  84. + $username = $credential.Username
  85. $password = $credential.Password
  86.  
  87. $bstrpassword= [Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
  88. @@ -96,7 +91,7 @@ function New-Gist {
  89.  
  90. $filesjson = $filesjson.TrimEnd(',')
  91.  
  92. - $isprivate = $Private.ToString().ToLower()
  93. + $ispublic = $Public.ToString().ToLower()
  94.  
  95. $body = "{
  96. ""description"": """ + $Description + """,
  97. @@ -104,8 +99,6 @@ function New-Gist {
  98. ""files"": {" + $filesjson + "}
  99. }"
  100.  
  101. - write-host $body
  102. -
  103. $bytes = [text.encoding]::Default.getbytes($body)
  104. $request.ContentLength = $bytes.Length
  105.  
  106. @@ -137,9 +130,11 @@ function New-Gist {
  107. $url = $result.html_url
  108.  
  109. write-output $url
  110. +
  111. + start $url
  112. }
  113. }
  114.  
  115. -new-alias diffgist Diff-Gist
  116. +new-alias diffgist New-DiffGist
  117.  
  118. -export-modulemember -alias * -function Diff-Gist
  119. +export-modulemember -alias * -function New-DiffGist
  120. diff --git a/build.ps1 b/build.ps1
  121. index 81affd0..bc9e5e3 100644
  122. --- a/build.ps1
  123. +++ b/build.ps1
  124. @@ -1,2 +1,2 @@
  125. New-ModuleManifest -Path PsGist.psd1 -Author "Ryan Cromwell" -CompanyName "EchelonTouch" -ModuleToProcess .\\PsGist.psm1 -Description "PsGist publishes Github Gists" -Copyright ""
  126. -
  127. +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 ""
  128. \\ No newline at end of file
Add Comment
Please, Sign In to add comment