jira流转issue条目状态transitions的rest实用脚本,issue状态改变调整

官方文档链接地址:

POST

Transition issue

Performs an issue transition and, if the transition has a screen, updates the fields from the transition screen.

sortByCategory To update the fields on the transition screen, specify the fields in the fields or update parameters in the request body. Get details about the fields using Get transitions with the transitions.fields expand.

This operation can be accessed anonymously.

Permissions required:

Connect app scope required : WRITE

OAuth 2.0 scopes required:

Classic RECOMMENDED:write:jira-work

Granular :write:issue:jira, write:issue.property:jira

实用json请求脚本如下:

{
  "transition": {
    "id": "%s"
  },
  "fields": {
    "resolution": {
      "name": "Fixed"
    }
  }
}

id参数是通过transitions api来获取的,

可以参考jira获取issue条目transitions id,以用来进行流转实用脚本_锐湃的博客-CSDN博客

示例代码如下:

        // The payload definition using the Jackson library
        JsonNodeFactory jnf = JsonNodeFactory.instance;
        ObjectNode payload = jnf.objectNode();
        {
            ObjectNode transition = payload.putObject("transition");
            {
                transition.put("id", "81");//"91"
            }
        }

// Connect Jackson ObjectMapper to Unirest
        Unirest.setObjectMapper(new ObjectMapper() {
            private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper
                    = new com.fasterxml.jackson.databind.ObjectMapper();

            @Override
            public <T> T readValue(String value, Class<T> valueType) {
                try {
                    return jacksonObjectMapper.readValue(value, valueType);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public String writeValue(Object value) {
                println("writeValue=====" + value);
                try {
                    return jacksonObjectMapper.writeValueAsString(value);
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }
            }
        });

// This code sample uses the  'Unirest' library:
// http://unirest.io/java.html
                                                         //"https://your-domain.atlassian.net/rest/api/2/issue/issueIdOrKey/transitions"
        HttpResponse<JsonNode> response = Unirest.post("https://jira.example.com/rest/api/2/issue/TEST-7/transitions")
                .basicAuth("User", "TOKEN")
                .header("Accept", "application/json")
                .header("Content-Type", "application/json")
                .body(payload)
                .asJson();

        System.out.println(response.getBody());

本次上送的请求json如下

{
  "transition": {
    "id": "81"
  }
}

执行成功后返回null打印出来,如果没有成功会返回失败的原因

执行成功后会发现issue已关闭

比如现在有一个需求要把TEST项目的处于待验证(已解决)状态的issue关闭;

对于这个需求可以分为三步:

1、通过search issue条目rest api获取到当前处于已解决待验证状态的issue,并把issueKeyOrId收集起来;

可以参考:jira搜索search issue条目rest实用脚本_锐湃的博客-CSDN博客

2、通过issueKeyOrId用transitions rest api获取到transitions id;

可以参考jira获取issue条目transitions id,以用来进行流转实用脚本_锐湃的博客-CSDN博客

3、用上一步获取的的id作为参数调用 文章开头的rest api请求就可以关闭流转issue了

相关推荐
刘_sy7 小时前
使用EasyExcel和多线程实现高效数据导出
java·excel·easyexcel·批量导出excel
PowerBI学谦12 小时前
Copilot:Excel中的Python高级分析来了
python·excel·copilot
E-iceblue2 天前
Python 合并 Excel 单元格
python·excel·合并
sszdzq2 天前
Excel 合并列数据
excel
prince_zxill2 天前
Excel中不用复杂公式根据指定X列的数值N复制整行数据N行简单方法
excel
VBAMatrix3 天前
DeepSeek操作Excel,实现图表自动化生成
运维·自动化·excel·wps·deepseek
一醉千秋3 天前
excel中单元格字符串提取数字累加
excel
VB.Net3 天前
19.4.9 数据库方式操作Excel
数据库·c#·excel
真就死难3 天前
CSV格式和普通EXCEL格式文件的区别
linux·excel
朵朵zeng3 天前
Excel文件的读取
python·excel