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了

相关推荐
神奇侠20241 天前
基于PaddleOCR对图片中的excel进行识别并转换成word(一)
python·word·excel·paddleocr
林枫依依1 天前
Unity 将Excel表格中的数据导入到Mysql数据表中
数据库·mysql·excel
CodeJourney.1 天前
基于DeepSeek与Excel的动态图表构建:技术融合与实践应用
数据库·人工智能·算法·excel
神奇侠20241 天前
基于PaddleOCR对图片中的excel进行识别并转换成word优化(二)
opencv·excel·paddleocr
xll_0071 天前
使用Python设置excel单元格的字体(font值)
开发语言·python·excel
inxunoffice1 天前
批量将多个 Excel 表格中的某张图片替换为新的图片
excel
林枫依依1 天前
Unity 创建、读取、改写Excel表格数据
unity·excel
杜大哥2 天前
wps打开的excel如何插入提示框?
excel·wps
HBR666_2 天前
vue3 excel文件导入
前端·excel
玥老师2 天前
Excel/WPS表格中图片链接转换成对应的实际图片
excel·wps