JIRA API

Everything about Jira api operation

搜索

JIRA 获取查询语句

https://community.atlassian.com/t5/Jira-questions/How-do-I-retrieve-issues-of-specific-status-with-JQL/qaq-p/540468

An easy way to get the proper encoding is to

  1. build your search in JIRA first
  2. When you have the results you want, click the Views button in Issue Navigator
  3. Right-click the XML link and copy the link address. It has all the proper formatting already.
  4. Paste everything that comes after ‘jqlQuery=’ into your code and add your variables and such.

https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

排序逻辑

按照问题id大小排序, 类似project = projectKey AND statusCategory = Done AND issuetype in (线上缺陷, Bug) ORDER BY issuekey DESC。其中的 issuekey为多个可排序的自定义字段,可以从/rest/api/2/field查看到哪些字段可参与排序,例如resolutiondate解决时间排序

jql高级搜索apijql: Jira Query Language——待实践

其他操作

创建issue

必选项:summary、description、issuetype、reporter 可选项:assignee、labels

https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-post

项目实例: https://bitbucket.org/atlassian/atlassian-connect-spring-boot/src/master/README.md

Basic 验证方式: https://developer.atlassian.com/server/jira/platform/basic-authentication 需要对用户名和密码做Base64转码, 例如 fred:fred转码为ZnJlZDpmcmVk

curl -H "Authorization: Basic ZnJlZDpmcmVk" -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/createmeta

Basic 验证下的API调研 https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/

修改issue状态

先查询JIRA下对应的transition的定义 https://developer.atlassian.com/cloud/jira/platform/rest/v3/?#api-rest-api-3-issue-issueIdOrKey-transitions-get

GET /rest/api/3/issue/{issueIdOrKey}/transitions

根据查询到的transitions进行操作 https://developer.atlassian.com/cloud/jira/platform/rest/v3/?#api-rest-api-3-issue-issueIdOrKey-transitions-post

ObjectNode payload = jnf.objectNode();
ObjectNode transition = payload.putObject("transition");
 transition.put("id", "401"); 
HttpResponse<JsonNode> response = Unirest.post(String.format("http://project.jira-corp.com/rest/api/2/issue/%s/transitions", id))
                    .basicAuth("user", "password")
                    .header("Accept", "application/json")
                    .header("Content-Type", "application/json")
                    .body(payload)
                    .asJson();
 
comments powered by Disqus