Как создать страницы в месте слияния, используя скрипт-бегун - PullRequest
0 голосов
/ 18 сентября 2018

Вся документация, которую я нашел в ScriptRunner и создании страниц в Confluence, предполагает, что вы делаете это из Jira, поэтому он добавляет ненужные шаги для аутентификации.Я хочу запустить скрипт в Confluence без ввода данных от Jira или внешней системы.

Вот код, который у меня был до сих пор, который зависает на authenticatedRequestFactory:

import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
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 groovy.json.JsonSlurper



def confluenceLink = getPrimaryConfluenceLink()
assert confluenceLink // must have a working app link set up

def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()




// set the page title - this should be unique in the space or page creation will fail
def pageTitle = "Teset Discussion"
def pageBody = """h3. Test

{quote}This is a quote{quote}

Yada yada, use this page to discuss the above...
"""

def params = [
        type: "page",
        title: pageTitle,
        space: [
                key: "COM" // set the space key - or calculate it from the project or something
        ],
        /* // if you want to specify create the page under another, do it like this:
         ancestors: [
             [
                 type: "page",
                 id: "14123220",
             ]
         ],*/
        body: [
                storage: [
                        value: pageBody,
                        representation: "wiki"
                ],
        ],
]


authenticatedRequestFactory
        .createRequest(Request.MethodType.POST, "rest/api/content")
        .addHeader("Content-Type", "application/json")
        .setRequestBody(new JsonBuilder(params).toString())
        .execute(new ResponseHandler<Response>() {
    @Override
    void handle(Response response) throws ResponseException {
        if(response.statusCode != HttpURLConnection.HTTP_OK) {
            throw new Exception(response.getResponseBodyAsString())
        }
        else {
            def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
        }
    }
})

Приведенный выше пример является урезанной версией из этой документации: https://scriptrunner.adaptavist.com/latest/jira/interacting-with-confluence-from-jira.html Оценителюбое направление о том, как просто создать страницу.

1 Ответ

0 голосов
/ 19 сентября 2018

Пример кода был предоставлен в следующей ветке Atlassian: https://community.developer.atlassian.com/t/how-to-create-a-confluence-page-with-scriptrunner-via-rest-api/23695 В нем рассматриваются способы создания страницы в Confluence без необходимости подключения к Jira.

...