Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.atlassian.sal.api.component.ComponentLocator
- import com.atlassian.confluence.pages.CommentManager
- import com.atlassian.confluence.pages.PageManager
- import com.atlassian.confluence.spaces.SpaceManager
- import com.atlassian.confluence.pages.Page
- import com.atlassian.confluence.user.UserAccessor
- import com.atlassian.sal.api.user.UserKey
- import com.atlassian.confluence.core.DefaultSaveContext
- import com.atlassian.confluence.core.SaveContext
- import com.atlassian.confluence.event.events.content.page.PageEvent
- import com.atlassian.applinks.api.ApplicationLinkService
- import com.atlassian.applinks.api.application.jira.JiraApplicationType
- import com.atlassian.sal.api.net.Response
- import com.atlassian.sal.api.net.ResponseException
- import com.atlassian.sal.api.net.ResponseHandler
- import com.onresolve.scriptrunner.runner.customisers.WithPlugin
- import groovy.json.JsonBuilder
- import groovy.json.JsonSlurper
- import org.apache.http.util.EntityUtils
- import org.jsoup.Jsoup
- import org.jsoup.nodes.Document
- import org.jsoup.nodes.Element
- import static com.atlassian.sal.api.net.Request.MethodType.POST
- import org.apache.log4j.Level
- import org.apache.log4j.Logger
- log = Logger.getLogger("com.test.Page")
- log.setLevel(Level.DEBUG)
- def pageManager = ComponentLocator.getComponent(PageManager)
- def entityUtils = ComponentLocator.getComponent(EntityUtils)
- def response = ComponentLocator.getComponent(Response)
- def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
- def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
- def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()
- def page = pageManager.getPage('OP','2019-10-09 Meeting notes')
- def text_page = page.getBodyAsString()
- def doc = Jsoup.parse(text_page)
- def element = doc.select("td")
- def result = element.collect {it.text()}
- for (int i = 0; i < result.size(); i = i + 6){
- def body = new JsonBuilder([
- fields: [
- project : [key: "QQ"],
- issuetype : [name: "Техническая консультация"],
- summary : result[ i+1],
- description: result[i+2],
- //assignee : [result[i+3]],
- //priority : [result[i+4]],
- //customfield_11801 : result[i+5],
- //remotelink: [globalId: "appId=5aac7244-e0d3-31df-a7f5-d93dce867807&pageId=10748184", application: {type: "com.atlassian.confluence"}, relationship:"Wiki Page", object:[url:"http://confluence-test-app.sands.local/pages/viewpage.action?pageId=10748184", title:"Wiki Page"]]
- ]
- ]).toString()
- def request = applicationLinkRequestFactory.createRequest(POST, "/rest/api/2/issue")
- .addHeader("Content-Type", "application/json")
- .setEntity(body)
- request.execute(new ResponseHandler<Response>() {
- @Override
- void handle(Response response) throws ResponseException {
- if (response.statusCode != 201) {
- log.error("Creating Jira issue failed: ${response.responseBodyAsString}")
- }
- }
- })
- def value = responce.getResponseBodyAsString()
- def s = entityUtils.toString()
- //def jsonSlurper = new JsonSlurper()
- //def issue = JsonSlurper.parseText(s)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement