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();
}
}
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.