如何创建一个 Confluence 用户宏来划分 2 个 Jira 过滤器的大小

How to create a Confluence user macro that divides the size of 2 Jira filters

提问人:Margus 提问时间:2/9/2023 更新时间:3/10/2023 访问量:64

问:

我尝试的是:

## Macro title: totalBugs
## Macro has a body: Y
## Body processing: Rendered
## Output: Rendered
##
## Developed by: Margus Martsepp
## Date created: 06/02/2023
## Installed by: Margus Martsepp
## @param Search1:title=Search1|type=string|required=true|desc=Choose search 1
## @param Search2:title=Search2|type=string|required=true|desc=Choose search 2
#set($jiraUrl = "https://.../")
#set($proxyHost = "http://...")
#set($proxyPort = "8080")
#set($action = $helper.getActionContext())
#set($jira = $action.getApplicationContext().getComponent("jira"))
#if($jira)
  #error("Jira variable is not initialized, check if the Jira plugin is properly installed and configured")
#end

#set($result1 = $jira.search($paramSearch1, $jiraUrl, $proxyHost, $proxyPort))
#set($result2 = $jira.search($paramSearch2, $jiraUrl, $proxyHost, $proxyPort))

#if($result1)
  #error("Search 1 has returned no results, check the query and connection details")
#end
#if($result2)
  #error("Search 2 has returned no results, check the query and connection details")
#end
#if($result1.total == 0)
  #error("Search 1 has returned no results, division by zero is not possible")
#end
#if($result2.total == 0)
  #error("Search 2 has returned no results, division by zero is not possible")
#end

#set($count1 = $result1.total)
#set($count2 = $result2.total)
#if($count2 == 0)
#error("Search 2 has returned no results, division by zero is not possible")
#end
#set($result = $count1 / $count2 * 100)
#set($output = "Result of dividing search 1 count ($count1) by search 2 count ($count2) is: $result")
$output

与此类似,我尝试了getIssuesFromJqlSearch$jira.getIssuesFromJqlSearch($paramSearch1, 1000))

但在这两种情况下,这都导致了:

Result of dividing search 1 count ($count1) by search 2 count ($count2) is: $result

我是否忘记为 JIRA 服务配置某些内容,或者 API 的使用方式是否不同?

Confluence Apache 速度

评论


答:

0赞 Margus 3/10/2023 #1

事实证明,仅使用 VTL 模板几乎是不可能的。但是,通过使用 JavaScript,它就像发出 Rx 可观察请求一样简单。这里的复杂性在于,如果 Jira 和 Confluence 位于不同的服务器或 URL 上,则它是 CORS 请求。我已经设置了 OpenId 引用,但我必须修改配置以启用 CORS 并重新启动应用程序。