Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I access commit diffs in a bitbucket server pre-receive hook plugin?

ehohenstein@imvu.com
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 2, 2019

I've spent quite a few hours looking over the bitbucket SPI documentation and I've studied the examples provided. I see that I can inspect the individual commits being added with an implementation of PreRepositoryHook by passing an instance of PreRepositoryHookCallback to the registerCommitCallback function of the PreRepositoryHookContext instance passed to the preUpdate function of PreRepositoryHook that I can implement in a plugin. The added commits will be passed as CommitAddedDetails to the onCommitAdded function of my callback. However, I don't see a way to obtain the actual changes to the files of the repository associated with those commits.

We are migrating a significantly sized set of policy checks from an svn server-side pre-commit hook to bitbucket as we migrate from svn to git. My goal is to implement a pre-receive hook that will analyze the changes made to individual files in the repository to validate that they are not violating our company policies. An example would be disallowing the use of calls to exec() in PHP files.

Many of our policy checks involve counting the occurrences of certain patterns in changed files to compare the number of instances of certain patterns before vs. after to ensure that a change is not "making things worse", so ideally we would want to be able to access the full content of a file in the repository at the previous and added revision. The same thing could be accomplished with just the diff, though the logic of our checks would have to be a bit different from how they are currently implemented.

I realize that this could be accomplished with client-side commit hooks (and we have already done so). However, we would prefer to maintain the enforcement of our policy server-side since it's trivial to bypass client-side checks.

We are using bitbucket server 5.9.1.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events