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了

相关推荐
云只上7 小时前
前端插件使用xlsx-populate,花样配置excel内容,根据坐添加标替换excel内容,修改颜色,合并单元格...。
excel
小哥山水之间8 小时前
在 Python 中操作 Excel 文件
开发语言·python·excel
blog_wanghao9 小时前
C#: 创建Excel文件并在Excel中写入数据库中的数据
数据库·c#·excel
游客52016 小时前
自动化办公|通过xlwings进行excel格式设置
python·自动化·excel
喝西瓜汁的兔叽Yan17 小时前
第三方库XLSX: 前端上传excel文件,并对excel文件内容做校验。
前端·excel·xlsx
刘_sy1 天前
使用EasyExcel和多线程实现高效数据导出
java·excel·easyexcel·批量导出excel
PowerBI学谦2 天前
Copilot:Excel中的Python高级分析来了
python·excel·copilot
E-iceblue3 天前
Python 合并 Excel 单元格
python·excel·合并
sszdzq3 天前
Excel 合并列数据
excel
prince_zxill3 天前
Excel中不用复杂公式根据指定X列的数值N复制整行数据N行简单方法
excel