Hosting events

Overview

Bitbucket Server provides events which can be used to hook into SCM hosting operations, of particular interest for hosting are the push event and the pull event.

Using Bitbucket Server events you can respond to user operations which repository hooks and global hooks cannot, you can also replicate the behaviour of global hooks.

Example: using an event to replicate global hooks

MyBitbucketEventListener.java

package com.atlassian.bitbucket.example;

import com.atlassian.event.api.EventListener;

public class MyBitbucketEventListener
{
	@EventListener
	public void mylistener(RepositoryPushEvent pushEvent)
	{
		//call to your psuedo-hook with pushEvent.getRepository() and pushEvent.getRefChanges()
	}
}

Note: you won't be able to reject a push or write information back to the client using this method.

Some examples of where we use these events in a few places in Bitbucket Server:

  • In pull requests, to work out if we need to update a pull request based on a client's push.
  • In branch permissions, to work out if we can delete a branch permission (when the branch is deleted).

Responding to application events is detailed here