jamuna
jamuna

Reputation: 113

I want to get commits on a branch in bitbucket stash via rest api

I am trying to get commits on a particular branch in bitbucket stash.

  1. Branch was initially branched from master to develop some features
  2. after feature code was committed it was merged back to master
  3. But the branch was not deleted, so I want to use Bitbucket rest API to get the exact commits on that particular feature branch.

I tried

https://<stash-url>/stash/rest/api/1.0/projects/<project-ID>/repos/<repo-slig>/compare/commits?from=<my-target-feature-branch>&to=master

which gives me

{
"values": [],
"size": 0,
"isLastPage": true,
"start": 0,
"limit": 25,
"nextPageStart": null
}

and the other url i tried is

https://<stash-url>/stash/rest/api/latest/projects/<project-ID>/repos/<repo-slug>/commits?until=<my-target-feature-branch>&limit=100

which gives me the whole commit history from master too.

can someone please help me? I am a newbie and I'm sure there is something wrong in my understanding of API docs

Upvotes: 1

Views: 16004

Answers (3)

Nabil Mohammed Asif
Nabil Mohammed Asif

Reputation: 21

You can! Using the tag:

?until=refs/heads/{branch-name}

My example:

curl -u <user>:<pass> -X GET "https://stash.xxx.com/rest/api/latest/projects/{project-key}/repos/{repo-slug}/commits?until=refs/heads/feature/ALMENGI-460"

Upvotes: 1

Alderven
Alderven

Reputation: 8270

This gives you the list of commits only for provided branch:

GET https://api.bitbucket.org/2.0/repositories/{WORKSPACE}/{REPO}/commits?include={BRANCH}&exclude=master

See BitBucket documentation for more details.

Upvotes: 1

eeijlar
eeijlar

Reputation: 1340

Try:

https://<stash-url>/stash/rest/api/latest/projects/<project-ID>/repos/<repo-slug>/commits?until=<my-target-feature-branch>&limit=0&start=0

See also: https://community.atlassian.com/t5/Bitbucket-questions/Querying-the-last-commit-on-a-particular-branch-in-Bitbucket/qaq-p/577910

Upvotes: 1

Related Questions