"Invalid tree info" (422) error when using --push in CD/CI - VMware Tanzu Spring Application Advisor
search cancel

"Invalid tree info" (422) error when using --push in CD/CI - VMware Tanzu Spring Application Advisor

book

Article ID: 454063

calendar_today

Updated On:

Products

VMware Tanzu Spring Essentials

Issue/Introduction

When running the advisor upgrade-plan apply --push command in an automated CI/CD pipeline to generate step-by-step pull requests, the pipeline consistently fails with the following error in the logs:

Could not create Pull Request for [Repository name: <repo> - Current Branch: main - New Branch: main-upgrade-plan]:
{"message":"Invalid tree info","documentation_url":"https://docs.github.com/rest/git/trees#create-a-tree","status":"422"}

Environment

Spring App Advisor 1.6.x

Cause

This is suspected to be caused by a limitation in how the underlying Java GitHub API client (kohsuke/github-api) constructs the Git tree payload for certain changes (e.g. file deletions), which can result in an invalid tree reference being sent to GitHub's Create Tree API. 

Resolution

This issue will be fixed in Spring Application Advisor 2.0.

Workaround

While the fixed version is released or if you can't immediately upgrade, the workaround consist on decoupling the local code changes from the Git/PR operations: let Application Advisor only modify files on disk, and handle branch creation, commit, push, and pull request creation yourself using native git and the GitHub CLI (gh). This avoids the GitHub API's tree-creation endpoint entirely for the commit step, so it isn't affected by this issue.

You must write a script (or workflow step) that does the following:

  1. Run advisor upgrade-plan apply without the --push flag. This applies the current upgrade step's changes to your local working copy only.
  2. Create the branch only if it doesn't already exist and there are changes to commit. Check whether the target branch is already present (locally and/or on the remote) before creating it. .
  3. Stage and commit the changes with native git (git add the working tree, then git commit)
  4. Push the branch to the remote with git push.
  5. Create the pull request with gh pr create, targeting your base branch. Authenticate gh with the same token you were already using for Advisor's --push flow.