SVN Mirror run before Script Pre Hooks

One of our team is working on migrate their SVN repo to git. They enabled the mirror and it’s working as supposed. Then they want to add a Bitbucket Script Runner Script Pre Hook to make sure all commit has a jira issue linked, so they created a “Script Pre Hook” to check if there is a valid Jira issue ID in the commit message; if not the Pre hook will reject the commit.

This Pre hook works fine with other bitbucket repos without SVN mirror enabled; but when SVN Mirror is enabled on the repo, when a user push a commit without a Jira Issue ID in message, he got the correct Pre Hook message:

remote: =====================================================================
remote: One or more JIRA issues from your commits not found by query (status = “In progress”):
remote:
remote: b30c6b0e6b7: Commit not associated with a valid ticket
remote: =====================================================================
remote:
remote:
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ‘ssh://git@mybitbucket.server.com/tools/testrepo1.git’

The commit was rejected by bitbucket, but it’s still synced to the SVN repo; and later it will be synced back to bitbucket by the mirror , so this defeated the goal for the bitbucket pre hook.

It seems SVN mirror will run before the Pre Hook.

Is there any way to work around this?

Thanks,
Jack

Hello Jack

it seems we overlooked this issue, sorry for that. Indeed, at this time Bitbucket invokes hooks basing on its internal algorithm and it may happen that our hook (that is supposed to be invoked last) is being invoked earlier than Script Pre Hook. To overcome that the SVN Mirror add-on hooks should be invoked last, but at this time Bitbucket doesn’t provide possibilities to set particular hooks order.

We managed to find a way to fix the hooks order, but it works only on Bitbucket v.4 and not on BB5 or 6. The Bitbucket Script Runner Script Pre Hook most probably uses Bitbucket Server commit callback API to analyze pushed commits and only reports result later, after all, other hooks were given a chance to run their code.

By this time, we haven’t managed to find a way to modify the SVN Mirror add-on hook code to fix that issue. However, we’re still working on the issue, I will inform you if any news comes. By the way, do I understand correctly, that you are suing Adaptavist ScriptRunner? If not, could you please describe your setup in a little more detail?

Thanks Ildar. Yes we are using Adaptavist ScriptRunner. We are running BB6.