reconquest / atlassian-external-hooks

External Hooks plugin for Atlassian Bitbucket
https://external-hooks.reconquest.io
Other
44 stars 37 forks source link

[Question] How to access PR information from a script #137

Closed andreycha closed 1 year ago

andreycha commented 1 year ago

Hi, I'm checking available plugins which can help me achieve following: all Bitbucket PRs that target Jira tickets with priority Critical should be approved before merge. I've checked External Hooks documentation and it looks like in general I should be able to implement such a check and set it up using a pre-receive or merge check trigger. Unfortunately, docs say nothing on how to access pull request information (and if it's possible at all). Could you please point me to such a sample or provide one? Thank you!

kovetskiy commented 1 year ago

Hey!

You can access pull request information with environment variables: https://external-hooks.reconquest.io/docs/environment-variables/

In previous versions of Bitbucket we could see things like PULL_REQUEST_TITLE but it's not technically possible now.

What you can do instead is to read git commit message from the hook script and access any other information using Bitbucket REST API (the pr id is available in BB_PULL_REQUEST_ID)

You can also check an example on how to require commits to have a jira link: https://external-hooks.reconquest.io/docs/example.bitbucket-require-commits-to-be-associated-with-a-jira-issue/

andreycha commented 1 year ago

access any other information using Bitbucket REST API (the pr id is available in BB_PULL_REQUEST_ID)

Ah, that's a good tip. Thank you!