|
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +function Get-GitHubRepositoryFork |
| 5 | +{ |
| 6 | +<# |
| 7 | + .SYNOPSIS |
| 8 | + Gets the list of forks of the specified repository on GitHub. |
| 9 | +
|
| 10 | + .DESCRIPTION |
| 11 | + Gets the list of forks of the specified repository on GitHub. |
| 12 | +
|
| 13 | + The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub |
| 14 | +
|
| 15 | + .PARAMETER OwnerName |
| 16 | + Owner of the repository. |
| 17 | + If not supplied here, the DefaultOwnerName configuration property value will be used. |
| 18 | +
|
| 19 | + .PARAMETER RepositoryName |
| 20 | + Name of the repository. |
| 21 | + If not supplied here, the DefaultRepositoryName configuration property value will be used. |
| 22 | +
|
| 23 | + .PARAMETER Uri |
| 24 | + Uri for the repository. |
| 25 | + The OwnerName and RepositoryName will be extracted from here instead of needing to provide |
| 26 | + them individually. |
| 27 | +
|
| 28 | + .PARAMETER Sort |
| 29 | + The sort order for results. |
| 30 | +
|
| 31 | + .PARAMETER AccessToken |
| 32 | + If provided, this will be used as the AccessToken for authentication with the |
| 33 | + REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. |
| 34 | +
|
| 35 | + .PARAMETER NoStatus |
| 36 | + If this switch is specified, long-running commands will run on the main thread |
| 37 | + with no commandline status update. When not specified, those commands run in |
| 38 | + the background, enabling the command prompt to provide status information. |
| 39 | + If not supplied here, the DefaultNoStatus configuration property value will be used. |
| 40 | +
|
| 41 | + .EXAMPLE |
| 42 | + Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub |
| 43 | +
|
| 44 | + Gets all of the forks for the PowerShell\PowerShellForGitHub repository. |
| 45 | +#> |
| 46 | + [CmdletBinding( |
| 47 | + SupportsShouldProcess, |
| 48 | + DefaultParametersetName='Elements')] |
| 49 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] |
| 50 | + param( |
| 51 | + [Parameter(ParameterSetName='Elements')] |
| 52 | + [string] $OwnerName, |
| 53 | + |
| 54 | + [Parameter(ParameterSetName='Elements')] |
| 55 | + [string] $RepositoryName, |
| 56 | + |
| 57 | + [Parameter( |
| 58 | + Mandatory, |
| 59 | + ParameterSetName='Uri')] |
| 60 | + [string] $Uri, |
| 61 | + |
| 62 | + [ValidateSet('newest', 'oldest', 'stargazers')] |
| 63 | + [string] $Sort = 'newest', |
| 64 | + |
| 65 | + [string] $AccessToken, |
| 66 | + |
| 67 | + [switch] $NoStatus |
| 68 | + ) |
| 69 | + |
| 70 | + Write-InvocationLog -Invocation $MyInvocation |
| 71 | + |
| 72 | + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters -DisableValidation |
| 73 | + $OwnerName = $elements.ownerName |
| 74 | + $RepositoryName = $elements.repositoryName |
| 75 | + |
| 76 | + $telemetryProperties = @{ |
| 77 | + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) |
| 78 | + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) |
| 79 | + 'Sort' = $Sort |
| 80 | + } |
| 81 | + |
| 82 | + $getParams = @( |
| 83 | + "sort=$Sort" |
| 84 | + ) |
| 85 | + |
| 86 | + $params = @{ |
| 87 | + 'UriFragment' = "repos/$OwnerName/$RepositoryName/forks" |
| 88 | + 'Description' = "Getting all forks of $RepositoryName" |
| 89 | + 'AccessToken' = $AccessToken |
| 90 | + 'TelemetryEventName' = $MyInvocation.MyCommand.Name |
| 91 | + 'TelemetryProperties' = $telemetryProperties |
| 92 | + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) |
| 93 | + } |
| 94 | + |
| 95 | + return Invoke-GHRestMethodMultipleResult @params |
| 96 | +} |
| 97 | + |
| 98 | +function New-GitHubRepositoryFork |
| 99 | +{ |
| 100 | +<# |
| 101 | + .SYNOPSIS |
| 102 | + Creates a new fork of a repository on GitHub. |
| 103 | +
|
| 104 | + .DESCRIPTION |
| 105 | + Creates a new fork of a repository on GitHub. |
| 106 | +
|
| 107 | + The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub |
| 108 | +
|
| 109 | + .PARAMETER OwnerName |
| 110 | + Owner of the repository. |
| 111 | + If not supplied here, the DefaultOwnerName configuration property value will be used. |
| 112 | +
|
| 113 | + .PARAMETER RepositoryName |
| 114 | + Name of the repository. |
| 115 | + If not supplied here, the DefaultRepositoryName configuration property value will be used. |
| 116 | +
|
| 117 | + .PARAMETER Uri |
| 118 | + Uri for the repository. |
| 119 | + The OwnerName and RepositoryName will be extracted from here instead of needing to provide |
| 120 | + them individually. |
| 121 | +
|
| 122 | + .PARAMETER OrganizationName |
| 123 | + Name of the organization that the new repository should be created under. |
| 124 | + If not specified, will be created under the current authenticated user's account. |
| 125 | +
|
| 126 | + .PARAMETER AccessToken |
| 127 | + If provided, this will be used as the AccessToken for authentication with the |
| 128 | + REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. |
| 129 | +
|
| 130 | + .PARAMETER NoStatus |
| 131 | + If this switch is specified, long-running commands will run on the main thread |
| 132 | + with no commandline status update. When not specified, those commands run in |
| 133 | + the background, enabling the command prompt to provide status information. |
| 134 | + If not supplied here, the DefaultNoStatus configuration property value will be used. |
| 135 | +
|
| 136 | + .EXAMPLE |
| 137 | + New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub |
| 138 | +
|
| 139 | + Creates a fork of this repository under the current authenticated user's account. |
| 140 | +
|
| 141 | + .EXAMPLE |
| 142 | + New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -OrganizationName OctoLabs |
| 143 | +
|
| 144 | + Creates a fork of this repository under the OctoLabs organization. |
| 145 | +#> |
| 146 | + [CmdletBinding( |
| 147 | + SupportsShouldProcess, |
| 148 | + DefaultParametersetName='Elements')] |
| 149 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] |
| 150 | + param( |
| 151 | + [Parameter(ParameterSetName='Elements')] |
| 152 | + [string] $OwnerName, |
| 153 | + |
| 154 | + [Parameter(ParameterSetName='Elements')] |
| 155 | + [string] $RepositoryName, |
| 156 | + |
| 157 | + [Parameter( |
| 158 | + Mandatory, |
| 159 | + ParameterSetName='Uri')] |
| 160 | + [string] $Uri, |
| 161 | + |
| 162 | + [string] $OrganizationName, |
| 163 | + |
| 164 | + [string] $AccessToken, |
| 165 | + |
| 166 | + [switch] $NoStatus |
| 167 | + ) |
| 168 | + |
| 169 | + Write-InvocationLog -Invocation $MyInvocation |
| 170 | + |
| 171 | + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters -DisableValidation |
| 172 | + $OwnerName = $elements.ownerName |
| 173 | + $RepositoryName = $elements.repositoryName |
| 174 | + |
| 175 | + $telemetryProperties = @{ |
| 176 | + 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) |
| 177 | + 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) |
| 178 | + } |
| 179 | + |
| 180 | + $getParams = @() |
| 181 | + if ($PSBoundParameters.ContainsKey('OrganizationName') -and |
| 182 | + (-not [String]::IsNullOrEmpty($OrganizationName))) |
| 183 | + { |
| 184 | + $telemetryProperties['OrganizationName'] = Get-PiiSafeString -PlainText $OrganizationName |
| 185 | + $getParams += "organization=$OrganizationName" |
| 186 | + } |
| 187 | + |
| 188 | + $params = @{ |
| 189 | + 'UriFragment' = "repos/$OwnerName/$RepositoryName/forks`?" + ($getParams -join '&') |
| 190 | + 'Method' = 'Post' |
| 191 | + 'Description' = "Creating fork of $RepositoryName" |
| 192 | + 'AccessToken' = $AccessToken |
| 193 | + 'TelemetryEventName' = $MyInvocation.MyCommand.Name |
| 194 | + 'TelemetryProperties' = $telemetryProperties |
| 195 | + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) |
| 196 | + } |
| 197 | + |
| 198 | + $result = Invoke-GHRestMethod @params |
| 199 | + |
| 200 | + Write-Log -Message 'Forking a repository happens asynchronously. You may have to wait a short period of time (up to 5 minutes) before you can access the git objects.' -Level Warning |
| 201 | + return $result |
| 202 | +} |
0 commit comments