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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

BitBucket Cloud API confirm if commit id in branch

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 Mar 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
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,927 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you