@@ -229,4 +229,102 @@ function New-GitHubPR
229
229
Invoke-RestMethod - Method Post - Uri $uri - Body $body - Headers $headers
230
230
}
231
231
232
- Export-ModuleMember - Function Copy-GitRepository , Submit-GitChanges , New-GitHubPR
232
+ function Publish-GitHubRelease
233
+ {
234
+ param (
235
+ [Parameter (Mandatory )]
236
+ [string ]
237
+ $Organization ,
238
+
239
+ [Parameter (Mandatory )]
240
+ [string ]
241
+ $Repository ,
242
+
243
+ [Parameter (Mandatory )]
244
+ [string ]
245
+ $Tag ,
246
+
247
+ [Parameter (Mandatory )]
248
+ [string ]
249
+ $ReleaseName ,
250
+
251
+ [Parameter (Mandatory )]
252
+ [string ]
253
+ $Description ,
254
+
255
+ [Parameter (Mandatory )]
256
+ [string ]
257
+ $GitHubToken ,
258
+
259
+ [Parameter ()]
260
+ [Alias (' Branch' , ' Commit' )]
261
+ [string ]
262
+ $Commitish ,
263
+
264
+ [Parameter ()]
265
+ [string []]
266
+ $AssetPath ,
267
+
268
+ [switch ]
269
+ $Draft ,
270
+
271
+ [switch ]
272
+ $Prerelease
273
+ )
274
+
275
+ $restParams = @ {
276
+ tag_name = $Tag
277
+ name = $ReleaseName
278
+ body = $Description
279
+ draft = [bool ]$Draft
280
+ prerelease = [bool ]$Prerelease
281
+ }
282
+
283
+ if ($Commitish )
284
+ {
285
+ $restParams.target_commitish = $Commitish
286
+ }
287
+
288
+ $restBody = ConvertTo-Json - InputObject $restParams
289
+ $uri = " https://api.github.com/repos/$Organization /$Repository /releases"
290
+ $headers = @ {
291
+ Accept = ' application/vnd.github.v3+json'
292
+ Authorization = " token $GitHubToken "
293
+ }
294
+
295
+ $response = Invoke-RestMethod - Method Post - Uri $uri - Body $restBody - Headers $headers
296
+
297
+ $releaseId = $response.id
298
+ $assetBaseUri = " https://uploads.github.com/repos/$Organization /$Repository /releases/$releaseId /assets"
299
+ foreach ($asset in $AssetPath )
300
+ {
301
+ $extension = [System.IO.Path ]::GetExtension($asset )
302
+ $fileName = [uri ]::EscapeDataString([System.IO.Path ]::GetFileName($asset ))
303
+ $contentType = ' text/plain'
304
+ switch ($extension )
305
+ {
306
+ { $_ -in ' .zip' , ' .vsix' }
307
+ {
308
+ $contentType = ' application/zip'
309
+ break
310
+ }
311
+
312
+ ' .json'
313
+ {
314
+ $contentType = ' application/json'
315
+ break
316
+ }
317
+ }
318
+
319
+ $assetUri = " ${assetBaseUri} ?name=$fileName "
320
+ $headers = @ {
321
+ Authorization = " token $GitHubToken "
322
+ }
323
+ # This can be very slow, but it does work
324
+ $null = Invoke-RestMethod - Method Post - Uri $assetUri - InFile $asset - ContentType $contentType - Headers $headers
325
+ }
326
+
327
+ return $response
328
+ }
329
+
330
+ Export-ModuleMember - Function Copy-GitRepository , Submit-GitChanges , New-GitHubPR , Publish-GitHubRelease
0 commit comments