# Pre-Receive Hook not invoked when Bitbucket file editor is used

**URL:** <https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087>\
**Category:** Bitbucket Server\
**Created:** [May 6, 2019, 12:44pm UTC](https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087 "2019-05-06T12:44:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![izymesdev](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/izymesdev/32/35901_2.png) [@izymesdev](https://community.developer.atlassian.com/u/izymesdev)\
**Post date:** [May 6, 2019, 12:44pm UTC](https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087/1 "2019-05-06T12:44:20Z")

</div>

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:

1. Create app with simple `<pre-receive-hook>` that rejects everything
2. Install app in BBS
3. edit a file in a repository on ‘master’ branch with the BBS Editor
4. Commit the file.

Expected result: commit rejected  
Actual result: commit accpted

---

<div class="post-metadata">

**Author:** ![khughes](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/khughes/32/37649_2.png) [@khughes](https://community.developer.atlassian.com/u/khughes)\
**Post date:** [May 7, 2019, 1:43am UTC](https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087/2 "2019-05-07T01:43:04Z")

</div>

Hi @izymesdev,

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](https://docs.atlassian.com/bitbucket-server/javadoc/latest/spi/reference/com/atlassian/bitbucket/hook/repository/PreRepositoryHook.html) 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)

Hope that helps.

Regards,  
Kristy

---

<div class="post-metadata">

**Author:** ![izymesdev](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/izymesdev/32/35901_2.png) [@izymesdev](https://community.developer.atlassian.com/u/izymesdev)\
**Post date:** [May 8, 2019, 8:37pm UTC](https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087/3 "2019-05-08T20:37:26Z")

</div>

Hello Kristy  
thanks for getting back to us.

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 👍

Thanks for your help clarifying this issue.

---

<div class="post-metadata">

**Author:** ![khughes](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/khughes/32/37649_2.png) [@khughes](https://community.developer.atlassian.com/u/khughes)\
**Post date:** [May 9, 2019, 12:14am UTC](https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087/4 "2019-05-09T00:14:05Z")

</div>

PreRepositoryHook was first released in 5.0 so it should be available for you to switch to.

---

<div class="post-metadata">

**Author:** ![izymesdev](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/izymesdev/32/35901_2.png) [@izymesdev](https://community.developer.atlassian.com/u/izymesdev)\
**Post date:** [May 14, 2019, 8:40pm UTC](https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087/5 "2019-05-14T20:40:05Z")

</div>

```auto
public class PushToBranchHook implements PreRepositoryHook<RepositoryHookRequest> { ...

```

with atlassian-plugin.xml

```auto
  <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  
[![CloudApp](https://f.v1.n0.cdn.getcloudapp.com/items/2h2t3o2C0H3q1Q1w3L0g/pre-receive-hook.gif "pre-receive-hook") ](https://cl.ly/qGuyo6lk)

The new module type `repository-hook`

```auto
  <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  
[![CloudApp](https://f.v1.n0.cdn.getcloudapp.com/items/2d1J44442y040u1q3M3z/repository-hook.gif "repository-hook") ](https://cl.ly/WnudN6lp)

@khughes - any idea what’s missing? Thanks for your help!

---

<div class="post-metadata">

**Author:** ![khughes](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/khughes/32/37649_2.png) [@khughes](https://community.developer.atlassian.com/u/khughes)\
**Post date:** [May 16, 2019, 12:49am UTC](https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087/6 "2019-05-16T00:49:29Z")

</div>

Your xml and class definition looks fine. Perhaps there is something missing in your implementation of the hook? Are you only rejecting certain `RepositoryHookTrigger`s? You will need to make sure your hook still rejects requests that are of type `StandardRepositoryHookTrigger.FILE_EDIT`.

---

<div class="post-metadata">

**Author:** ![izymesdev](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/izymesdev/32/35901_2.png) [@izymesdev](https://community.developer.atlassian.com/u/izymesdev)\
**Post date:** [May 16, 2019, 10:52am UTC](https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087/7 "2019-05-16T10:52:24Z")

</div>

> [@khughes](#):
>
> `<repository-hook>`

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.

 ![image](https://global.discourse-cdn.com/atlassiandeveloper/original/3X/4/7/472dcb1cef8a10fef13a506d16c8f40f5e12f835.png)  
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.

---

<div class="post-metadata">

**Author:** ![khughes](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/khughes/32/37649_2.png) [@khughes](https://community.developer.atlassian.com/u/khughes)\
**Post date:** [May 17, 2019, 2:27am UTC](https://community.developer.atlassian.com/t/pre-receive-hook-not-invoked-when-bitbucket-file-editor-is-used/29087/8 "2019-05-17T02:27:00Z")

</div>

Yep! If you take a look at the ‘Global Hooks’ section of the [docs](https://developer.atlassian.com/server/bitbucket/how-tos/hooks-merge-checks-guide/) you will see:

> This can be achieved by adding the `configurable="false"` attribute to the `repository-hook` element in `atlassian-plugin.xml`

Global hooks are always triggered, and your plugin can decide whether or not to reject each request or not based on your own configuration.
