I need to know the date of the first commit for a branch in multiple repos to know the creation time of the repo, I'm using the REST API V2.
i need something like :
But i need to sort the answer from the last page, since some repos have more than 100 pages of commits but i don't know the total amount of pages, and i need the first historical commit in a master branch for each one.
Hello @Maximiliano Venesio,
I'm afraid this is not easily possible. There's no direct link to the very first commit, and to find it the whole commit tree traversal is required. This is why Bitbucket doesn't have this option in the commit list API.
You can get repo creation date by hitting repository endpoint, potentially narrowing it down to just the created_on attribute (I also included slug in this example):
However this will show when the repo has been created in Bitbucket which doesn't necessarily mean when the first commit was pushed to it or when that commit was created. The latter can be both before and after the repo creation date.
If you really need to find the date of the first commit, the only way to do that without cloning every repository is to traverse commit list till the end – until there's no next attribute in the response:
page = fetch('https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit-mk-2/commits?pagelen=100&fields=next,values.date')
page = fetch(page.next)
first_commit_date = page.values.last().date
If cloning the repo is an option, you can run this command locally (assuming your repo is under Git):
git rev-list --max-parents=0 HEAD | xargs git log --pretty=format:'%ad'
Hope this helps. Let me know if you have any questions.
Hi Daniil, thanks for your quick answer.
In my case, this call does not bring any data
Do you know if i have to add something else in my call ?
the creation date should be enough in this case.
I guess the problem is that you need to authenticate the request. That particular repository in my example is public, so you can just paste the URL into the browser, and it'll work (even in incognito mode). But for a private repository you need to authenticate the request (api.bitbucket.org doesn't allow session auth).
If that's not the issue, can you elaborate what do you actually get back?
Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster ! While we’re all excited about the new improvements to Bitbucket ...
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