gpt4 book ai didi

BitBucket:如何通过 API 更新文件

转载 作者:行者123 更新时间:2023-12-02 02:46:33 25 4
gpt4 key购买 nike

我很难理解如何实现以下 API 来更新存储库中的文件:

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/src#post

GitLab 和 GitHub 有一个简单的 API - 传递文件内容 + 提交 SHA,如果提交 SHA 仍然是最新的,它将更新。

我试过了,当然它很高兴地覆盖了已经存在的任何东西:

curl -X POST \
'https://api.bitbucket.org/2.0/repositories/%7B%7D/{uuid}/src' \
-H 'Authorization: Bearer ***' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'cache-control: no-cache' \
-d 'src%2Flocale%2Fen.js=test&message=Test%20commit'

如何指定文件提交 SHA,以便它不会在更新后覆盖内容?谢谢

最佳答案

在您的问题中已有的文档中说明:

parents (string):
A comma-separated list of SHA1s of the commits that should be the parents of the newly created commit.
When omitted, the new commit will inherit from and become a child of the main branch's tip/HEAD commit.
When more than one SHA1 is provided, the first SHA1 identifies the commit from which the content will be inherited.
When more than 2 parents are provided on a Mercurial repo, a 400 is returned as Mercurial does not support "octopus merges".

这并没有真正说明预防,但在 branch 参数的描述中指出:

When a branch name is not specified, but a parent SHA1 is provided, then Bitbucket asserts that it represents the main branch's current HEAD/tip, or a 409 is returned.

所以,听起来您只需要将该参数添加到您的数据负载中,如果提供的哈希不是当前提交,它应该可以防止更改。然后您会收到返回 HTTP 状态 409 的响应。

-d 'src%2Flocale%2Fen.js=test&message=Test%20commit&parents=sha-hash'

关于BitBucket:如何通过 API 更新文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54430626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com