I am using Scriptrunner to create a custom event handler for a repository.
Currently the event handler gets triggered every time a new branch is created in any repository or project. I want to be able to restrict the custom event handler only to a specific repository.
The BranchCreatedEvent class enables me to apply my program logic to a specific repository but as of right now I haven't found a solution to prevent the event handler to be triggered by a different repository.
I have successfully tried to restrict a different kind of event handler to a specific repository using the Bitbucket web UI. Unfortunately there isn't this kind of configuration option available for creating custom event handlers. Is it even possible to change the setting from
'Repositories/ Projects: All' to 'Repositories/ Projects: specificRepository' for custom event handler?

I have also checked the documentation at: https://scriptrunner.adaptavist.com/6.5.0-p5/bitbucket/StashEventHandlers.html?utm_source=product-help#_applying_event_handlers_to_specific_projects_repositories
I'm not sure if I understand the sample code correctly and I haven't successfully tried it that way. I assume that the code restricts only the if block and does not change the display of the BitBucket web UI.
My code:
import com.atlassian.bitbucket.event.branch.BranchCreatedEvent
BranchCreatedEvent event = event
def repo = event.repository
def branch = event.branch
def branchName = event.branch.displayId
if(repo.name == "foo") {
doSomething()
}