Using EntityLinks to query Jira data from a BitBucket plugin

Hi,

I’m working on creating a BitBucket plugin to enforce a naming scheme for branches which I realise is not really how git is meant to work but it’s a requirement from a team at my company. As part of it, I’m writing a class to validate any Jira ID’s that are in the branch names.

To do this I’m trying to use EntityLinks since I know Jira and BitBucket are connected via an ApplicationLink. I’ve tried looking at different questions and examples that use EntityLinks but so far haven’t had any luck returning any data.

Is EntityLinks the right way to do this? Or is there another way of querying Jira data from a BitBucket plugin?

Versions
BitBucket 5.3.2
Jira 7.4.4
Atlassian SDK 6.3.4

Almost. You’ll want to use the ApplicationLinkService: https://docs.atlassian.com/applinks-api/3.2/com/atlassian/applinks/api/ApplicationLinkService.html

Then in it get the appropriate ApplicationLink (in your case I’m guessing that it’s going to be all of the Jira instances - so look at https://docs.atlassian.com/applinks-api/3.2/com/atlassian/applinks/api/ApplicationLinkService.html#getApplicationLinks(java.lang.Class) ).

One the ApplicationLink you’d call https://docs.atlassian.com/applinks-api/3.2/com/atlassian/applinks/api/ApplicationLink.html#createAuthenticatedRequestFactory() - that will then allow you to create authenticated requests to wherever the instance is.

One note though: Since you’re running on every git interaction - you’ll be very chatty - so make sure to cache the look ups: https://developer.atlassian.com/server/confluence/atlassian-cache-2-overview/ .

All of that said (Warning promo pitch ahead) - you could look into Wittified’s Javascript Hooks for Bitbucket Server since you can write some javascript code that interacts with Jira from Bitbucket Server (Note: I’m one of folks behind this app): https://marketplace.atlassian.com/plugins/com.wittified.stash.js-hooks/server/overview (Promo pitch over).

1 Like

Thank you for replying, really helpful!

I’ve been trying out the steps you provided but I’m now running into compilation issues when trying to use Response and Request from the com.atlassian.sal.api.net package. I was going to start a new topic on it as it might be a completely separate topic.

I’ll keep an eye out for the post either way :slight_smile: