api - 从 bitbucket api 2.0 获取最新的标签提交

标签 api bitbucket bitbucket-api bitbucket-cloud

我正在尝试创建一个实用工具,我需要为其获取提交给特定存储库的最新标签。 到目前为止我已经尝试过:

    curl -X GET \
  https://api.bitbucket.org/2.0/repositories/<team>/<reposlug>/refs/tags \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Authorization: Basic encodedpasswd' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Host: api.bitbucket.org'

我得到的返回是分页响应,如下所示:

{
    "pagelen": 10,
    "values": [
        {
            "name": "release-1.2",
            "links": {
            },
            "tagger": {

            },
            "date": "2019-11-15T11:53:56+00:00",
            "message": "[maven-release-plugin]copy for tag release-1.2\n",
            "type": "tag",
            "target": {
            }
        },
        {
            "name": "release-1.3",
            "links": {
            },
            "tagger": {
            },
            "date": "2019-11-20T07:53:51+00:00",
            "message": "[maven-release-plugin]copy for tag release-1.3\n",
            "type": "tag",
            "target": {
            }
        }
    ],
    "page": 1
}

现在根据我通过 here 引用的文档, tags 在返回时被特别排序,但我很困惑为什么值 release-1.3 不是响应中的第一个。我想我错过了什么。或者,如果这是预期的顺序,我怎样才能实现按 date 属性排序的标签,以获取最新的标签。

最佳答案

所以我能够通过对属性 target.date 使用 sort 来解决这个问题。

   curl -X GET \
  https://api.bitbucket.org/2.0/repositories/<team>/<reposlug>/refs/tags?sort=target.date \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Authorization: Basic encodedpasswd' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Host: api.bitbucket.org'

关于api - 从 bitbucket api 2.0 获取最新的标签提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59305529/

相关文章:

git - 从提交和标记生成变更日志

git - 使用 3.6 GB bin 文件提交后无法克隆我的 bitbucket 存储库

BitBucket:如何通过 API 更新文件

bitbucket - Snyk 如何设置自动拉取请求的审阅者(Bitbucket Cloud)

reactjs - 如何在React中显示API错误句柄?

git子模块添加错误: does not have a commit checked out

azure - 如何从 Azure Devops REST API 仅返回特定属性

rest - 如何通过 OAuth 客户端凭据配置/访问 Bitbucket 服务器 REST API

java - 如何访问JWT Token然后处理请求?

java - request.getRemoteAddr() 返回服务器ip