When using CommitAndPushFiles to update a single file that already exists in a GitHub repository, the operation fails with:
PUT https://api.github.com/repos/{owner}/{repo}/contents/{path}: 422 Invalid request.
"sha" wasn't supplied. []
Root Cause
PR #163 introduced an optimization where single-file commits use the GitHub Contents API, while multi-file commits use the Git Data API (blobs/trees/commits).
The Contents API requires the sha parameter when updating an existing file. Currently, CommitAndPushFiles doesn't fetch the existing file's SHA before calling the Contents API, causing the error.
Steps to Reproduce
- Create a repository with an existing file (e.g.,
config.yml)
- Call
CommitAndPushFiles with a single FileToCommit targeting that existing file
- Observe the 422 error
Expected Behavior
CommitAndPushFiles should successfully update the existing file by:
- Fetching the current file's SHA using
GetContents
- Including the SHA in the Contents API request
Workaround
Passing 2+ files triggers the Git Data API path, which doesn't require SHA and works correctly for updates.
Environment
- froggit-go version: v1.21.1
- VCS Provider: GitHub
When using
CommitAndPushFilesto update a single file that already exists in a GitHub repository, the operation fails with:Root Cause
PR #163 introduced an optimization where single-file commits use the GitHub Contents API, while multi-file commits use the Git Data API (blobs/trees/commits).
The Contents API requires the
shaparameter when updating an existing file. Currently,CommitAndPushFilesdoesn't fetch the existing file's SHA before calling the Contents API, causing the error.Steps to Reproduce
config.yml)CommitAndPushFileswith a singleFileToCommittargeting that existing fileExpected Behavior
CommitAndPushFilesshould successfully update the existing file by:GetContentsWorkaround
Passing 2+ files triggers the Git Data API path, which doesn't require SHA and works correctly for updates.
Environment