我试图编写一个存储插件,它将遍历一个更改集中的提交,这些更改集被推送到存储在Pre Receive Repository Hook中。
API在onReceive方法中传递了一个refChange集合。
public boolean onReceive(RepositoryHookContext context, Collection<RefChange> refChanges, HookResponse hookResponse)
如果我进行3次提交然后推送我得到一个看起来像这样的RefChange
refId = refs/heads/master
fromHash = ded3e4583653f14892cc3e8a898ba74ee75e1a58 // First Commit in change set
toHash = ae017dcdadf7ca69617fb05f6905cccfe2aa4229 // Most recent commit
type = "UPDATE"
我想获得所有提交的集合,以便我可以获得所有提交消息。
我正在查看com.atlassian.stash.commit.CommitService getCommit和getCommits。我想我需要getCommitsBetween但是不能完全弄清楚如何创建我所拥有的RefChange所需的GetCommitsBetween参数。
我甚至在这里走正确的道路吗?
答案 0 :(得分:2)
即使Atlassian Stash API文档中的CommitsBetweenRequest
页面是少数几个有解释的页面之一,但需要一些试验和错误来解决这个问题。 GetCommitsBetween
有效,但这就是诀窍......
将commitsBetweenBuilder.exclude
设置为更改集中的起始提交,将commitsBetweenBuilder.include
设置为结束提交哈希。
CommitsBetweenRequest.Builder commitsBetweenBuilder = new CommitsBetweenRequest.Builder(context.getRepository() );
commitsBetweenBuilder.exclude(refChange.getFromHash()); //Starting with
commitsBetweenBuilder.include(refChange.getToHash()); // ending with
PageRequest pageRequest = new PageRequestImpl(0,6);
Page<Commit> commits = commitService.getCommitsBetween(commitsBetweenBuilder.build(), pageRequest);
//TODO: handle Pages
for (Commit commit : commits.getValues()) {
hookResponse.out().println("Message = " + commit.getMessage() + "\n");
}
答案 1 :(得分:-2)
我无法让依赖注入为CommitService工作。当试图在本地运行时,Spring出于某种原因无法找到它
我确实使用组件定位器让它工作。
CommitService commitService = ComponentLocator.getComponent(CommitService.class);