问题
I want to update file content and commit it. To be able to achieve it, I looked the api of gitlab from the url; http://mygitlabadress/help/api/README.md
It says Updating existing file is done as; http://mygitlabadress/help/api/repository_files.md#update-existing-file-in-repository
I follow the instructions and write; http://mygitlabadress/api/v4/projects/:id/repository/files/file1%2Ffile2%2Ftest?ref=master&author_name=name%20surname&content=some%20other%20content&commit_message=update%20file&private_token=:PRIVATE_TOKEN
This returns as; {"file_name":"test","file_path":"file1/file2/test","size":5,"encoding":"base64","content":"ZmRhcwo=","ref":"master","blob_id":"e1afa79f4...","commit_id":"5d61796...","last_commit_id":"5d617962a23c07345e68..."}
But when I check commits on master branch. The commit is not done. I don't understand why this is happening. The above request doesn't return an error. On the contrary, it returns as commit is done.
What am I missing? How can I update the file and commit it??
回答1:
It looks like you are making a GET request instead of a PUT.
Are you using curl ? You should use the example curl
request given in the doc :
curl --request PUT --header 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' 'https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject%2Erb?branch=master&author_email=author%40example.com&author_name=Firstname%20Lastname&content=some%20other%20content&commit_message=update%20file'
来源:https://stackoverflow.com/questions/45837806/updating-and-committing-file-by-using-gitlab-api