0

The feature is:only user in the approved-list can push code to a special branch. I use Atlassian Bitbucket as Gitserver. In the hook pre-update. I need to figure out the user who is pushing the code.

for example:

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

There are 3 commits in a push, The author is different,the commiter is same. In pre-update, refer to the atlassian developer api

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

I can only get the author of every commit.In this example,I can get 3 different user names. some code bellow:

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()
    }
}

So, Does anyone know how to get the user who are pushing the code? Is there an api or git-command support this function?

This feature is like "Prevent changes without a pull request, except by:". How to achieve this function in my scripts. Or may I set the permission in bitbucket through api? Because it will take a long time and need many times of executions if we do it manually.For example:

PROA/repo1 PROA/repo2 PROA/repo3 for user1.
PROA/repo2 PROA/repo4 for user2. 
clara
  • 182
  • 1
  • 2
  • 13
  • Are you sure the [bitbucket integrated branch permission management](https://confluence.atlassian.com/bitbucketserver/using-branch-permissions-776639807.html) cannot satisfy your requirements? – Zeitounator Dec 12 '19 at 09:40
  • Prevent changes without a pull request, except by: This can satisfy my requirements in a whole project or a single repo. But we divided repos into groups according to developer groups.So we want to develop a tool to set the permission. – clara Dec 13 '19 at 01:59
  • This feature is like "Prevent changes without a pull request, except by:". how to achieve this function in my scripts. Or may I set the permission in bitbucket through api? Because it will take a long time and need many times of executions if we do it manually.For example:PROA/repo1 PROA/repo2 PROA/repo3 for user1.PROA/repo2 PROA/repo4 for user2. – clara Dec 13 '19 at 02:08

0 Answers0