提交未在使用 gitlab api 的合并请求中提交

时间:2021-03-12 10:47:11

标签: git gitlab-api

从 GITLAB API 文档中,我想在单个分支上创建多个提交,然后在 bash 脚本中创建一个合并请求。

   curl -i --request POST --header "PRIVATE-TOKEN: privatekey" --header "Content-Type: application/json" --data "$PAYLOAD" "https://hostgit/api/v4/projects/1234/repository/commits"

关于有效载荷

    PAYLOAD=$(cat << JSON 
{
  "branch": "mybranch",
  "commit_message": "some commit message",
  "actions": [
    {
      "action": "update",
      "file_path": "roles/test.j2"
    },
     {
          "action": "update",
      "file_path": "roles/prod.j2"
      }
  ]
}
JSON
)

脚本更新文件,所以在这次提交之后我使用创建 MR 但它是一个空的 MR。为什么它是空的??提交更改为 0。 我也习惯于在操作中包含文件路径,但它不起作用并且提交仍然是空的。

1 个答案:

答案 0 :(得分:1)

对于 update 操作,您必须指定文件的内容,它应该是整个文件内容,而不仅仅是更新的部分。 Gitlab 然后将生成差异并正确提交更改。您需要更新您的有效负载,使其看起来像:

PAYLOAD=$(cat << JSON
{
  "branch": "mybranch",
  "commit_message": "some commit message",
  "actions": [
    {
      "action": "update",
      "file_path": "roles/test.j2",
      "content": "this is the entire content in the test.j2 file after updating it"
    },
    {
      "action": "update",
      "file_path": "roles/prod.j2",
      "content": "This is the entire content in the prod.j2 file after updating it"
    }
  ]
}
JSON
)

您可以在 the docs 中看到所有可选和必需的参数。 ]