Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

BitBucket Cloud API confirm if commit id in branch

izalcomax March 14, 2021

hi,

I'm trying to find out if a commit is within a branch. I thought I could filter the commits in a branch eg

https://api.bitbucket.org/2.0/repositories/cartoncloud/service-access/commits/staging

returns a response with the "hash" that I thought I could filter on.

values: [
  {
    "rendered": {
        ..
    },

    "hash": "fed8b7a890fb2dafb7eb7d44bd11d2e7efb36fa3",
...

So based on sort and filter doc I should be able to do this.

https://api.bitbucket.org/2.0/repositories/cartoncloud/service-access/commits/staging?q=hash=fed8b7a890fb2dafb7eb7d44bd11d2e7efb36fa3

However this gives exactly the same response ie seems filter not applied.

Also tried

https://api.bitbucket.org/2.0/repositories/cartoncloud/service-access/commits/?hash=fed8b7a890fb2dafb7eb7d44bd11d2e7efb36fa3&include=staging

without success.

Seems the only approach is to page through all commits for a branch and search within each page response for that commit?

Thanks.

1 answer

1 accepted

0 votes
Answer accepted
seanaty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 17, 2021

@izalcomax The commits API is a little bit special and not filterable using `q=`. That said there are a few handy URL params for include/excluding commits.

Compare these

https://api.bitbucket.org/2.0/repositories/atlassian/bbql/commits/master?fields=values.hash,values.message
https://api.bitbucket.org/2.0/repositories/atlassian/bbql/commits/master?fields=values.hash,values.message&include=a225c3e87f897167550469144cdff0631f3995d0

If you enter a commit has that's not reachable on that branch then you get a message like:

{
"data": {
"shas": [
"a225c3e87f897167550469144cdff0631f3995d1"
]
},
"type": "error",
"error": {
"message": "Commit not found",
"data": {
"shas": [
"a225c3e87f897167550469144cdff0631f3995d1"
]
}
}
}

 See more examples here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/commits

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events