@@ -317,7 +317,12 @@ function Get-GitHubRepository
317
317
. PARAMETER GetAllPublicRepositories
318
318
If this is specified with no other parameter, then instead of returning back all
319
319
repositories for the current authenticated user, it will instead return back all
320
- public repositories on GitHub.
320
+ public repositories on GitHub in the order in which they were created.
321
+
322
+ . PARAMETER Since
323
+ The ID of the last public repository that you have seen. If specified with
324
+ -GetAllPublicRepositories, will only return back public repositories created _after_ this
325
+ one.
321
326
322
327
. PARAMETER AccessToken
323
328
If provided, this will be used as the AccessToken for authentication with the
@@ -340,24 +345,30 @@ function Get-GitHubRepository
340
345
Gets all public repositories on GitHub.
341
346
342
347
. EXAMPLE
343
- Get-GitHubRepository -OctoCat OctoCat
348
+ Get-GitHubRepository -OwnerName octocat
349
+
350
+ Gets all of the repositories for the user octocat
344
351
345
352
. EXAMPLE
346
- Get-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub
353
+ Get-GitHubRepository -Uri https://github.com/microsoft/PowerShellForGitHub
354
+
355
+ Gets information about the microsoft/PowerShellForGitHub repository.
347
356
348
357
. EXAMPLE
349
358
Get-GitHubRepository -OrganizationName PowerShell
350
359
360
+ Gets all of the repositories in the PowerShell organization.
351
361
#>
352
362
[CmdletBinding (
353
363
SupportsShouldProcess ,
354
- DefaultParameterSetName = ' Elements ' )]
364
+ DefaultParameterSetName = ' AuthenticatedUser ' )]
355
365
[Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSShouldProcess" , " " , Justification= " Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently." )]
366
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSReviewUnusedParameter" , " " , Justification= " One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1." )]
356
367
param (
357
- [Parameter (ParameterSetName = ' Elements ' )]
368
+ [Parameter (ParameterSetName = ' ElementsOrUser ' )]
358
369
[string ] $OwnerName ,
359
370
360
- [Parameter (ParameterSetName = ' Elements ' )]
371
+ [Parameter (ParameterSetName = ' ElementsOrUser ' )]
361
372
[string ] $RepositoryName ,
362
373
363
374
[Parameter (
@@ -369,21 +380,36 @@ function Get-GitHubRepository
369
380
[string ] $OrganizationName ,
370
381
371
382
[ValidateSet (' All' , ' Public' , ' Private' )]
383
+ [Parameter (ParameterSetName = ' AuthenticatedUser' )]
372
384
[string ] $Visibility ,
373
385
386
+ [Parameter (ParameterSetName = ' AuthenticatedUser' )]
374
387
[string []] $Affiliation ,
375
388
389
+ [Parameter (ParameterSetName = ' AuthenticatedUser' )]
390
+ [Parameter (ParameterSetName = ' ElementsOrUser' )]
391
+ [Parameter (ParameterSetName = ' Organization' )]
376
392
[ValidateSet (' All' , ' Owner' , ' Public' , ' Private' , ' Member' , ' Forks' , ' Sources' )]
377
393
[string ] $Type ,
378
394
395
+ [Parameter (ParameterSetName = ' AuthenticatedUser' )]
396
+ [Parameter (ParameterSetName = ' ElementsOrUser' )]
397
+ [Parameter (ParameterSetName = ' Organization' )]
379
398
[ValidateSet (' Created' , ' Updated' , ' Pushed' , ' FullName' )]
380
399
[string ] $Sort ,
381
400
401
+ [Parameter (ParameterSetName = ' AuthenticatedUser' )]
402
+ [Parameter (ParameterSetName = ' ElementsOrUser' )]
403
+ [Parameter (ParameterSetName = ' Organization' )]
382
404
[ValidateSet (' Ascending' , ' Descending' )]
383
405
[string ] $Direction ,
384
406
407
+ [Parameter (ParameterSetName = ' PublicRepos' )]
385
408
[switch ] $GetAllPublicRepositories ,
386
409
410
+ [Parameter (ParameterSetName = ' PublicRepos' )]
411
+ [int64 ] $Since ,
412
+
387
413
[string ] $AccessToken ,
388
414
389
415
[switch ] $NoStatus
@@ -395,36 +421,115 @@ function Get-GitHubRepository
395
421
$OwnerName = $elements.ownerName
396
422
$RepositoryName = $elements.repositoryName
397
423
398
- $telemetryProperties = @ {}
424
+ $telemetryProperties = @ {
425
+ ' UsageType' = $PSCmdlet.ParameterSetName
426
+ }
399
427
400
428
$uriFragment = [String ]::Empty
401
429
$description = [String ]::Empty
402
- if (( -not [ String ]::IsNullOrEmpty( $OwnerName )) -and ( -not [ String ]::IsNullOrEmpty( $RepositoryName )) )
430
+ switch ( $PSCmdlet .ParameterSetName )
403
431
{
404
- $telemetryProperties [' OwnerName' ] = Get-PiiSafeString - PlainText $OwnerName
405
- $telemetryProperties [' RepositoryName' ] = Get-PiiSafeString - PlainText $RepositoryName
432
+ { (' ElementsOrUser' , ' Uri' ) -contains $_ } {
433
+ # This is a little tricky. Ideally we'd have two separate ParameterSets (Elements, User),
434
+ # however PowerShell would be unable to disambiguate between the two, so unfortunately
435
+ # we need to do some additional work here. And because fallthru doesn't appear to be
436
+ # working right, we're combining both of those, along with Uri.
437
+
438
+ if ([String ]::IsNullOrWhiteSpace($OwnerName ))
439
+ {
440
+ $message = ' OwnerName could not be determined.'
441
+ Write-Log - Message $message - Level Error
442
+ throw $message
443
+ }
444
+ elseif ([String ]::IsNullOrWhiteSpace($RepositoryName ))
445
+ {
446
+ if ($PSCmdlet.ParameterSetName -eq ' ElementsOrUser' )
447
+ {
448
+ $telemetryProperties [' UsageType' ] = ' User'
449
+ $telemetryProperties [' OwnerName' ] = Get-PiiSafeString - PlainText $OwnerName
450
+
451
+ $uriFragment = " users/$OwnerName /repos"
452
+ $description = " Getting repos for $OwnerName "
453
+ }
454
+ else
455
+ {
456
+ $message = ' RepositoryName could not be determined.'
457
+ Write-Log - Message $message - Level Error
458
+ throw $message
459
+ }
460
+ }
461
+ else
462
+ {
463
+ if ($PSCmdlet.ParameterSetName -eq ' ElementsOrUser' )
464
+ {
465
+ $telemetryProperties [' UsageType' ] = ' Elements'
466
+
467
+ if ($PSBoundParameters.ContainsKey (' Type' ) -or
468
+ $PSBoundParameters.ContainsKey (' Sort' ) -or
469
+ $PSBoundParameters.ContainsKey (' Direction' ))
470
+ {
471
+ $message = ' Unable to specify -Type, -Sort and/or -Direction when retrieving a specific repository.'
472
+ Write-Log - Message $message - Level Error
473
+ throw $message
474
+ }
475
+ }
476
+
477
+ $telemetryProperties [' OwnerName' ] = Get-PiiSafeString - PlainText $OwnerName
478
+ $telemetryProperties [' RepositoryName' ] = Get-PiiSafeString - PlainText $RepositoryName
479
+
480
+ $uriFragment = " repos/$OwnerName /$RepositoryName "
481
+ $description = " Getting $OwnerName /$RepositoryName "
482
+ }
406
483
407
- $uriFragment = " repos/$OwnerName /$RepositoryName "
408
- $description = " Getting repo $RepositoryName "
409
- }
410
- elseif ([String ]::IsNullOrEmpty($OwnerName ) -and [String ]::IsNullOrEmpty($OrganizationName ))
411
- {
412
- $uriFragment = ' user/repos'
413
- $description = ' Getting repos for current authenticated user'
414
- }
415
- elseif ([String ]::IsNullOrEmpty($OwnerName ))
416
- {
417
- $telemetryProperties [' OrganizationName' ] = Get-PiiSafeString - PlainText $OrganizationName
484
+ break
485
+ }
418
486
419
- $uriFragment = " orgs/$OrganizationName /repos"
420
- $description = " Getting repos for $OrganizationName "
421
- }
422
- else
423
- {
424
- $telemetryProperties [' OwnerName' ] = Get-PiiSafeString - PlainText $OwnerName
487
+ ' Organization' {
488
+
489
+ $telemetryProperties [' OrganizationName' ] = Get-PiiSafeString - PlainText $OrganizationName
490
+
491
+ $uriFragment = " orgs/$OrganizationName /repos"
492
+ $description = " Getting repos for $OrganizationName "
493
+
494
+ break
495
+ }
496
+
497
+ ' User' {
498
+ $telemetryProperties [' OwnerName' ] = Get-PiiSafeString - PlainText $OwnerName
499
+
500
+ $uriFragment = " users/$OwnerName /repos"
501
+ $description = " Getting repos for $OwnerName "
502
+
503
+ break
504
+ }
505
+
506
+ ' AuthenticatedUser' {
507
+ if ($PSBoundParameters.ContainsKey (' Type' ) -and
508
+ ($PSBoundParameters.ContainsKey (' Visibility' ) -or
509
+ $PSBoundParameters.ContainsKey (' Affiliation' )))
510
+ {
511
+ $message = ' Unable to specify -Type when using -Visibility and/or -Affiliation.'
512
+ Write-Log - Message $message - Level Error
513
+ throw $message
514
+ }
515
+
516
+ $uriFragment = ' user/repos'
517
+ $description = ' Getting repos for current authenticated user'
518
+
519
+ break
520
+ }
521
+
522
+ ' PublicRepos' {
523
+ $uriFragment = ' repositories'
524
+ $description = " Getting all public repositories"
425
525
426
- $uriFragment = " users/$OwnerName /repos"
427
- $description = " Getting repos for $OwnerName "
526
+ if ($PSBoundParameters.ContainsKey (' Since' ))
527
+ {
528
+ $description += " since $Since "
529
+ }
530
+
531
+ break
532
+ }
428
533
}
429
534
430
535
$sortConverter = @ {
@@ -448,10 +553,12 @@ function Get-GitHubRepository
448
553
{
449
554
$getParams += " affiliation=$ ( $Affiliation -join ' ,' ) "
450
555
}
556
+ if ($PSBoundParameters.ContainsKey (' Since' )) { $getParams += " since=$Since " }
451
557
452
558
$params = @ {
453
559
' UriFragment' = $uriFragment + ' ?' + ($getParams -join ' &' )
454
560
' Description' = $description
561
+ ' AcceptHeader' = " $script :nebulaAcceptHeader ,$script :baptisteAcceptHeader ,$script :mercyAcceptHeader "
455
562
' AccessToken' = $AccessToken
456
563
' TelemetryEventName' = $MyInvocation.MyCommand.Name
457
564
' TelemetryProperties' = $telemetryProperties
@@ -810,7 +917,7 @@ function Get-GitHubRepositoryTopic
810
917
' UriFragment' = " repos/$OwnerName /$RepositoryName /topics"
811
918
' Method' = ' Get'
812
919
' Description' = " Getting topics for $RepositoryName "
813
- ' AcceptHeader' = ' application/vnd.github.mercy-preview+json '
920
+ ' AcceptHeader' = $ script :mercyAcceptHeader
814
921
' AccessToken' = $AccessToken
815
922
' TelemetryEventName' = $MyInvocation.MyCommand.Name
816
923
' TelemetryProperties' = $telemetryProperties
@@ -933,7 +1040,7 @@ function Set-GitHubRepositoryTopic
933
1040
' Body' = (ConvertTo-Json - InputObject $hashBody )
934
1041
' Method' = ' Put'
935
1042
' Description' = $description
936
- ' AcceptHeader' = ' application/vnd.github.mercy-preview+json '
1043
+ ' AcceptHeader' = $ script :mercyAcceptHeader
937
1044
' AccessToken' = $AccessToken
938
1045
' TelemetryEventName' = $MyInvocation.MyCommand.Name
939
1046
' TelemetryProperties' = $telemetryProperties
0 commit comments