我有一个要求,当用户单击Confluence页面中的“发布”按钮时,需要触发一个外部API(发布端点),我可以在其中将Confluence数据保存在外部DB中。
答案 0 :(得分:0)
看看Event Listener module和How to build an Event Listener。基本上,您将创建一个捕获com.atlassian.confluence.event.events.content.page.PageEvent的插件。就您而言,您可以使用go test -bench=. -benchtime 100x
或PageCreateEvent
。这是针对Confluence Server的。至于Confluence Cloud,它可能是用JavaScript之类的。
答案 1 :(得分:0)
如果您不想为其开发插件, 那么我建议使用插件adaptavist scriprunner:
这是完成此任务的最简单方法(尽管不是免费的!)
他们网页上的示例:
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.jira.JiraApplicationType
import com.atlassian.confluence.event.events.space.SpaceCreateEvent
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler
import groovy.json.JsonBuilder
import
static com.atlassian.sal.api.net.Request.MethodType.POST
def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()
def event = event as SpaceCreateEvent
def space = event.space
def input = new JsonBuilder([
projectTypeKey : "business",
projectTemplateKey: "com.atlassian.jira-core-project-templates:jira-core-task-management",
name : space.name,
key : space.key,
lead : event.space.creator.name,
]).toString()
def request = applicationLinkRequestFactory.createRequest(POST, "/rest/api/2/project")
.addHeader("Content-Type", "application/json")
.setEntity(input)
request.execute(new ResponseHandler<Response>() {
@Override
void handle(Response response) throws ResponseException {
if (response.statusCode != 201) {
log.error("Creating jira project failed: ${response.responseBodyAsString}")
}
}
})