I'm attempting to write a pre-receive hook in Stash 3.9. I have some problems to retreive the commits that were pushed. This is what i've done so far:
CommitsBetweenRequest.Builder commitsBetweenBuilder = new CommitsBetweenRequest.Builder(context.getRepository()) ;
commitsBetweenBuilder.exclude(refChange.getFromHash());
commitsBetweenBuilder.include(refChange.getToHash());
PageRequest pageRequest = new PageRequestImpl(0,125);
CommitsBetweenRequest request = commitsBetweenBuilder.build();
I'm having some problems with the commitService.
Please help me to understand how should proceed.
Thanks,
Alex
Community moderators have prevented the ability to post new answers.
After this, you need to use getCommitsBetween.
Something like this:
final CommitsBetweenRequest request = new CommitsBetweenRequest.Builder(repository) .exclude(refChange.getFromHash()) //this is all 0's for RefChangeType.ADD .include(refChange.getToHash()) .build(); final Page<Commit> cs = commitService.getCommitsBetween(request, PageUtils.newRequest(0, 9999)); for(Commit commit: cs.getValues()) { //false for new commits, true for old ones if (!commitIndex.isMemberOf(commit.getId(), repository)) { //do stuff; } }
In which package can i find "PageUtils". By the way, what is the the commitIndex ? I don't really if the "cs" Page is showing to me the current commits that user is about to push or it's showing to me the whole history ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
PageUtils is com.atlassian.stash.util.PageUtils (for some reason, I cannot find it here: https://developer.atlassian.com/static/javadoc/stash/latest/api/reference/classes.html) CommitIndex: https://developer.atlassian.com/static/javadoc/stash/latest/api/reference/com/atlassian/stash/idx/CommitIndex.html ; You need to pass it in as a parameter to the constructor, like this: public YourHook(final CommitService commitService, final CommitIndex commitIndex, final NavBuilder navBuilder) {this.commitService = commitService; this.commitIndex = commitIndex; this.navBuilder = navBuilder;} cs will contain more than the freshly pushed commits, because it has all the commits whose ref information has changed. eg. for a new branch with no unique commits, it will only contain pre-existing commits. (All the commits than now belong to this branch as well.) These are filtered out with the help of CommitIndex.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great! I have another question what can i do with the "NavBuilder" ? Last but not least, do you know how can i ammend a commit message, and also what is the process of getting fields from a specific issue on Jira, before we've started working with Stash, i've used simple bash scripts and just used the REST API of Jira, but i'm sure that there is a better way, to get some fields from Jira issues. Thanks, Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
NavBuilder is used for creating URL's pointing to Stash pages: https://developer.atlassian.com/static/javadoc/stash/latest/api/reference/com/atlassian/stash/nav/NavBuilder.html No idea about the Jira part.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.