reconquest / atlassian-external-hooks

External Hooks plugin for Atlassian Bitbucket
https://external-hooks.reconquest.io
Other
44 stars 37 forks source link

Execute pre/post-receive hooks when editing files in the browser #61

Closed gnustavo closed 4 years ago

gnustavo commented 6 years ago

I had to disable Bitbucket's online editing feature because it doesn't invoke our pre/post-receive hooks. However, the issue [BSERV-9521|https://jira.atlassian.com/browse/BSERV-9521] was closed suggesting that Bitbucket 5.0 implements a new hook API which also invokes hooks when a file is edited or created in the browser.

Would you consider this as an improvement? Without this I can't enable Bitbucket's online editing feature.

Thanks!

edwyn commented 6 years ago

this issue here is you need to use the new API for it to trigger inside the Bitbucket UI

public RepositoryHookResult preUpdate(@Nonnull PreRepositoryHookContext context, @Nonnull RepositoryHookRequest request) {

I'm rewriting external hook.. and see if i can get it to work using https://bitbucket.org/atlassian/bitbucket-server-example-plugins/src/9e1728cfab668ab0f8c1c4ada507994dffa5b5e6/hooks-guide/src/main/java/com/atlassian/bitbucket/server/examples/BranchInReviewHook.java?at=master&fileviewer=file-view-default

gnustavo commented 6 years ago

Cool! I'm glad to know it.

edwyn commented 6 years ago

@gnustavo I've copied much from https://github.com/ngsru/atlassian-external-hooks/pull/56 to make it work for me

simon-graham commented 6 years ago

What's the current status of this? We have a particular External Pre Receive Hook. When editing a file in the browser, I can see that it does successfully block a commit, as there is a message added to the log file:

hook 'external-pre-receive-hook' vetoed the push request

However in the browser itself, the Commit file popup stays up indefinitely with a spinning icon.

If I check on the server, the hook script has definitely stopped running and returned an error code. Why then doesn't the stderr message from the hook script appear in the browser?

seletskiy commented 6 years ago

@latitude37s: which version of plugin do you use?

simon-graham commented 6 years ago

We're using Bitbucket v5.13.1 and External Hooks v4.4-1. Especially since https://jira.atlassian.com/browse/BSERV-9749 was resolved, we were expecting to see the error messages from the bash script shown in the browser, the same as when committing from the command line.

seletskiy commented 6 years ago

@latitude37s: thanks, let me see what's wrong with it. I will let you know about results.

seletskiy commented 6 years ago

@latitude37s: well it seems like bug in Bitbucket itself.

When I try to reproduce issue I indeed see described behavior, but when I open Inspector in browser, I see:

a) JavaScript error:

TypeError: str.replace is not a function

b) In Network tab I'm able to see:

{
  "errors": [
    {
      "context": null,
      "message": "File editing canceled for 'add_file/add_file.txt' on 'master'.",
      "exceptionName": "com.atlassian.bitbucket.hook.repository.RepositoryHookVetoedException",
      "details": [
        "Push rejected by External Hook\nERROR\n"
      ],
      "trigger": {
        "id": "file-edit",
        "abortOnFirstVeto": false
      }
    }
  ]
}

ERROR in response is string which I return from bash script.

So my conclusion is that it's some problem in Bitbucket's UI itself.

Are you able to create ticket in Bitbucket bug tracker?

simon-graham commented 6 years ago

@seletskiy thanks very much for investigating. I will chase Atlassian support on this.

simon-graham commented 5 years ago

Update: Atlassian accepted this issue as a bug: https://jira.atlassian.com/browse/BSERV-11168.

seletskiy commented 5 years ago

@latitude37s: great, thanks for the update!

sourcedelica commented 3 years ago

This Bitbucket issue was Closed: Fixed with fix version 5.15.0 but the problem still exists on 6.3.6. Basically we don't see any commit range in the hook input for UI edits. What are your thoughts?

sourcedelica commented 3 years ago

Nevermind - I just upgraded to the latest External Hooks and it fixed the problem. :)