首页 > 解决方案 > Jira 云 REST 创建问题和问题link

问题描述

我正在尝试使用 scriptrunner 同时从触发的问题中创建问题、问题链接和复制附件。
目前,下面的代码能够创建问题和附件,但我无法链接我创建的问题,有人处理过这种情况吗?

import org.apache.http.entity.ContentType;

def issueKey = issue.key
def result = get('/rest/api/2/issue/' + issueKey)
        .header('Content-Type', 'application/json')
        .asObject(Map)

def projectkey = "PILOTLV"
if (result.body.fields.customfield_10078.id == "10124"){
projectkey = "SPCLRQ"
} 

def issuetypekey = "10018"
def ticketno = result.body.fields.customfield_10060
if (result.body.fields.issuetype.id == "10015"){
issuetypekey = "10017"
ticketno = result.body.fields.customfield_10059
}

def description = result.body.fields.description
def summary = result.body.fields.summary
def sysname = result.body.fields.customfield_10078.id

logger.info(description)
logger.info(summary)
logger.info(sysname)
logger.info(ticketno)

// create issue 
def createReq = Unirest.post("/rest/api/2/issue")
        .header("Content-Type", "application/json")
        .body([
        fields: [
        summary : summary,
        description: description,
        customfield_10078: [
        id: sysname
                  ],
        customfield_10060: ticketno,
        project : [
        key: projectkey
                  ],
        issuetype : [
        id: issuetypekey
                    ]
                ],
        update: [
        issuelinks: [
            add: [
                type:[
                    name: "Blocks",
                    inward: "is blocked by",
                    outward: "blocks"
                    ],
                outwardIssue: [
                    key: issuekey
                    ]
                ]
            ]
        ]
              ])
        .asObject(Map)

assert createReq.status >= 200 && createReq.status < 300

def clonedIssue = createReq.body

// copy attachments

if (issue.fields.attachment) {
    issue.fields.attachment.collect { attachment ->
        def url = attachment.content as String
        url = url.substring(url.indexOf("/secure"))
        def fileBody = Unirest.get("${url}").asBinary().body
        def resp = Unirest.post("/rest/api/2/issue/${clonedIssue.id}/attachments")
                .header("X-Atlassian-Token", "no-check")
                .field("file", fileBody, ContentType.create(attachment['mimeType'] as String), attachment['filename'] as String)
                .asObject(List)
        assert resp.status >=200 && resp.status < 300
    }
}

还有一个小问题,我发现新问题上的附件名称不能显示汉字 https://community.atlassian.com/t5/Jira-questions/rest-api-3-issue-issue-key-attachments -upload-file-with-a/qaq-p/1070389\ 看起来我缺少库

标签: jirajira-rest-apiunirest-java

解决方案


推荐阅读