I am using script runner. Need to identify the source and destination branch of a pullrequest merge.
import com.atlassian.bitbucket.event.pull.PullRequestMergedEvent
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.sal.api.component.ComponentLocator
PullRequestMergedEvent event = (PullRequestMergedEvent)event
// Retrieve Source branch of the pull request
def source = event.getPullRequest().getFromRef().getId()
// Retrieve Target branch of the pull request
def destination = event.getPullRequest().getToRef().getId()
In script runner console I see below error:
Static type checking - Variable event is undeclared,
I am new to groovy, still in learning state.
Hi @pp
The error complained about undeclared event variable. Your above code is not called from an event source
I suggest to use com.atlassian.event.api.EventListener annotation for your handler method
so it will be something like
@EventListener
deff onPullRequestMerged(PullRequestMergedEvent event) {
// Retrieve Source branch of the pull request
def source = event.getPullRequest().getFromRef().getId()
// Retrieve Target branch of the pull request
def destination = event.getPullRequest().getToRef().getId()
}
I hope this help
Regards,
Minh
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.