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

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: 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events