Reputation: 474
I am trying to create a utility tool for which I need to get the latest tag committed to a specific repo. I have tried so far:
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'
What I get in return is paginated response, like this:
{
"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
}
Now as per the documentation I have referred through here, tags
are specially ordered when returned, but I am confused as to why the value release-1.3
is not first in the response. I think I am missing something. Or if this is the expected order, how can I achieve the tags sorted on date
attribute, to get the latest tag.
Upvotes: 4
Views: 5783
Reputation: 31
Answer by @Dota2 is nearly correct but the matter of fact is its descending sorted and never give latest commit sorted on top this easily can be done by adding - to query string like below
https://api.bitbucket.org/2.0/repositories/purevpn/dialerxn/refs/tags?sort=-target.date
In json adding - will do assending sort sort=-target.date
Upvotes: 1
Reputation: 474
So I was able to solve this by using sort
on 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'
Upvotes: 2