jira - 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\ 看起来我缺少库
解决方案
推荐阅读
- css - 如何让我的自定义光标在 create-react-app 中工作?
- ssl - 启用 SSL 的 Cloudflare 代理如何连接到非 SSL 端点?
- r - 如何获得lme4混合模型中随机变量的p值?
- python - Python数组元素赋值
- r - R Markdown:导入 R 脚本对象
- c++ - 了解每月第一天函数的代码
- git - 如何从另一个仓库移动多个目录并保留 git log 目录行为?
- swift - 定时器的替代品
- visual-studio-code - 在 Visual Code (mac) 中,有没有办法从片段的第二个占位符开始?
- python - 让matplotlib的ylabel垂直显示CJK文本