Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Pullrequest merge source and destination branch

pp
Contributor
January 7, 2020

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.

 

1 answer

0 votes
Minh Tran
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 7, 2020

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events