Forums

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

PullRequestOpenedEvent or pre hooks when pull request is created

zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 22, 2020

I would like to create Jira issue when pull request is created in BitBucket. So I've read in documentation that there is a PullRequestOpenedEvent. In addition, I've read that there is Pre Hooks.

Guys, do you know what should I use to create Jira task in Jira when pull request is created in Jira?

 

If you could provide some code or links, it would be really helpful. Any help would be greatly appreciated.

2 answers

1 accepted

1 vote
Answer accepted
Robert Giddings _Adaptavist_
Community Champion
May 22, 2020

Hi @zaharovvv_suek_ru ,

Looking at the links you provided, it looks like you are using the app ScriptRunner for Bitbucket?

If that is the case, then you want to create a Custom Event Handler in ScriptRunner for Bitbucket, that listens for the PullRequestOpenedEvent and then creates a Jira issue via the Jira REST API.

Here is an example script in our documentation which updates a Jira issue when a Pull Request is opened: https://scriptrunner.adaptavist.com/6.0.1/bitbucket/StashEventHandlers.html#_update_all_related_jira_issues_when_pull_request_opened

You should be able to use this script as a base and then edit it to create, rather than update a Jira issue my changing the REST API used.

Kind regards,

Robert Giddings,

Product Manager for ScriptRunner for Bitbucket

zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 25, 2020

@Robert Giddings _Adaptavist_  thank you for your answer! 

It was not simple to create an issue from the Bitbucket. I've tried to create an issue, however issue is not created and there is no errors. Could you, please, see this question

1 vote
Egor Kovetskiy
Contributor
May 22, 2020

Hi,

Yeah, you got the right direction, first, you need to catch the event, in your add-on it will be something like that:

```
@EventListener
public void onPullRequestOpened(PullRequestOpenedEvent event) {
```

You don't need pre hooks, you just define a class and use that @EventListener annotation, so your java code receives these events from now on.

It's the first part, the second part is creating a Jira issue. For your add-on Jira is just a remote server with a REST API, so you just need to consume this API and create an issue by making specific HTTP requests.

zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 25, 2020

@Egor Kovetskiy  thank you for your answer. It was not simple to create an issue from the Bitbucket. I've tried to create an issue, however issue is not created and there is no errors. Could you, please, see this question

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.4.1
TAGS
AUG Leaders

Atlassian Community Events