I am trying to upload file to GitHub via GITHub API (http://developer.github.com/v3/repos/contents/). Somehow I am not able to upload file. When I tried to upload existing file it gave me message "{\"message\":\"refs/heads/master expected to be at ee1cd720841a4b5b06a8339c333c56b1748e66f9\",\"documentation_url\":\"http://developer.github.com/v3/repos/contents/\"}". When I went to github and tried to delete file using website it gave me below error. I can do workaround with reset head to previous version and move on. But I am trying to understand what caused this behavior and how can I prevent same in future. Neither Google nor Github Help was able to answer me so looking for something from community. Thanks for looking into it.
For uploading the file into GitHub you can go through basic steps: Get the file content using 'fs' module. Encode the content into base64 format. then use GitHub API “https://api.github.com/repos/{owner}/{repo}/contents/{file name}”.
The rules are the same as those applied to the set metadata values REST API. Use Content-Type: application/json to describe this information as a JSON object. File to upload. This must come after the jsonInputParameters parameter.
As Ivan suggested, if we try to create/update files using quick succession using API it causes mentioned behavior. Till issue is fixed we can workaround this by making thread sleep between two request. I hope it will help someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With