【问题标题】:how to get a list of commits from refChanges in Atlassian Stash Pre Receive Repository Hook如何从 Atlassian Stash Pre Receive Repository Hook 中的 refChanges 获取提交列表
【发布时间】:2015-03-14 18:26:07
【问题描述】:

我正在尝试编写一个存储插件,该插件将遍历推送到预接收存储库挂钩中存储的更改集中的提交。

API 在 onReceive 方法中传递一个 refChange 集合。

public boolean onReceive(RepositoryHookContext context, Collection<RefChange> refChanges, HookResponse hookResponse)

如果我进行 3 次提交,然后 push 我会得到一个 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 参数。

我是不是走在正确的道路上?

【问题讨论】:

    标签: bitbucket-server atlassian-plugin-sdk


    【解决方案1】:

    尽管 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");
    }
    

    【讨论】:

    • 您如何使用commitService ?我想弄清楚如何初始化它
    • 我相信它是通过构造函数注入的...public class myClass implements AsyncPostReceiveRepositoryHook, RepositorySettingsValidator { private final CommitService commitService; public myClass(CommitService commitService, NavBuilder navBuilder) { this.commitService = commitService; this.navBuilder = navBuilder; }
    • 当我出于某种原因使用这个构造函数时,它会完全禁用我的插件,当我刷新我的存储库挂钩时,它会从列表中消失......我该如何实现这个?
    【解决方案2】:

    我无法让依赖注入为 CommitService 工作。尝试在本地运行时,Spring由于某种原因无法找到它???

    我确实使用组件定位器让它工作了。

    CommitService commitService = ComponentLocator.getComponent(CommitService.class);
    

    【讨论】:

      猜你喜欢
      • 2017-01-18
      • 2012-08-16
      • 2015-06-28
      • 1970-01-01
      • 2016-09-19
      • 2013-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多