Getting repository id associated with "pull request deletion requested" event


I have written below code for event handler > create custom event handler.
Which will be hooked on “PullRequestDeletionRequestedEvent”.

This is to disable ability of normal user (author of pull request ) to delete pull request. And allow only repo admins to do this.

This works fine for one repository/project, which is hard-coded in the code.

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.user.UserService
import com.atlassian.bitbucket.event.pull.PullRequestDeletionRequestedEvent

import com.atlassian.bitbucket.permission.PermissionService
import com.atlassian.bitbucket.permission.Permission
import com.atlassian.bitbucket.project.ProjectType
import com.atlassian.bitbucket.project.ProjectService
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.bitbucket.repository.Repository

def userService = ComponentLocator.getComponent(UserService.class)
def permissionService = ComponentLocator.getComponent(PermissionService.class)
def projectservice = ComponentLocator.getComponent(ProjectService.class)
def repositoryservice = ComponentLocator.getComponent(RepositoryService.class)

def event = event as PullRequestDeletionRequestedEvent
def project = projectservice.getByKey("project_key") // how to avoid this hard coding
def repository = repositoryservice.getBySlug("project_key","repo slug")

//get repo id at run time
//ids = [list of repos for which this event handler should run]
//if (repo id ! in ids)

 if ( !permissionService.hasRepositoryPermission(event.getUser(),repository, Permission.REPO_ADMIN) ) 
        event.cancel("Only Repo Admins can delete this request ")

What we want to achieve is creating a list of repositories for which this event will be triggered ( that will be hard-coded ). And for that we need repo id to which this event belongs to.

So, my question is how to get repository id or slug at run time associated with PullRequestDeletionRequestedEvent

Try to use


Thanks @yorlov. It worked as expected :smiley: