使用gitlab api更新和提交文件

问题描述:

我想更新文件内容并提交它。为了能够实现它,我从url中查找了gitlab的api; http://mygitlabadress/help/api/README.md使用gitlab api更新和提交文件

它说更新现有文件完成为; http://mygitlabadress/help/api/repository_files.md#update-existing-file-in-repository

我按照说明书写; 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

返回为; “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 ...“}

但是,当我检查提交master分支。提交没有完成。我不明白为什么会发生这种情况。上述请求不会返回错误。相反,它会在提交完成后返回。

我错过了什么?我如何更新文件并提交?

它看起来像你正在做一个GET请求,而不是一个PUT。

你使用卷曲吗?您应该使用在文档中给出的示例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'