Forum Discussion
nicktulett
13 years agoContributor
So, rather than just complain, I've been playing around with a JScript in TestComplete to talk to the JIRA JSON-RPC API
So here are some routines, culminating in creating an issue.
I apologise for all the callbacks, but that's the nature of the beast.
(The JSON unit contains the text of Crockford's json2.js script)
Now all I need to do is parse the log at the end of a run and send it through as the new bug description...
function JIRA_POST(message, cb) {
var baseURL = "http://10.15.10.81:8181/rpc/json-rpc/jirasoapservice-v2",
XmlHttpRequest = Sys["OleObject"]("MSXML2.XMLHTTP.3.0");
XmlHttpRequest.open("POST", baseURL, false);
XmlHttpRequest.setRequestHeader("Content-Type","application/json");
XmlHttpRequest.onreadystatechange = function () {
if (XmlHttpRequest.readyState === 4) {
cb(JSON.JSON.parse(XmlHttpRequest.responseText));
XmlHttpRequest = null;
}
};
XmlHttpRequest.send(message);
}
function JIRA_LOGIN(cb) {
var login = JIRA_POST('{"jsonrpc": "2.0", "method": "login", "params": ["jiraadmin", "JIRAadmin"], "id": "12345"}', function (login) {
Log.Message(login.result);
cb && cb(login);
});
}
function JIRA_SYSINFO(cb) {
JIRA_LOGIN(function (login) {
JIRA_POST('{"jsonrpc": "2.0", "method": "getServerInfo", "params": ["' + login.result + '"], "id": "12345"}', function (sysinfo) {
cb && cb(sysinfo);
});
});
}
function TEST_JIRA_SYSINFO() {
JIRA_SYSINFO(function (sysinfo) {
Log.Message(sysinfo.result.version);
});
}
function JIRA_GETISSUE(issue, cb) {
JIRA_LOGIN(function (login) {
JIRA_POST('{"jsonrpc": "2.0", "method": "getIssue", "params": ["' + login.result + '", "' + issue + '"], "id": "12345"}', function (sysinfo) {
cb && cb(sysinfo);
});
});
}
function TEST_JIRA_GETISSUE() {
JIRA_GETISSUE("EVAL-1", function (sysinfo) {
Log.Message(sysinfo.result.description);
});
}
function JIRA_CREATEISSUE(issueDetails, cb) {
JIRA_LOGIN(function (login) {
var newIssue = {
"jsonrpc": "2.0",
"method": "createIssue",
"params": [login.result, issueDetails],
"id": "12345"};
JIRA_POST(JSON.JSON.stringify(newIssue), function (issueInfo) {
cb && cb(issueInfo);
});
});
}
function TEST_JIRA_CREATEISSUE() {
var newIssueDetails = {
"summary": "Another bug from TC",
"type": "1",
"description": "I am still surprised that this works",
"project": "EVAL"
}
JIRA_CREATEISSUE(newIssueDetails, function (issueInfo) {
Log.Message(issueInfo.result.key);
});
}
So here are some routines, culminating in creating an issue.
I apologise for all the callbacks, but that's the nature of the beast.
(The JSON unit contains the text of Crockford's json2.js script)
Now all I need to do is parse the log at the end of a run and send it through as the new bug description...
function JIRA_POST(message, cb) {
var baseURL = "http://10.15.10.81:8181/rpc/json-rpc/jirasoapservice-v2",
XmlHttpRequest = Sys["OleObject"]("MSXML2.XMLHTTP.3.0");
XmlHttpRequest.open("POST", baseURL, false);
XmlHttpRequest.setRequestHeader("Content-Type","application/json");
XmlHttpRequest.onreadystatechange = function () {
if (XmlHttpRequest.readyState === 4) {
cb(JSON.JSON.parse(XmlHttpRequest.responseText));
XmlHttpRequest = null;
}
};
XmlHttpRequest.send(message);
}
function JIRA_LOGIN(cb) {
var login = JIRA_POST('{"jsonrpc": "2.0", "method": "login", "params": ["jiraadmin", "JIRAadmin"], "id": "12345"}', function (login) {
Log.Message(login.result);
cb && cb(login);
});
}
function JIRA_SYSINFO(cb) {
JIRA_LOGIN(function (login) {
JIRA_POST('{"jsonrpc": "2.0", "method": "getServerInfo", "params": ["' + login.result + '"], "id": "12345"}', function (sysinfo) {
cb && cb(sysinfo);
});
});
}
function TEST_JIRA_SYSINFO() {
JIRA_SYSINFO(function (sysinfo) {
Log.Message(sysinfo.result.version);
});
}
function JIRA_GETISSUE(issue, cb) {
JIRA_LOGIN(function (login) {
JIRA_POST('{"jsonrpc": "2.0", "method": "getIssue", "params": ["' + login.result + '", "' + issue + '"], "id": "12345"}', function (sysinfo) {
cb && cb(sysinfo);
});
});
}
function TEST_JIRA_GETISSUE() {
JIRA_GETISSUE("EVAL-1", function (sysinfo) {
Log.Message(sysinfo.result.description);
});
}
function JIRA_CREATEISSUE(issueDetails, cb) {
JIRA_LOGIN(function (login) {
var newIssue = {
"jsonrpc": "2.0",
"method": "createIssue",
"params": [login.result, issueDetails],
"id": "12345"};
JIRA_POST(JSON.JSON.stringify(newIssue), function (issueInfo) {
cb && cb(issueInfo);
});
});
}
function TEST_JIRA_CREATEISSUE() {
var newIssueDetails = {
"summary": "Another bug from TC",
"type": "1",
"description": "I am still surprised that this works",
"project": "EVAL"
}
JIRA_CREATEISSUE(newIssueDetails, function (issueInfo) {
Log.Message(issueInfo.result.key);
});
}
Related Content
- 5 years agokip
- 5 years agoArunachalam
- 8 months agogdave