首页 > 解决方案 > 如何获取使用 Atlassian api 推送代码的用户

问题描述

特点是:只有被批准列表中的用户才能将代码推送到特殊分支。我使用 Atlassian Bitbucket 作为 Gitserver。在钩子预更新中。我需要找出推送代码的用户。

例如:

git add 1
git commit
git cherry-pick 2
git cherry-pick 3
git push

一次推送有 3 个提交,作者不同,提交者相同。在更新前,请参考 atlassian 开发者 api

com.atlassian.bitbucket.hook.repository.RepositoryHookRequest;
com.atlassian.bitbucket.repository.RefChange;

我只能得到每个提交的作者。在这个例子中,我可以得到 3 个不同的用户名。一些代码如下:

Collection<RefChange> refChanges = request.getRefChanges();
for (RefChange refChange : refChanges) {
    List<Commit> commits = CommitSvc.getCommitsBetweenFromAndTo(refChangeNew, repo, false);
    for (Commit commit : commits) {
        String username = commit.getAuthor().getName()
    }
}

那么,有谁知道如何获取推送代码的用户?是否有 api 或 git-command 支持此功能?

此功能类似于“在没有拉取请求的情况下防止更改,除非:”。如何在我的脚本中实现此功能。或者我可以通过api在bitbucket中设置权限吗?因为如果我们手动执行会花费很长时间并且需要多次执行。例如:

PROA/repo1 PROA/repo2 PROA/repo3 for user1.
PROA/repo2 PROA/repo4 for user2. 

标签: gitbitbucket-api

解决方案


推荐阅读