如何使用 JIRA Cloud REST API 创建关于 jira 问题的内部评论

Sim*_*ick 3 groovy json jira jira-rest-api

关于如何对仅限内部的问题创建评论,确实很难找到明确的答案。

Sim*_*ick 7

JIRA Cloud REST API 文档指定以下架构,用于在创建或更新事件评论时设置评论属性

https://docs.atlassian.com/jira/REST/cloud/#api/2/issue/{issueIdOrKey}/comment-addComment

"properties": {
    "type": "array",
    "items": {
        "title": "Entity Property",
        "type": "object",
        "properties": {
            "key": {
                "type": "string"
            },
            "value": {}
        },
        "additionalProperties": false
    }
}
Run Code Online (Sandbox Code Playgroud)

要对内部问题发表评论(意味着只有服务台代理才能看到评论),您需要将键设置sd.public.comment为具有值{ "internal": true } ,可以通过在创建或更新 API 请求正文中传递以下 JSON 来实现该值。

{
    "properties": {
        "key": "sd.public.comment",
        "value": {
            "internal": true
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您还需要在请求上设置 Content-Type 标头。

Content-Type: application/json
Run Code Online (Sandbox Code Playgroud)

以下是使用 Groovy 脚本创建内部注释的示例 - Groovy 脚本是 ScriptRunner(一种流行的 JIRA 插件)使用的脚本语言

post("/rest/api/2/issue/${issue.id}/comment")
    .header("Content-Type", "application/json")
    .body([
        body: "This is the text which will appear in the comment",
        properties: [
            [key: "sd.public.comment", value: [ "internal": true ]]
        ]
    ]).asString()
Run Code Online (Sandbox Code Playgroud)

请注意,对象/JSON 映射将根据您使用的脚本语言或 HTTP 请求框架而有所不同。