Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create empty file #2427

Closed
Ashvin-Ranjan opened this issue Aug 1, 2022 · 4 comments · Fixed by #2430
Closed

Unable to create empty file #2427

Ashvin-Ranjan opened this issue Aug 1, 2022 · 4 comments · Fixed by #2430
Assignees

Comments

@Ashvin-Ranjan
Copy link
Contributor

Ashvin-Ranjan commented Aug 1, 2022

When attempting to commit an empty file to a repository using ghClient.Repositories.CreateFile and passing in []byte{} under the Content field of a github.RepositoryContentFileOptions the GitHub API will return a 422 error stating that content was not supplied. This is most likely due to the line:

Content []byte `json:"content,omitempty"` // unencoded

Which adds omitempty to the Content field of github.RepositoryContentFileOptions, even though it is a necessary field of the request.

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 1, 2022

Have you tried calculating the SHA of an empty byte slice?

$ touch bogus
$ shasum bogus
da39a3ee5e6b4b0d3255bfef95601890afd80709  bogus
$ ls -la bogus
-rw-rw-r-- 1 glenn glenn 0 Aug  1 19:06 bogus

Try passing in this SHA when your file is empty and see if that works.

@Ashvin-Ranjan
Copy link
Contributor Author

That does not work, I continue to get a 422 from the GitHub API because the "content" field was not supplied, here is the error message I get:

PUT https://api.github.com/repos/OWNER/REPO/contents/FILE: 422 Invalid request.

"content" wasn't supplied.

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 2, 2022

OK, gotcha. Then I think we have a bug that needs to be fixed. My main concern is that we don't break existing behavior where content should not be passed.

Do you want to submit a PR or would you like me to open this up to other contributors to this repo to address?

@Ashvin-Ranjan
Copy link
Contributor Author

I do not think there should be any problems with breaking existing behavior with this because looking at the update file contents endpoint it does appear that they label the content field required, unless I am mistaken. Also I can submit a PR for this. Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants