A simple pre-receive hook (blocking all commits+push) is not invoked when the Bitbucket built-in editor is used. Any change can be committed and is added to the respective ref/branch regardless of the pre-receive hook presence.
A push from a git CLI invokes the pre-receive hook and the push is rejected.
How to reproduce:
Create app with simple <pre-receive-hook> that rejects everything
Install app in BBS
edit a file in a repository on ‘master’ branch with the BBS Editor
Commit the file.
Expected result: commit rejected
Actual result: commit accpted
May I ask what version of the Bitbucket Server API you are using? As of 6.0, <pre-receive-hook> has been deprecated. Instead you can use <repository-hook> and create a class that implements PreRepositoryHook. PreRepositoryHooks receive updates from both Git and UI events such as file edit, where as the old pre-receive hooks only received updates that happened through git push (and file editing comes through the REST API rather than through Git)
We’re looking at Bitbucket 5.15.x and 5.16.x - I will have migrate to repository-hooks for 5.x as well. Do you know which is the earliest version of Bitbucket that introduced PreRepositoryHook
For Bitbucket 6x we have changed to PushToBranchHook implements PreRepositoryHook<RepositoryHookRequest> already. Web UI commits are rejected
public class PushToBranchHook implements PreRepositoryHook<RepositoryHookRequest> { ...
with atlassian-plugin.xml
<pre-receive-hook key="workzone-pushToBranchHook" name="Push to Branch Hook" class="com.izymes.workzone.hook.PushToBranchHook">
<description>Disables pushing to branches that are the source of an active pull request</description>
</pre-receive-hook>
rejects the push from the web-ui editor
The new module type repository-hook
<repository-hook key="workzone-pushToBranchHook" name="Push to Branch Hook" class="com.izymes.workzone.hook.PushToBranchHook">
<description>Disables pushing to branches that are the source of an active pull request</description>
</repository-hook>
does not seem to enforce the control
@khughes - any idea what’s missing? Thanks for your help!
Your xml and class definition looks fine. Perhaps there is something missing in your implementation of the hook? Are you only rejecting certain RepositoryHookTriggers? You will need to make sure your hook still rejects requests that are of type StandardRepositoryHookTrigger.FILE_EDIT.
adds a configuration item to the repository hooks configuration - which has to be enabled manually.
Is there a way to turn on/of this hook programmatically? The hook Workzone provides is configured via the workzone app. Is there any option to enable the <repository-hook> permanently and programmatically when installing the app?
The Workzone admin should not have to go to the hooks configuration outside workzone to enable the hook.
In fact if <pre-receive-hook> is replaced with <repository-hook> most clients would lose their workzone hooks configuration since it won’t be activated.