团队的成员碰到一个问题,使用JIRA建立多个有关联性的任务时,过于耗时。所以花了3天时间,间断地看了一下Jira官方文档和网上的资料。下面总结一下Jira API的使用。
Jira develop 文档中提到了其对rest风格api的支持,同时也支持SOAP的调用。我们采用 Jira rest API的方式进行调用,链接中有各种调用方式,可以细细看一下。
首先思考一下我们要做什么,可以归纳为以下几点:
private JiraClient getJiraClient() {
if (null == this.jiraClient) {
Properties prop = PropertiesReader.loadProperties();
String url = prop.getProperty("jira.connection.url");
String username = prop.getProperty("jira.connection.username");
String password = prop.getProperty("jira.connection.password");
jiraClient = new JiraClient(url, new BasicCredentials(username, password));
}
return jiraClient;
}连接后就可以读取jira中的项目信息了,比如获取issue信息Issue issue = this.getJiraClient().getIssue(key.trim());获取project信息
this.getJiraClient().getProjects();还有此次工具中的重点,创建issue
Issue parentIssue = this.getJiraClient().getIssue(vo.getParentIssueKey());
//2. create develop task
if (null != vo.getDevelopers() && vo.getDevelopers().length != 0) {
for (String dev : vo.getDevelopers()) {
Issue newIssue = this.getJiraClient().createIssue(project, issueType)
.field(Field.SUMMARY, devMap.get(dev) + parentIssue.getSummary())
.field(Field.PRIORITY, Field.valueById("3"))
.field(Field.ASSIGNEE, dev)
.field(Field.FIX_VERSIONS, versions)
.execute();
parentIssue.link(newIssue.getKey(), "包含");
newIssues.add(newIssue);
}
}$("#jira_table").jqGrid({
datatype: "local",
height: 500,
weight: 900,
colNames: ['Jira#','Developers', 'Qas'],
colModel : [
{
name : 'issueKey',
index : 'issueKey',
width : 100,
editable : true,
edittype : 'text'
},
{
name : 'developers',
index : 'developers',
width : 400,
editable : true,
edittype : 'custom',
editoptions : {
custom_element : function(value,
options) {
var comp = "<div id=\""
+ options.id
+ "\" style=\"white-space:normal;\" >"
+ "<input type=\"checkbox\" name=\"user\" value=\"1\"/>1"
+ "<input type=\"checkbox\" name=\"user\" value=\"2\" />2"
+ "<input type=\"checkbox\" name=\"user\" value=\"3\" />3"
+ "<input type=\"checkbox\" name=\"user\" value=\"4\" />4"
+ "<input type=\"checkbox\" name=\"user\" value=\"5\" />5"
+ "</div>";
return comp;
},
custom_value : function(elem,
operation, value) {
if (operation === 'get') {
var id = elem.attr("id");
var qas = "";
$("#" + id + " input").each(function() {
if($(this).is(":checked")){
qas = qas + $(this).val()+ ",";
}
});
qas = crudHelper.formatSliptStr(qas,",");
elem.val(qas);
return elem.val();
} else if (operation === 'set') {
var id = elem.attr("id");
var qas = "";
$("#" + id + " input").each(function() {
if($(this).is(":checked")){
qas = qas + $(this).val()+ ",";
}
});
qas = crudHelper.formatSliptStr(qas,",");
elem.val(qas);
}
}
}
},
{
name : 'qas',
index : 'qas',
width : 400,
editable : true,
edittype : 'custom',
editoptions : {
custom_element : function(value,
options) {
var comp = "<div id=\""
+ options.id
+ "\" style=\"white-space:normal;\" >"
+ "<input type=\"checkbox\" name=\"user\" value=\"6\"/>6"
+ "<input type=\"checkbox\" name=\"user\" value=\"7\" />7</div>";
return comp;
},
custom_value : function(elem,
operation, value) {
if (operation === 'get') {
var id = elem.attr("id");
var qas = "";
$("#" + id + " input").each(function() {
if($(this).is(":checked")){
qas = qas + $(this).val()+ ",";
}
});
elem.val(qas);
qas = crudHelper.formatSliptStr(qas,",");
return elem.val();
} else if (operation === 'set') {
var id = elem.attr("id");
var qas = "";
$("#" + id + " input").each(function() {
if($(this).is(":checked")){
qas = qas + $(this).val()+ ",";
}
});
qas = crudHelper.formatSliptStr(qas,",");
elem.val(qas);
}
}
}
}
],
multiselect: true,
caption: "创建Jira任务",
ondblClickRow: function(id){
$('#jira_table').jqGrid('editRow', id, {
keys : true,
url : 'clientArray',
restoreAfterError : true
});
}
});这里主要是为了给多个人创建任务,提供了一个简单的多选支持框,效果图明天补上。原文地址:http://blog.csdn.net/paristao/article/details/42746647