public static JSONArray getJiraProjects() {
//httpClient 自己封装的http接口调用
HttpClientResponse clientResponse = httpClient("get", "http://you jira address:port/rest/api/2/project", "");
if (clientResponse != null) {
logger.info("获取jira上project成功");
//已json数组的方式返回
return JSONArray.fromObject(clientResponse.getResponseBody());
}
return null;
}
//url 可使用参数如下expand扩充字段、recent返回的个数、properties返回的属性//http://jira.timevale.cn:8081/rest/api/2/project?expand=projectKeys,description,url,lead&recent=2&properties=key,id
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
,
//返回的数据结构如下,其中id和key会在后面的api中使用,需要保存[
{
"expand": "description,lead,url,projectKeys",
"self": "http://you jira address:port/rest/api/2/project/12345",
"id": "12345",//后续需要使用
"key": "AI",//后续需要使用
"name": "AI项目组",
"avatarUrls": {
"48x48": "http://you jira address:port/secure/projectavatar?avatarId=10324",
"24x24": "http://you jira address:port/secure/projectavatar?size=small&avatarId=10324",
"16x16": "http://you jira address:port/secure/projectavatar?size=xsmall&avatarId=10324",
"32x32": "http://you jira address:port/secure/projectavatar?size=medium&avatarId=10324"
},
"projectTypeKey": "software"
}]
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
,
//入参projectKey是步骤一中返回的id或者key
public static String getBoardId(String projectKey) {
String boarId = "";
HttpClientResponse boardResponse = httpClient("get", "http://you jira address:port/rest/agile/1.0/board?projectKeyOrId=" + projectKey, "");
if (boardResponse != null && "200".equals(boardResponse.getStateCode())
&& boardResponse.getResponseBody() != null) {
JSONObject jsonObject = JSONObject.fromObject(boardResponse.getResponseBody().toString());
//获取项目看板数组
JSONArray boardArray = jsonObject.getJSONArray("values");
if (boardArray != null && boardArray.size() > 0) {
for (int i = 0; i < boardArray.size(); i++) {
//默认使用项目名称+ board作为项目看板
JSONObject object = boardArray.getJSONObject(i);
if ((projectKey + " board").equals(object.getString("name")) || (projectKey + " Board").equals(object.getString("name"))) {
//返回看板ID
boarId = object.getString("id");
}
}
//没有满足要求的,设置第一个
if (StringUtils.isBlank(boarId)) {
boarId = boardArray.getJSONObject(0).getString("id");
}
}
}
return boarId;
}
//URL 中可使用参数startAt表示开始的位置、maxResults表示返回的数量
//http://you jira address:port/rest/agile/1.0/board?projectKeyOrId={projectKeyOrId}&startAt=1&maxResults=1
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
,
//返回结果如下,其中的id在获取sprint时需要使用,需要保存{
"maxResults": 50,
"startAt": 0,
"isLast": true,
"values": [
{
"id": num1,//后续需要使用
"self": "http://you jira address:port/rest/agile/1.0/board/num1",
"name": "测试",
"type": "kanban"
},
{
"id": num2,
"self": "http://you jira address:port/rest/agile/1.0/board/num2",
"name": "医签宝",
"type": "scrum"
}
]}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
,
//入参boardId就是第二步中获取的idpublic static List getSpring(String boardId) {
List result = new ArrayList<>();
HttpClientResponse boardResponse = httpClient("get", "http://you jira address:port/rest/agile/1.0/board/" + boardId + "/sprint?state=future,active", "");
if (boardResponse != null && "200".equals(boardResponse.getStateCode())
&& boardResponse.getResponseBody() != null) {
JSONObject jsonObject = JSONObject.fromObject(boardResponse.getResponseBody().toString());
//获取Spring
JSONArray boardArray = jsonObject.getJSONArray("values");
if (boardArray != null && boardArray.size() > 0) {
for (int i = 0; i < boardArray.size(); i++) {
//自己封装的对象
TmsJiraSpringModel springModel = new TmsJiraSpringModel();
JSONObject object = boardArray.getJSONObject(i);
if (object != null) {
springModel.setSpringId(object.getString("id"));
springModel.setSpringName(object.getString("name"));
result.add(springModel);
}
}
}
}
return result;
}//url 可使用参数startAt表示开始的位置、maxResults表示返回的数量、state表示sprint的状态//http://you jira address:port/rest/agile/1.0/board/{boardId}/sprint?state=future,active&startAt=1&maxResults=1
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
,
//返回结果如下, 其中id为sprint id后面会使用{
"maxResults": 2,
"startAt": 1,
"isLast": false,
"values": [
{
"id": num1,//后续需要使用
"self": "http://you jira address:port/rest/agile/1.0/sprint/num1",
"state": "active",
"name": "【智能人事】一期项目",
"startDate": "2020-12-07T14:10:58.582+08:00",
"endDate": "2021-01-15T02:10:00.000+08:00",
"originBoardId": xxx },
{
"id": num2,
"self": "http://you jira address:port/rest/agile/1.0/sprint/num2",
"state": "active",
"name": "企业合同权限迭代",
"startDate": "2020-12-16T10:11:24.631+08:00",
"endDate": "2020-12-29T10:11:00.000+08:00",
"originBoardId": xxx }
]}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.