Skip to content

new features #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>node-jira</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
277 changes: 274 additions & 3 deletions lib/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,20 @@ var url = require('url'),
OAuth = require("oauth");


var JiraApi = exports.JiraApi = function(protocol, host, port, username, password, apiVersion, verbose, strictSSL, oauth) {
var JiraApi = exports.JiraApi = function(protocol, host, port, username, password, apiVersion, verbose, strictSSL, oauth,isLocal) {
this.protocol = protocol;
this.host = host;
this.port = port;
this.username = username;
this.password = password;
this.apiVersion = apiVersion;

this.isLocal=false;
if(isLocal!=null)
{
this.isLocal=isLocal;
}

// Default strictSSL to true (previous behavior) but now allow it to be
// modified
if (strictSSL == null) {
Expand All @@ -152,7 +159,12 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
// This is the same almost every time, refactored to make changing it
// later, easier
this.makeUri = function(pathname, altBase, altApiVersion) {
var basePath = 'rest/api/';

var basePath = 'rest/api/';
if(this.isLocal){
var basePath = 'jira/rest/api/';
}

if (altBase != null) {
basePath = altBase;
}
Expand All @@ -161,7 +173,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
if (altApiVersion != null) {
apiVersion = altApiVersion;
}

var uri = url.format({
protocol: this.protocol,
hostname: this.host,
Expand Down Expand Up @@ -1916,5 +1928,264 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
callback(response.statusCode + ': Error while retrieving backlog');
});
};

/**
* Create a new filter for this user.
* var filterParams = {
* "name": "All Open Bugs",
* "description": "Lists all open bugs",
* "jql": "type = Bug and resolution is empty",
* "favourite": true
* }
*/
this.createFilter = function(filterParams,callback){

var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri('/filter'),
method: 'POST',
json: true,
body: filterParams
};
console.log(options);
this.doRequest(options, function(error, response) {
//console.log(response.body);
if (error) {
callback(error, null);

return;
}

if (response.statusCode === 200) {
if (typeof response.body.errors === "undefined"){
callback(null, response.body);
}
else {
callback(response.body.errors);
}
return;
}
callback(response.statusCode +' : ' +response.body.errors[0]);
});

};



/**
* Change the default scope for filters that the user makes
* }
*/
this.changeFilterShareScope = function(bGlobal,callback){

var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri('/filter/defaultShareScope'),
method: 'PUT',
json: true,
body: {"scope": (bGlobal)?"GLOBAL":"LOCAL"},
};
this.doRequest(options, function(error, response) {
//console.log(response.body);
if (error) {
callback(error, null);
return;
}

if (response.statusCode === 200) {
if (typeof response.body.errors === "undefined"){
callback(null, response.body);
}
else {
callback(response.body.errors);
}
return;
}
callback(response.statusCode +' : ' +response.body.errors[0]);
});

};


/**
* Update an existing filter for this user.
* var filterParams = {
* "name": "All Open Bugs",
* "description": "Lists all open bugs",
* "jql": "type = Bug and resolution is empty",
* "favourite": true
* }
*/
this.updateFilter = function(filterId,filterParams,callback){

var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri('/filter/'+filterId),
method: 'PUT',
json: true,
body: filterParams
};
this.doRequest(options, function(error, response) {
//console.log(response.body);
if (error) {
callback(error, null);
return;
}

if (response.statusCode === 200) {
if (typeof response.body.errors === "undefined"){
callback(null, response.body);
}
else {
callback(response.body.errors);
}
return;
}
callback(response.statusCode +' : ' +response.body.errors[0]);
});

};

/**
* deletes filter with id filterid
*/
this.deleteFilter = function(filterId, callback) {

var options = {
rejectUnauthorized : this.strictSSL,
uri : this.makeUri('/filter/' + filterId),
method : 'DELETE',
json : false
};
this.doRequest(options, function(error, response) {
//console.log(response.body);
if (error) {
callback(error, null);
return;
}
callback(null, response);
});
};

/**
* get filter with name from fav filters of this user
*/
this.findFilter = function(name, callback) {
var options = {
rejectUnauthorized : this.strictSSL,
uri : this.makeUri('/filter/favourite'),
method : 'GET',
json : true
};
this.doRequest(options, function(error, response) {
//console.log(response.body);
if (error) {
callback(error, 0);
return;
}
var id = 0;
for (var i = 0; i < response.body.length; i++) {
var item=response.body[i];
if (item.name == name) {
id = item.id;
break;
}
}
if(id==0) console.log("could not find a filter with name "+name);
callback(null, id);
});
};

/**
* get filters with names from fav filters of this user
*/
this.findFilters = function(names, callback) {
var options = {
rejectUnauthorized : this.strictSSL,
uri : this.makeUri('/filter/favourite'),
method : 'GET',
json : true
};
this.doRequest(options, function(error, response) {
//console.log(response.body);
if (error) {
callback(error,null);
return;
}
names.errors=false;
for(var j =0; j < names.length; j++){
names[j].id=0;
for (var i = 0; i < response.body.length; i++) {
var item=response.body[i];
if (item.name == names[j].name) {
names[j].id=item.id;
break;
}
}
if(names[j].id==0){
console.log("could not find a filter with name "+names[j].name);
names.errors=true; //at least one filter was not found
delete names[j].id;
}
}
callback(null, names);
});
};

/**
* get details of a version
*/
this.getVersion = function(id, callback) {
var options = {
rejectUnauthorized : this.strictSSL,
uri : this.makeUri('/version/'+id+'/relatedIssueCounts'),
method : 'GET',
json : true
};
var self=this;
this.doRequest(options, function(error, response) {
//console.log(response.body);
if (response){
options.uri=self.makeUri('/version/'+id+'/unresolvedIssueCount');

self.doRequest(options, function(error, resp2) {
if(resp2){
//merge the resp2
response.body.issuesUnresolvedCount=resp2.body.issuesUnresolvedCount;
callback(null, response.body);
}
else if (error) {
callback(error, 0);
}
else{
callback("Unknown error", 0);
}
});
}
else if (error) {
callback(error, 0);
}
else{
callback("Unknown error", 0);
}
});
};

this.deleteVersion = function(id, callback) {
var options = {
rejectUnauthorized : this.strictSSL,
uri : this.makeUri('/version/'+id),
method : 'DELETE',
json : true
};
this.doRequest(options, function(error, response) {
if(error){
console.log("Error deleting version "+id+" : "+error);
}
if(callback){
callback(error, response);
}
});
};

}).call(JiraApi.prototype);