@@ -461,6 +461,114 @@ function Get-GitHubRepository
461
461
return Invoke-GHRestMethodMultipleResult @params
462
462
}
463
463
464
+ function Rename-GitHubRepository
465
+ {
466
+ <#
467
+ . SYNOPSIS
468
+ Rename a GitHub repository
469
+
470
+ . DESCRIPTION
471
+ Renames a GitHub repository with the new name provided.
472
+
473
+ The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
474
+
475
+ . PARAMETER OwnerName
476
+ Owner of the repository.
477
+ If not supplied here, the DefaultOwnerName configuration property value will be used.
478
+
479
+ . PARAMETER RepositoryName
480
+ Name of the repository.
481
+ If not supplied here, the DefaultRepositoryName configuration property value will be used.
482
+
483
+ . PARAMETER Uri
484
+ Uri for the repository to rename. You can supply this directly, or more easily by
485
+ using Get-GitHubRepository to get the repository as you please, and then piping the result to this cmdlet
486
+
487
+ . PARAMETER NewName
488
+ The new name to set for the given GitHub repository
489
+
490
+ . PARAMETER AccessToken
491
+ If provided, this will be used as the AccessToken for authentication with the
492
+ REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
493
+
494
+ . PARAMETER NoStatus
495
+ If this switch is specified, long-running commands will run on the main thread
496
+ with no commandline status update. When not specified, those commands run in
497
+ the background, enabling the command prompt to provide status information.
498
+ If not supplied here, the DefaultNoStatus configuration property value will be used.
499
+
500
+ . EXAMPLE
501
+ Get-GitHubRepository -Owner octocat -RepositoryName hello-world | Rename-GitHubRepository -NewName hello-again-world
502
+ Get the given 'hello-world' repo from the user 'octocat' and rename it to be https://github.com/octocat/hello-again-world.
503
+ . EXAMPLE
504
+ Get-GitHubRepository -Uri https://github.com/octocat/hello-world | Rename-GitHubRepository -NewName hello-again-world -Confirm:$false
505
+ Get the repository at https://github.com/octocat/hello-world and then rename it https://github.com/octocat/hello-again-world. Will not prompt for confirmation, as -Confirm:$false was specified.
506
+
507
+ . EXAMPLE
508
+ Rename-GitHubRepository -Uri https://github.com/octocat/hello-world -NewName hello-again-world
509
+ Rename the repository at https://github.com/octocat/hello-world to https://github.com/octocat/hello-again-world.
510
+
511
+ . EXAMPLE
512
+ New-GitHubRepositoryFork -Uri https://github.com/octocat/hello-world | Foreach-Object {$_ | Rename-GitHubRepository -NewName "$($_.name)_fork"}
513
+ Fork the `hello-world` repository from the user 'octocat', and then rename the newly forked repository by appending '_fork'.
514
+ #>
515
+ [CmdletBinding (
516
+ SupportsShouldProcess ,
517
+ DefaultParametersetName = ' Uri' ,
518
+ ConfirmImpact = " High" )]
519
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSShouldProcess" , " " , Justification= " Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently." )]
520
+ param (
521
+ [Parameter (Mandatory = $true , ParameterSetName = ' Elements' )]
522
+ [string ] $OwnerName ,
523
+
524
+ [Parameter (Mandatory = $true , ParameterSetName = ' Elements' )]
525
+ [string ] $RepositoryName ,
526
+
527
+ [Parameter (
528
+ Mandatory ,
529
+ ValueFromPipelineByPropertyName ,
530
+ ParameterSetName = ' Uri' )]
531
+ [Alias (" html_url" )]
532
+ [string ] $Uri ,
533
+
534
+ [parameter (Mandatory )][String ]$NewName ,
535
+
536
+ [string ] $AccessToken ,
537
+
538
+ [switch ] $NoStatus
539
+ )
540
+
541
+ process
542
+ {
543
+ $repositoryInfoForDisplayMessage = if ($PSCmdlet.ParameterSetName -eq " Uri" ) { $Uri } else { $OwnerName , $RepositoryName -join " /" }
544
+ if ($PSCmdlet.ShouldProcess ($strRepositoryInfoForDisplayMessage , " Rename repository to '$NewName '" ))
545
+ {
546
+ Write-InvocationLog - Invocation $MyInvocation
547
+ $elements = Resolve-RepositoryElements - BoundParameters $PSBoundParameters
548
+ $OwnerName = $elements.ownerName
549
+ $RepositoryName = $elements.repositoryName
550
+
551
+ $telemetryProperties = @ {
552
+ ' OwnerName' = (Get-PiiSafeString - PlainText $OwnerName )
553
+ ' RepositoryName' = (Get-PiiSafeString - PlainText $RepositoryName )
554
+ }
555
+
556
+ $params = @ {
557
+ ' UriFragment' = " repos/$OwnerName /$RepositoryName "
558
+ ' Method' = ' Patch'
559
+ Body = ConvertTo-Json - InputObject @ {name = $NewName }
560
+ ' Description' = " Renaming repository at '$repositoryInfoForDisplayMessage ' to '$NewName '"
561
+ ' AccessToken' = $AccessToken
562
+ ' TelemetryEventName' = $MyInvocation.MyCommand.Name
563
+ ' TelemetryProperties' = $telemetryProperties
564
+ ' NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue - BoundParameters $PSBoundParameters - Name NoStatus - ConfigValueName DefaultNoStatus)
565
+ }
566
+
567
+ return Invoke-GHRestMethod @params
568
+ }
569
+ }
570
+ }
571
+
464
572
function Update-GitHubRepository
465
573
{
466
574
<#
0 commit comments