Created
July 2, 2015 23:53
-
-
Save feminie/8fe722c63cc7b795dc8c to your computer and use it in GitHub Desktop.
jira-node source code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main.js | |
var request = require("request"); | |
var url = require("url"); | |
var querystring = require("querystring"); | |
var jira = {}; | |
module.exports = jira; | |
jira.setServer = function(server){ | |
jira.urlServer = server; | |
} | |
jira.setCredentials = function(username, password){ | |
jira.credentials = { | |
"username" : username, | |
"password" : password | |
}; | |
} | |
jira.getAllIssues = function(JQLQuery, callback){ | |
//first fetch the number of issues; | |
var authorization,headers = {}; | |
if (jira.credentials) | |
authorization = "Basic " + new Buffer(jira.credentials.username + ":" + jira.credentials.password).toString('base64'); | |
if (authorization) | |
headers.authorization = authorization; | |
headers["Content-Type"] = "application/json"; | |
var urlPath = jira.urlServer + "/rest/api/2/search" + "?" + querystring.stringify({ | |
jql : JQLQuery, | |
maxResults: 0}); | |
request.get({ | |
"url" : urlPath, | |
"headers" : headers | |
},function (error,responce){ | |
if (error){ | |
return callback(error,null); | |
} | |
var numberOfIssues = JSON.parse(responce.body).total; | |
urlPath = jira.urlServer + "/rest/api/2/search" + "?" + querystring.stringify({ | |
jql : JQLQuery, | |
maxResults: numberOfIssues}); | |
request.get({ | |
"url" : urlPath, | |
"headers" : headers | |
}, function (error,responce){ | |
if(error){ | |
return callback(error,null); | |
} | |
var returnObj = JSON.parse(responce.body); | |
callback(null, returnObj); | |
}); | |
}); | |
} | |
example.js | |
var jira = require("../lib/main"); | |
jira.setServer("serverName"); | |
jira.setCredentials("user","password"); | |
jira.getAllIssues('issuetype = "IssueTypename" AND createdDate > -3d',function(err,result){ | |
console.log(result.issues[0]); | |
}); | |
console.log("bla"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment