Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Test/public/setRepoPropertiesSuccess.test.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
function Test_SetRepoProperties_Success{

$owner = 'solidifydemo' ; $repo = 'bit21' ; $property = 'kk' ; $value = 'someValuekk'
$token = 'fakeToken'

$cmd = @'
curl -L -s -H "Authorization: Bearer $env:GH_TOKEN" -X PATCH https://api.github.com/repos/{owner}/{repo}/properties/values -d '{"properties":[{"property_name":"{name}","value":"{value}"}]}'
curl -L -s -H "Authorization: Bearer {token}" -X PATCH https://api.github.com/repos/{owner}/{repo}/properties/values -d '{"properties":[{"property_name":"{name}","value":"{value}"}]}'
'@
$cmd = $cmd -replace '{owner}',$owner
$cmd = $cmd -replace '{repo}',$repo
$cmd = $cmd -replace '{name}',$property
$cmd = $cmd -replace '{value}',$value
$cmd = $cmd -replace '{token}',$token

# If success return null
Set-InvokeCommandMock -Alias $cmd -Command "echo null"
Set-InvokeCommandMock -Alias getToken -Command "echo $token"

$result = Set-RepoProperty -owner $owner -repo $repo -name $property -value $value

Expand All @@ -21,18 +24,21 @@ curl -L -s -H "Authorization: Bearer $env:GH_TOKEN" -X PATCH https://api.github.
function Test_SetRepoProperties_NotFound{

$owner = 'solidifydemo' ; $repo = 'bit21' ; $property = 'kk' ; $value = 'someValuekk'
$token = 'fakeToken'

$cmd = @'
curl -L -s -H "Authorization: Bearer $env:GH_TOKEN" -X PATCH https://api.github.com/repos/{owner}/{repo}/properties/values -d '{"properties":[{"property_name":"{name}","value":"{value}"}]}'
curl -L -s -H "Authorization: Bearer {token}" -X PATCH https://api.github.com/repos/{owner}/{repo}/properties/values -d '{"properties":[{"property_name":"{name}","value":"{value}"}]}'
'@
$cmd = $cmd -replace '{owner}',$owner
$cmd = $cmd -replace '{repo}',$repo
$cmd = $cmd -replace '{name}',$property
$cmd = $cmd -replace '{value}',$value
$cmd = $cmd -replace '{token}',$token

# If success return null
$mockfile = $PSScriptRoot | Join-Path -ChildPath 'testData' -AdditionalChildPath 'setRepoPropertiesNotFound.json'
Set-InvokeCommandMock -Alias $cmd -Command "Get-Content -Path $(($mockfile | Get-Item).FullName)"
Set-InvokeCommandMock -Alias getToken -Command "echo $token"

$result = Set-RepoProperty -owner $owner -repo $repo -name $property -value $value @ErrorParameters

Expand Down
20 changes: 18 additions & 2 deletions public/setRepoProperties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# This command works
# curl -L -H "Authorization: Bearer $env:GH_TOKEN" -X PATCH https://api.github.com/repos/solidifydemo/bit21/properties/values -d '{"properties":[{"property_name":"kk","value":"kkvalue23"}]}'
$cmd = @'
curl -L -s -H "Authorization: Bearer $env:GH_TOKEN" -X PATCH https://api.github.com/repos/{owner}/{repo}/properties/values -d '{"properties":[{"property_name":"{name}","value":"{value}"}]}'
curl -L -s -H "Authorization: Bearer {token}" -X PATCH https://api.github.com/repos/{owner}/{repo}/properties/values -d '{"properties":[{"property_name":"{name}","value":"{value}"}]}'
'@

Set-MyInvokeCommandAlias -Alias SetRepoProperty -Command $cmd
Set-MyInvokeCommandAlias -Alias getToken -Command "Get-UserToken"

<#
.SYNOPSIS
Expand All @@ -34,7 +35,9 @@ function Set-RepoProperty{

"Setting property $Name to $Value for $Owner/$Repo" | Write-Verbose

$param = @{ owner = $Owner ; repo = $Repo ; name = $Name ; value = $Value }
$token = Invoke-MyCommand -Command getToken

$param = @{ owner = $Owner ; repo = $Repo ; name = $Name ; value = $Value ; token= $token}

if($PSCmdlet.ShouldProcess("$Owner/$Repo","Set property $Name to $Value")){
$result = Invoke-MyCommandJson -Command SetRepoProperty -Parameters $param
Expand All @@ -47,3 +50,16 @@ function Set-RepoProperty{
return $null
} Export-ModuleMember -Function Set-RepoProperty

<#
.SYNOPSIS
Gets the user token from the environment
#>
function Get-UserToken{
$token = $env:GH_TOKEN
if($null -eq $token){
"GH_TOKEN environment variable is not set" | Write-Error
return $null
}
return $token
} Export-ModuleMember -Function Get-UserToken

Loading