Skip to content

[Contribution Process Bug]: CleanUpStalePRChecks action fails when exactly one open PR exists #9867

Description

@pamura1977

Describe the issue

The CleanUpStalePRChecks composite action (.github/actions/CleanUpStalePRChecks/action.ps1) fails whenever a repository has exactly one open pull request.

The script runs:

$prs = gh pr list --state open --json number,title,url,mergeable --limit 1000 | ConvertFrom-Json
...
Write-Host "Found $($prs.Count) open pull requests"

When gh pr list returns a single result, ConvertFrom-Json returns a single PSCustomObject instead of an array. A PSCustomObject has no Count property. Because the script runs under Set-StrictMode -Version 2.0, accessing $prs.Count in this case throws a terminating error instead of silently returning $null or 1:

action.ps1: /home/runner/work/_temp/<guid>.ps1:2
Line |
   2 |  /home/runner/work/BCApps/BCApps/./.github/actions/CleanUpStalePRChecks …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The property 'Count' cannot be found on this object. Verify that the
     | property exists.
Error: Process completed with exit code 1.

This causes the scheduled workflow run to fail every day for as long as the repository has exactly one open PR, and generates a daily failure notification email to the repository owner.

Expected behavior

The action should correctly handle the case where gh pr list returns a single pull request (as well as zero or multiple), count it as 1 open PR, and continue processing normally without throwing a StrictMode error.

Steps to reproduce

  1. In a repository where this action is installed, ensure there is exactly one open pull request.
  2. Trigger the Clean Up Stale PR Status Checks workflow (scheduled run, or manually via workflow_dispatch).
  3. Observe that the job fails in the "Clean Up Stale PR Checks" step with the error The property 'Count' cannot be found on this object.

Additional context

Root cause: ConvertFrom-Json in PowerShell does not return an array when the JSON input contains a single object, so .Count is undefined on the resulting PSCustomObject. Under Set-StrictMode -Version 2.0, this is a hard error rather than a silent $null.

Suggested fix — wrap the result in @(...) to force it into an array regardless of element count:

$prs = @(gh pr list --state open --json number,title,url,mergeable --limit 1000 | ConvertFrom-Json)

Observed on: fork pamura1977/BCApps, workflow file .github/workflows/CleanUpStalePRChecks.yaml, action .github/actions/CleanUpStalePRChecks/action.ps1 (owned per CODEOWNERS by @microsoft/d365-bc-engineering-systems).

Example failed run: pamura1977/BCApps Actions run #7 (job "Clean Up Stale PR Status Checks"), failed in 29s with 1 annotation.
Log: https://github.com/pamura1977/BCApps/actions/runs/30600290979/job/91061250206#logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Contribution-BugSomething isn't working in the contribution processFinanceGitHub request for Finance area

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions