How to get all the commits of a pull request using bitbucket java api?

bitbucket

#1

I’m creating a Bitbucket plugin which needs to check on all the commits of a pull request. I cannot find the corresponding Java api to get this information. The Bitbucket REST API give error message of

status: 401 Response: {“errors”:[{“context”:null,“message”:“You are not permitted to access this resource”,“exceptionName”:“com.atlassian.bitbucket.AuthorisationException”}]}

although I’ve given admin login to the http get method.


#2

I figure this out myself. Here are the code I used for getting pull request commits, hopefully it can be useful for others.

	CommitsBetweenRequest.Builder builder = new CommitsBetweenRequest.Builder(pullRequest);
	CommitsBetweenRequest cbr = builder.build();
	Page<Commit> commits = commitService.getCommitsBetween(cbr, new PageRequestImpl(0, SEARCH_PAGE_SIZE));
	SortedMap<Integer, Commit> commit_map = commits.getOrdinalIndexedValues();

Also the Bitbucket REST APIs are to be accessed from outside of Bitbucket. It doesn’t like to be used inside the Bitbucket. This could explain the error I received when try to use it inside the plugin.