I have a gitea server set up with docker and a webserver that uses the gitea swagger API to push and update files on the gitea server. Now when I send an http request to upload a file into a repository via the API this works completely fine. The authorization token is inside the header and the content of the file is in the body of the request and the file gets pushed just fine.
However when I use the command to update the file I need to provide the SHA hash for the file as it is currently before being changed. I created a file for testing purposes (A simple .txt filled with a single sentence) and uploaded it. I then cloned the repo, used the unix command “sha1sum” to get to the SHA value of the file as it is before editing and then provided this SHA to update the file with a different content. However I get rejected with a 422 Unprocessable Entitiy response and I can not explain why that is. The formatting should be correct. Does the SHA hashmean something differently or is there another, proper way to generate the SHA hash?
This is how the http request is currently being put together. I am using the python library requests for this. Again for upload this works without a hitch.
Upload file:
// Header including authorization token
headers = {'Access-Control-Allow-Origin': 'GITEA SERVER URL', 'accept' : 'application/json', Authorization' : 'token TOKEN VALUE'}
// Body containing file contents encoded in base 64
data={"content": base64.b64encode(fileString)}
// Send Request to Upload the file
response=requests.post('GITEA SERVER URL/api/v1/repos/owner/repo/contents/filepath', data=data, headers=headers)
Update file:
// Header including authorization token
headers = {'Access-Control-Allow-Origin': 'GITEA SERVER URL', 'accept' : 'application/json', 'Authorization' : 'token TOKEN VALUE'}
// Body containing file contents encoded in base 64, as well as old SHA value
data={"content": base64.b64encode(fileString), "sha":"SHA VALUE"}
response=requests.put('GITEA SERVER URL/api/v1/repos/owner/repo/contents/filepath', data=data, headers=headers)
I would be very thankful for any help on this matter.