The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Java API to get commit history in a merge check

Sandeep Pillay
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 24, 2019

I am writing a merge check plugin for which I need a list of commits made to the repository in question in the preUpdate method. Can someone help me with the right API to use? 

My Code:

public class MyCheck implements RepositoryMergeCheck
{
public RepositoryHookResult preUpdate(PreRepositoryHookContext context, PullRequestMergeHookRequest request)
{
//TODO: Get list of repository commits here to process them
return RepositoryHookResult.accepted();
}
}

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
gsj889
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 2, 2025

You want to do something like this:

final PullRequest pullRequest = pullRequestMergeHookRequest.getPullRequest();

CommitsBetweenRequest commitsRequest = new CommitsBetweenRequest.Builder(pullRequest)
.include(pullRequest.getFromRef().getLatestCommit())
.exclude(pullRequest.getToRef().getLatestCommit())
.build();

PageRequest pageRequest = new PageRequestImpl(0, PageRequest.MAX_PAGE_LIMIT);
Page<Commit> commits = commitService.getCommitsBetween(commitsRequest, pageRequest);

You will have to loop and do

pageRequest = commits.getNextPageRequest();

until

pageRequest != null

Check these examples: 

TAGS
AUG Leaders

Atlassian Community Events