是否可以直接与 Confluence 通信,以通过自定义 Jira 插件搜索页面/将页面添加到空间等?
我目前正在开发一个 Jira 插件,它在问题查看器中显示一个面板,但希望在 confluence 中搜索特定页面以显示指向它的链接(如果存在)。如果它不存在,我想要一个允许用户创建该页面的按钮。
我已经查看了 REST API,它看起来应该可以实现我想要的功能,但是我可以直接使用 JAVA 类进行交互吗?
它们之间的单点登录是否允许我从 JIRA 调用 Confluence 上的 REST 服务,而无需将身份验证放入 REST 调用中?
最佳答案
简而言之:
I have looked at the REST API and it looks like it should do what I want, but can I interact directly using the JAVA classes?
没有。没有可用的 java api 这么简单:
ConfluenceService.searchPage(String title)
ConfluenceService.createPage(String parent, String title)
Does the single sign on between them allow me to call a REST service on confluence from JIRA without putting authentication into the REST call?
是的。
更详细:
您可以使用的 java api 是 Application Link api和 SAL api ,特别是来自 com.atlassian.sal.api.net 的请求和响应包。
归根结底,您首先在 JIRA 中配置一个到 Confluence 实例的应用程序链接。然后,在您的自定义插件中,您可以使用应用程序链接 api 来检索 ApplicationLink 实例,例如:
ApplicationLink confluenceLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType.class)
之后,您可以使用此confluencelink来获取requestFactory:
ApplicationLinkRequestFactory requestFactory = confluenceLink.createAuthenticatedRequestFactory();
requestFactory 可以轻松地将 REST 请求发送到 Confluence 并处理响应。它还使用 JIRA 中应用程序链接的配置来负责身份验证。
有关更详细的示例,包括搜索 Confluence 页面,请查看 this tutorial .
根据您想要实现的目标,可能还值得查看 Structure和 Structure Pages附加组件。他们的目标是更紧密地集成 JIRA 和 Confluence,并提供一种用户友好的方式来在 JIRA 内的结构中显示 Confluence 页面并在 JIRA 内编辑这些页面。
关于JIRA 插件与 Confluence 通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37232348/