gitlab:通过API提交多个文件

发布于 2025-02-07 12:04:50 字数 1053 浏览 1 评论 0原文

我有一个在gitlab ci中运行的脚本,该脚本结帐了一个新的分支并运行“ NPM运行文档”。这是根据上次运行以来的更改来更新各种Markdown文件。如果有任何更改,脚本将进行更改并创建新的MR。 GitLab文档显示了多文件提交的示例,但您似乎必须知道哪些文件将会更改。

PAYLOAD=$(cat << 'JSON'
{
  "branch": "master",
  "commit_message": "some commit message",
  "actions": [
    {
      "action": "create",
      "file_path": "foo/bar",
      "content": "some content"
    },
    {
      "action": "delete",
      "file_path": "foo/bar2"
    },
    {
      "action": "move",
      "file_path": "foo/bar3",
      "previous_path": "foo/bar4",
      "content": "some content"
    },
    {
      "action": "update",
      "file_path": "foo/bar5",
      "content": "new content"
    },
    {
      "action": "chmod",
      "file_path": "foo/bar5",
      "execute_filemode": true
    }
  ]
}
JSON
)
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" \
     --data "$PAYLOAD" "https://gitlab.example.com/api/v4/projects/1/repository/commits"

如果更新的文件是可变的,我将如何生成操作。 (我正在通过API承诺围绕GPG签名)

I have a script that runs in Gitlab CI that checkouts a new branch and runs 'npm run docs'. This updates various markdown files based on the changes since the last run. If there are any changes, the script will commit the changes and create a new MR. The Gitlab docs show an example of multi file commits but it seems like you have to know which files will change.

PAYLOAD=$(cat << 'JSON'
{
  "branch": "master",
  "commit_message": "some commit message",
  "actions": [
    {
      "action": "create",
      "file_path": "foo/bar",
      "content": "some content"
    },
    {
      "action": "delete",
      "file_path": "foo/bar2"
    },
    {
      "action": "move",
      "file_path": "foo/bar3",
      "previous_path": "foo/bar4",
      "content": "some content"
    },
    {
      "action": "update",
      "file_path": "foo/bar5",
      "content": "new content"
    },
    {
      "action": "chmod",
      "file_path": "foo/bar5",
      "execute_filemode": true
    }
  ]
}
JSON
)
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" \
     --data "$PAYLOAD" "https://gitlab.example.com/api/v4/projects/1/repository/commits"

How would I go about generating the actions if the files that are updated is variable. (I am committing via API to get around GPG signatures)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文