I am writing a plugin in Bitbucket Server.
How can I connect to application links without using the REST API with Jira Server?
Is there a solution for this?
Take a look at this documentation as this might be helpful.
Ah sorry I got it backwards when reading. Try this documentation and let me know if that is helpful
Hi @umitdemirel.ozgenpls,
I believe you should be able to import the ApplicationLinkService
into your plugin and then use its API to retrieve the available JIRA ApplicationLink
. The ApplicationLink
will give you access to the authenticated request factory to query JIRA.
Hope that helps!
Cheers
Juan
Hi @umitdemirel.ozgenpls,
Could you provide a bit more context?
What do you mean itâs not running? Is the service not getting wired into your constructor? How are you defining the Spring bean? Is the merge check not being executed? How are you configuring it?
May I ask, what are you trying to achieve in your merge check?
Cheers
Juan Palacios
No one has any idea what âit did not workâ means. You need to show us what you mean. Are you seeing errors? Are you seeing bugs? What are you seeing?
Depending on what you are trying to achieve in your check this may be advisable or not. Youâll need to keep in mind that these checks will execute whenever a user opens a pull request so you donât want to have very heavy operations running that often. They will also execute when a user clicks the pull request Merge button and they will have to wait until the checks complete before the merge takes place and they get a result for the operation. So you donât want to have very long running operations in those checks.
Iâm not saying âdonât use themâ. I donât know what type of checks youâll be performing, so Iâm giving you context so you can decide whether itâs advisable or not.
That being said, in order to get your merge check to run youâll need to configure a couple of things. From the code youâve shared so far youâve mixed a couple of approaches together so Iâll try and get you going with one (the 100% Spring one).
Remove the @Inject
and @ComponentImport
annotations. Instead add @Component("myMergeCheck")
to the class and @Autowired
to the constructor.
Configure OSGi to import the ApplicationLinkService
for usage in your plugin. Create a file with the path src/main/resources/META-INF/spring/atlassian-plugins-component-imports.xml
and add:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:reference id="applicationLinkService" interface="com.atlassian.applinks.api.ApplicationLinkService"/>
</beans>
Configure spring to scan your classes by adding src/main/resources/META-INF/spring/atlassian-plugin-components.xml
with:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
default-autowire="autodetect">
<context:annotation-config/>
<context:component-scan base-package="com.atlassian.bitbucket.plugin.mymergecheck"/> <!-- THIS SHOULD BE THE BASE PACKAGE FOR YOUR PLUGIN CLASSES -->
</beans>
In src/main/resources/atlassian-plugin.xml
make sure your merge check is added like this:
<repository-merge-check key="my-merge-check-key" configurable="false"
class="bean:myMergeCheck" />
With that done (and assuming the rest of your plugin configuration is correct) you will have:
- Imported the
ApplicationLinkService
into your plugin - Configured your merge check as a Spring bean with the
ApplicationLinkService
as a dependency - Configured the merge check Spring bean as a repository merge check available to the system
Hope this helped out.
Regards
Juan