如何通过Gitlab的API执行PUT操作?

时间:2019-09-10 20:20:30

标签: api curl gitlab crud readme

我想使用Gitlab的API构造curl命令,以便可以编辑README.md文件。我知道有可能根据文档:

https://docs.gitlab.com/ee/api/repository_files.html

我可以使用curl 'https://private.private.io/api/v4/56/projects?private_token=private-token'找到我的项目,但似乎无法更深入地了解以回购方式读取或编辑文件。

更新

解决方案是

curl --request PUT --header 'PRIVATE-TOKEN: private-token' --header "Content-Type: application/json" --data '{"branch": "master", "author_email": "email", "author_name": "name",
"content": "status, building", "commit_message": "update file"}' 'https://private.private.io/api/v4/projects/56/repository/files/README.md'

1 个答案:

答案 0 :(得分:0)

请考虑使用文档here中提到的此解决方案。这可让您更新单个文件

curl --request PUT --header 'PRIVATE-TOKEN: <your_access_token>' --header "Content-Type: application/json" \
  --data '{"branch": "master", "author_email": "author@example.com", "author_name": "Firstname Lastname", \
    "content": "some content", "commit_message": "update file"}' \
  'https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject%2Erb'