jira搜索search issue条目rest实用脚本

官方文档链接地址:

The Jira Cloud platform REST API

实用json请求脚本如下:

复制代码
{

                "fields": [
                  "summary",
                  "status"
                ],
                "jql": "project = abc AND summary ~ '【%s】【coverity】' AND component=Coverity",
                "maxResults": 1000,
                "startAt": 0
}

jql字段就是表达式,类似于sql语句里的where条件设定语句,多个条件用"AND"连接

代码示例如下:

复制代码
public static void searchIssueXTKFDT() throws UnirestException {
        JsonNodeFactory jnf = JsonNodeFactory.instance;
        ObjectNode payload = jnf.objectNode();
        {
            ArrayNode fields = payload.putArray("fields");
            fields.add("summary");
            fields.add("status");
            //fields.add("assignee");
            payload.put("jql", "project = TEST");
            payload.put("maxResults", 100);
            payload.put("startAt", 0);
        }

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

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

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


        //"https://your-domain.atlassian.net/rest/api/2/search"
        HttpResponse<JsonNode> response = Unirest.post("https://devops-jira.example.com/rest/api/2/search")
                .basicAuth("USER", "TOKEN")
                .header("Accept", "application/json")
                .header("Content-Type", "application/json")
                .body(payload)
                .asJson();

        JsonNode body = response.getBody();
        JSONObject json = body.getObject();
        JSONArray array = json.getJSONArray("issues");
        int length = array.length();
        System.out.println("length = " + length);
        ArrayList<String> status = new ArrayList<>();
        for (int i = 0; i < length; i ++){
            JSONObject object = array.getJSONObject(i);
            String key = object.getString("key");
            String id = object.getJSONObject("fields")
                    .getJSONObject("status")
                    .getString("id");
            status.add(key + "=" + id);
        }
        System.out.println("status = " + status);
        System.out.println(body);
    }

返回结果如下:

