首页 > 解决方案 > 从 bitbucket api 2.0 获取最新的标签提交

问题描述

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

    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
}

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

标签: apibitbucketbitbucket-apibitbucket-cloud

解决方案


所以我能够通过使用sorton attribute来解决这个问题target.date

   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'

推荐阅读