From d1bd976d70cc975dfd247f9ad2bace58a465c7da Mon Sep 17 00:00:00 2001 From: Simon Heather <32168619+X-Guardian@users.noreply.github.com> Date: Tue, 2 Jun 2020 21:02:18 +0100 Subject: [PATCH] Set-GitHubRepositoryTopic: Fix Exception When Clear 'Parameter' is Specified (#216) This fixes the exception in the `Set-GithubRepositoryTopic` function when the `Clear` parameter is specified. #### References https://developer.github.com/v3/repos/#replace-all-repository-topics - Send an empty array ([]) to clear all topics from the repository. The problem with the existing implementation was that it was creating an array of 1 element, where the element was `$null`. Fixes #215 --- GitHubRepositories.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 29228af7..842c75ea 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1033,12 +1033,18 @@ function Set-GitHubRepositoryTopic 'Clear' = $PSBoundParameters.ContainsKey('Clear') } - $description = "Replacing topics in $RepositoryName" - if ($Clear) { $description = "Clearing topics in $RepositoryName" } + if ($Clear) + { + $description = "Clearing topics in $RepositoryName" + $Name = @() + } + else + { + $description = "Replacing topics in $RepositoryName" + } - $names = @($Name) $hashBody = @{ - 'names' = $names + 'names' = $Name } $params = @{