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