Skip to content

🪲 [Fix]: Connect-GitHubApp no longer fails when only one installation exists#568

Draft
Marius Storhaug (MariusStorhaug) wants to merge 2 commits intomainfrom
fix/567-connect-githubapp-single-installation
Draft

🪲 [Fix]: Connect-GitHubApp no longer fails when only one installation exists#568
Marius Storhaug (MariusStorhaug) wants to merge 2 commits intomainfrom
fix/567-connect-githubapp-single-installation

Conversation

@MariusStorhaug
Copy link
Copy Markdown
Member

@MariusStorhaug Marius Storhaug (MariusStorhaug) commented Mar 29, 2026

Connect-GitHubApp now correctly connects to all available installations regardless of whether one or many exist. Previously, calling Connect-GitHubApp when the GitHub App had exactly one installation caused an AddRange failure, because PowerShell returned a single object instead of an array.

Fixed: Connecting with a single app installation

Connect-GitHubApp (with no filter parameters) no longer throws when your GitHub App has only one installation. The command now handles one, many, or zero installations identically.

This resolves the error:

Cannot convert argument "c", with value: "GitHubAppInstallation", for "AddRange" to type
"System.Collections.ICollection": "Cannot convert the "GitHubAppInstallation" value of type
"GitHubAppInstallation" to type "System.Collections.ICollection"."

Automation workflows (e.g., Distributor sync) that call Connect-GitHubApp without parameters will no longer fail on single-installation apps.

Technical Details

  • File: src/functions/public/Auth/Connect-GitHubApp.ps1
  • Root cause: ArrayList.AddRange() requires an ICollection. When Get-GitHubAppInstallation returns a single object, PowerShell does not wrap it in an array — the bare object doesn't implement ICollection, causing the call to throw.
  • Fix: Wrapped the call with the array sub-expression operator @() to guarantee an array is always passed: $selectedInstallations.AddRange(@(Get-GitHubAppInstallation -Context $Context))
  • This is a standard PowerShell idiom for preventing pipeline unrolling issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Fix Connect-GitHubApp AddRange failure when a single installation exists

1 participant