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了

相关推荐
爱代码的小黄人16 小时前
Excel VLOOKUP函数使用详解:原理、格式、常见错误与解决方案
excel
YouYOUyouFairy17 小时前
EXCEL动态表格
excel
Maruko31018 小时前
Java 实现excel大批量导出
excel·poi
忧郁的蛋~18 小时前
HTML表格导出为Excel文件的实现方案
前端·html·excel
不坑老师1 天前
利用不坑盒子的Copilot,快速排值班表
microsoft·word·powerpoint·excel·copilot·wps
开开心心就好1 天前
批量PDF转换工具,一键转换Word Excel
开发语言·前端·学习·pdf·电脑·word·excel
Fireworkitte2 天前
Apache POI 详解 - Java 操作 Excel/Word/PPT
java·apache·excel
Prodigy_kyw2 天前
VBA初学3----实战(VBA实现Excel转csv)
excel·vba·csv
红衣女妖仙2 天前
JXLS 库导出复杂 Excel
java·excel·jxls·java 导出 excel
吃我两拳2 天前
EasyExcel停止当前Sheet的读取,且不影响主线程及其他Sheet读取的方法
excel