复制代码
{
    "expand": "schema,names",
    "total": 8,
    "maxResults": 100,
    "issues": [
        {
            "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            "self": "https://devops-jira.example.com/rest/api/2/issue/867674",
            "id": "867674",
            "fields": {
                "summary": "a test of the crash Main order flow broken",
                "status": {
                    "name": "等待验证",
                    "self": "https://devops-jira.example.com/rest/api/2/status/11601",
                    "description": "",
                    "iconUrl": "https://devops-jira.example.com/images/icons/statuses/generic.png",
                    "id": "11601",
                    "statusCategory": {
                        "colorName": "yellow",
                        "name": "In Progress",
                        "self": "https://devops-jira.example.com/rest/api/2/statuscategory/4",
                        "id": 4,
                        "key": "indeterminate"
                    }
                }
            },
            "key": "TEST-10"
        },
        {
            "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            "self": "https://devops-jira.example.com/rest/api/2/issue/861855",
            "id": "861855",
            "fields": {
                "summary": "fawtwa4twa这是一个测试",
                "status": {
                    "name": "取消",
                    "self": "https://devops-jira.example.com/rest/api/2/status/10124",
                    "description": "",
                    "iconUrl": "https://devops-jira.example.com/images/icons/statuses/generic.png",
                    "id": "10124",
                    "statusCategory": {
                        "colorName": "green",
                        "name": "Done",
                        "self": "https://devops-jira.example.com/rest/api/2/statuscategory/3",
                        "id": 3,
                        "key": "done"
                    }
                }
            },
            "key": "TEST-9"
        },
        {
            "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            "self": "https://devops-jira.example.com/rest/api/2/issue/861924",
            "id": "861924",
            "fields": {
                "summary": "a test of the crash Main order flow broken",
                "status": {
                    "name": "激活",
                    "self": "https://devops-jira.example.com/rest/api/2/status/10354",
                    "description": "新发现的缺陷",
                    "iconUrl": "https://devops-jira.example.com/images/icons/statuses/generic.png",
                    "id": "10354",
                    "statusCategory": {
                        "colorName": "blue-gray",
                        "name": "To Do",
                        "self": "https://devops-jira.example.com/rest/api/2/statuscategory/2",
                        "id": 2,
                        "key": "new"
                    }
                }
            },
            "key": "TEST-8"
        },
        {
            "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            "self": "https://devops-jira.example.com/rest/api/2/issue/861835",
            "id": "861835",
            "fields": {
                "summary": "wewrwr",
                "status": {
                    "name": "重新打开",
                    "self": "https://devops-jira.example.com/rest/api/2/status/10359",
                    "description": "问题未彻底修复",
                    "iconUrl": "https://devops-jira.example.com/images/icons/statuses/generic.png",
                    "id": "10359",
                    "statusCategory": {
                        "colorName": "yellow",
                        "name": "In Progress",
                        "self": "https://devops-jira.example.com/rest/api/2/statuscategory/4",
                        "id": 4,
                        "key": "indeterminate"
                    }
                }
            },
            "key": "TEST-7"
        },
        {
            "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            "self": "https://devops-jira.example.com/rest/api/2/issue/861664",
            "id": "861664",
            "fields": {
                "summary": "a test of the crash Main order flow broken",
                "status": {
                    "name": "需求规划",
                    "self": "https://devops-jira.example.com/rest/api/2/status/10500",
                    "description": "",
                    "iconUrl": "https://devops-jira.example.com/images/icons/statuses/generic.png",
                    "id": "10500",
                    "statusCategory": {
                        "colorName": "blue-gray",
                        "name": "To Do",
                        "self": "https://devops-jira.example.com/rest/api/2/statuscategory/2",
                        "id": 2,
                        "key": "new"
                    }
                }
            },
            "key": "TEST-6"
        },
        {
            "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            "self": "https://devops-jira.example.com/rest/api/2/issue/861719",
            "id": "861719",
            "fields": {
                "summary": "a test of the crash Main order flow broken",
                "status": {
                    "name": "需求规划",
                    "self": "https://devops-jira.example.com/rest/api/2/status/10500",
                    "description": "",
                    "iconUrl": "https://devops-jira.example.com/images/icons/statuses/generic.png",
                    "id": "10500",
                    "statusCategory": {
                        "colorName": "blue-gray",
                        "name": "To Do",
                        "self": "https://devops-jira.example.com/rest/api/2/statuscategory/2",
                        "id": 2,
                        "key": "new"
                    }
                }
            },
            "key": "TEST-5"
        },
        {
            "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            "self": "https://devops-jira.example.com/rest/api/2/issue/861243",
            "id": "861243",
            "fields": {
                "summary": "这是一个测试",
                "status": {
                    "name": "需求规划",
                    "self": "https://devops-jira.example.com/rest/api/2/status/10500",
                    "description": "",
                    "iconUrl": "https://devops-jira.example.com/images/icons/statuses/generic.png",
                    "id": "10500",
                    "statusCategory": {
                        "colorName": "blue-gray",
                        "name": "To Do",
                        "self": "https://devops-jira.example.com/rest/api/2/statuscategory/2",
                        "id": 2,
                        "key": "new"
                    }
                }
            },
            "key": "TEST-2"
        },
        {
            "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            "self": "https://devops-jira.example.com/rest/api/2/issue/860777",
            "id": "860777",
            "fields": {
                "summary": "testtesttest",
                "status": {
                    "name": "开发处理中",
                    "self": "https://devops-jira.example.com/rest/api/2/status/10355",
                    "description": "",
                    "iconUrl": "https://devops-jira.example.com/images/icons/statuses/generic.png",
                    "id": "10355",
                    "statusCategory": {
                        "colorName": "yellow",
                        "name": "In Progress",
                        "self": "https://devops-jira.example.com/rest/api/2/statuscategory/4",
                        "id": 4,
                        "key": "indeterminate"
                    }
                }
            },
            "key": "TEST-1"
        }
    ],
    "startAt": 0
}

在此做个笔记

相关推荐
放风铃的兔子2 小时前
我把 5 个 Python bug 投进 CubeSandbox 当沙盘 —— 从 envd 协议反编译到一键 RED→GREEN
bug·issue
●VON6 天前
AtomGit Flutter鸿蒙客户端:Issue管理
flutter·华为·架构·harmonyos·鸿蒙·issue
海岸线科技7 天前
飞书 Issue/8D Agent:从“被动救火”到“主动免疫”的实测报告
汽车·飞书·制造·issue
武子康11 天前
调查研究-151 Slack vs Jira:区别、使用指南与团队选择方法
人工智能·科技·深度学习·ai·职场和发展·jira·slack
猴哥聊项目管理13 天前
研发管理常用的工具链有哪些?zentao/Jira/Confluence/Trello各有什么特殊点?
敏捷开发·jira·任务管理·研发工具选型·研发管理工具·研发协同·开源研发工具
程序员的程16 天前
从一个 issue 到阮一峰周刊推荐:stock-sdk 的开源成长记
开源·issue
Loli_Wolf18 天前
AI 编码 Agent 的工程实践:Issue 到 PR 的自动化不是魔法
人工智能·自动化·issue
小a彤22 天前
ops-cv 计算机视觉算子库:YOLOv5 在昇腾NPU上的正确打开方式
issue·cann
14年ABAP码农23 天前
Chinese Word Issue in attached PDF of Email
issue
郑..方..醒1 个月前
codex配置MCP连接并修改wiki、jira、数据库、观测云日志详细教程
ai编程·jira