Recently I moved one site from Verel to Firebase, but a “This branch has no deployments” banner keep showing.

A simple Google search find this:

Github doc: https://docs.github.com/en/rest/deployments/deployments?apiVersion=2022-11-28

Seems we can only use API. but I first tried delete:

gh api /repos/$User/$Repo/deployments --jq=".[].id" `
| ForEach-Object {
  gh api --method DELETE -H "Accept: application/vnd.github+json" `
    -H "X-GitHub-Api-Version: 2022-11-28" `
    "/repos/$User/$Repo/deployments/$_"
}

but get error:

{
  "message": "Validation Failed",
  "errors": [
    "We cannot delete an active deployment unless it is the only deployment in a given environment."
  ],
  "documentation_url": "https://docs.github.com/rest/deployments/deployments#delete-a-deployment",
  "status": "422"
}
gh: Validation Failed (HTTP 422)

Then I tried to create a deployment and set it as active:

gh api -H "Accept: application/vnd.github+json" `
  -H "X-GitHub-Api-Version: 2022-11-28" `
  /repos/$User/$Repo/deployments

gh api --method POST -H "Accept: application/vnd.github+json" `
  -H "X-GitHub-Api-Version: 2022-11-28" `
  /repos/$User/$Repo/deployments `
  -f "ref=$Branch" -f "payload={'deploy': 'migrate'}" `
  -f "description=Deploy request from cli"

$Id = (gh api /repos/$User/$Repo/deployments --jq=".[].id").Split('\n')[0]

gh api --method POST -H "Accept: application/vnd.github+json" `
  -H "X-GitHub-Api-Version: 2022-11-28"`
  /repos/$User/$Repo/deployments/$Id/statuses `
  -f "environment=production" -f "state=success" `
  -f "log_url=https://example.com/deployment/42/output" `
  -f "description=Deployment finished successfully."

but I still get the same error.

Later I realized that it’s related to environments that didn’t show on private repo.

So the solution was simple: change the repo to public, and delete the environments (firebase are not using it), then the delete request succeeds. Later you can change it back to public.