@@ -139,7 +139,7 @@ function New-GitHubReference
139
139
them individually.
140
140
141
141
. PARAMETER Reference
142
- The name of the fully qualified reference to be created (eg: heads/master)
142
+ The name of the reference to be created (eg: heads/master or tags/myTag )
143
143
144
144
. PARAMETER Sha
145
145
The SHA1 value for the reference to be created
@@ -227,3 +227,216 @@ function New-GitHubReference
227
227
228
228
return Invoke-GHRestMethod @params
229
229
}
230
+
231
+ function Update-GitHubReference
232
+ {
233
+ <#
234
+ . SYNOPSIS
235
+ Update a reference in a given GitHub repository.
236
+
237
+ . DESCRIPTION
238
+ Update a reference in a given GitHub repository.
239
+ The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
240
+
241
+ . PARAMETER OwnerName
242
+ Owner of the repository.
243
+ If not supplied here, the DefaultOwnerName configuration property value will be used.
244
+
245
+ . PARAMETER RepositoryName
246
+ Name of the repository.
247
+ If not supplied here, the DefaultRepositoryName configuration property value will be used.
248
+
249
+ . PARAMETER Uri
250
+ Uri for the repository.
251
+ The OwnerName and RepositoryName will be extracted from here instead of needing to provide
252
+ them individually.
253
+
254
+ . PARAMETER Reference
255
+ The name of the reference to be created (eg: heads/master or tags/myTag)
256
+
257
+ . PARAMETER Sha
258
+ The updated SHA1 value to be set for this reference
259
+
260
+ . PARAMETER Force
261
+ Indicates whether to force the update. If not set it will ensure that the update is a fast-forward update.
262
+
263
+ . PARAMETER AccessToken
264
+ If provided, this will be used as the AccessToken for authentication with the
265
+ REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
266
+
267
+ . PARAMETER NoStatus
268
+ If this switch is specified, long-running commands will run on the main thread
269
+ with no commandline status update. When not specified, those commands run in
270
+ the background, enabling the command prompt to provide status information.
271
+ If not supplied here, the DefaultNoStatus configuration property value will be used.
272
+
273
+ . EXAMPLE
274
+ Update-GitHubReference -OwnerName Powershell -RepositoryName PowerShellForGitHub -Reference heads/master -Sha aa218f56b14c9653891f9e74264a383fa43fefbd
275
+ #>
276
+ [CmdletBinding (
277
+ SupportsShouldProcess ,
278
+ DefaultParametersetName = ' Elements' )]
279
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSShouldProcess" , " " , Justification= " Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently." )]
280
+ param (
281
+ [Parameter (ParameterSetName = ' Elements' )]
282
+ [string ] $OwnerName ,
283
+
284
+ [Parameter (ParameterSetName = ' Elements' )]
285
+ [string ] $RepositoryName ,
286
+
287
+ [Parameter (
288
+ Mandatory ,
289
+ ParameterSetName = ' Uri' )]
290
+ [string ] $Uri ,
291
+
292
+ [Parameter (Mandatory )]
293
+ [string ] $Reference ,
294
+
295
+ [Parameter (Mandatory )]
296
+ [string ] $Sha ,
297
+
298
+ [switch ] $Force ,
299
+
300
+ [string ] $AccessToken ,
301
+
302
+ [switch ] $NoStatus
303
+ )
304
+
305
+ Write-InvocationLog - Invocation $MyInvocation
306
+
307
+ $elements = Resolve-RepositoryElements - BoundParameters $PSBoundParameters - DisableValidation
308
+ $OwnerName = $elements.ownerName
309
+ $RepositoryName = $elements.repositoryName
310
+
311
+ $telemetryProperties = @ {
312
+ ' OwnerName' = (Get-PiiSafeString - PlainText $OwnerName )
313
+ ' RepositoryName' = (Get-PiiSafeString - PlainText $RepositoryName )
314
+ }
315
+
316
+ if ($OwnerName -xor $RepositoryName )
317
+ {
318
+ $message = ' You must specify both Owner Name and Repository Name.'
319
+ Write-Log - Message $message - Level Error
320
+ throw $message
321
+ }
322
+
323
+ $uriFragment = " repos/$OwnerName /$RepositoryName /git/refs/$Reference "
324
+ $description = " Updating SHA for Reference $Reference in $RepositoryName to $Sha "
325
+
326
+ $hashBody = @ {
327
+ ' force' = $Force.IsPresent
328
+ ' sha' = $Sha
329
+ }
330
+
331
+ $params = @ {
332
+ ' UriFragment' = $uriFragment
333
+ ' Method' = ' Patch'
334
+ ' Body' = (ConvertTo-Json - InputObject $hashBody )
335
+ ' Description' = $description
336
+ ' AccessToken' = $AccessToken
337
+ ' TelemetryEventName' = $MyInvocation.MyCommand.Name
338
+ ' TelemetryProperties' = $telemetryProperties
339
+ ' NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue - Name NoStatus - ConfigValueName DefaultNoStatus)
340
+ }
341
+
342
+ return Invoke-GHRestMethod @params
343
+ }
344
+
345
+ function Remove-GitHubReference
346
+ {
347
+ <#
348
+ . SYNOPSIS
349
+ Delete a reference in a given GitHub repository.
350
+
351
+ . DESCRIPTION
352
+ Delete a reference in a given GitHub repository.
353
+ The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
354
+
355
+ . PARAMETER OwnerName
356
+ Owner of the repository.
357
+ If not supplied here, the DefaultOwnerName configuration property value will be used.
358
+
359
+ . PARAMETER RepositoryName
360
+ Name of the repository.
361
+ If not supplied here, the DefaultRepositoryName configuration property value will be used.
362
+
363
+ . PARAMETER Uri
364
+ Uri for the repository.
365
+ The OwnerName and RepositoryName will be extracted from here instead of needing to provide
366
+ them individually.
367
+
368
+ . PARAMETER Reference
369
+ The name of the reference to be deleted (eg: heads/master)
370
+
371
+ . PARAMETER AccessToken
372
+ If provided, this will be used as the AccessToken for authentication with the
373
+ REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
374
+
375
+ . PARAMETER NoStatus
376
+ If this switch is specified, long-running commands will run on the main thread
377
+ with no commandline status update. When not specified, those commands run in
378
+ the background, enabling the command prompt to provide status information.
379
+ If not supplied here, the DefaultNoStatus configuration property value will be used.
380
+
381
+ . EXAMPLE
382
+ Remove-GitHubReference -OwnerName Powershell -RepositoryName PowerShellForGitHub -Reference heads/master
383
+ #>
384
+ [CmdletBinding (
385
+ SupportsShouldProcess ,
386
+ DefaultParametersetName = ' Elements' )]
387
+ [Alias (' Delete-GitHubReference' )]
388
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSShouldProcess" , " " , Justification= " Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently." )]
389
+ param (
390
+ [Parameter (ParameterSetName = ' Elements' )]
391
+ [string ] $OwnerName ,
392
+
393
+ [Parameter (ParameterSetName = ' Elements' )]
394
+ [string ] $RepositoryName ,
395
+
396
+ [Parameter (
397
+ Mandatory ,
398
+ ParameterSetName = ' Uri' )]
399
+ [string ] $Uri ,
400
+
401
+ [Parameter (Mandatory )]
402
+ [string ] $Reference ,
403
+
404
+ [string ] $AccessToken ,
405
+
406
+ [switch ] $NoStatus
407
+ )
408
+
409
+ Write-InvocationLog - Invocation $MyInvocation
410
+
411
+ $elements = Resolve-RepositoryElements - BoundParameters $PSBoundParameters - DisableValidation
412
+ $OwnerName = $elements.ownerName
413
+ $RepositoryName = $elements.repositoryName
414
+
415
+ $telemetryProperties = @ {
416
+ ' OwnerName' = (Get-PiiSafeString - PlainText $OwnerName )
417
+ ' RepositoryName' = (Get-PiiSafeString - PlainText $RepositoryName )
418
+ }
419
+
420
+ if ($OwnerName -xor $RepositoryName )
421
+ {
422
+ $message = ' You must specify both Owner Name and Repository Name.'
423
+ Write-Log - Message $message - Level Error
424
+ throw $message
425
+ }
426
+
427
+ $uriFragment = " repos/$OwnerName /$RepositoryName /git/refs/$Reference "
428
+ $description = " Deleting Reference $Reference from repository $RepositoryName "
429
+
430
+ $params = @ {
431
+ ' UriFragment' = $uriFragment
432
+ ' Method' = ' Delete'
433
+ ' Body' = (ConvertTo-Json - InputObject $hashBody )
434
+ ' Description' = $description
435
+ ' AccessToken' = $AccessToken
436
+ ' TelemetryEventName' = $MyInvocation.MyCommand.Name
437
+ ' TelemetryProperties' = $telemetryProperties
438
+ ' NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue - Name NoStatus - ConfigValueName DefaultNoStatus)
439
+ }
440
+
441
+ return Invoke-GHRestMethod @params
442
+ }
0 commit comments