从Bitbucket API 2.0获取最新的标签提交

时间:2019-12-12 13:18:06

标签: 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
}

现在,根据我通过heretags引用的文档,在返回时会按特殊顺序排列,但是我对为什么值release-1.3不是响应中的第一位感到困惑。我想我缺少了一些东西。或者,如果这是预期的顺序,那么我如何实现按date属性排序的标签,以获得最新的标签。

1 个答案:

答案 0 :(得分:0)

因此,我可以通过在属性sort上使用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'