forked from baz/node-jira
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9abc1f4
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
url = require 'url' | ||
JiraRPC = require('./jira_client').JiraRPC | ||
JiraREST = require('./jira_client').JiraREST | ||
|
||
class JiraAPI | ||
constructor: -> | ||
@jiraRPC = new JiraRPC username, password, location | ||
@jiraREST = new JiraREST username, password, location | ||
|
||
authenticate: (callback) -> | ||
@jiraRPC.call 'login', [@jiraRPC.username, @jiraRPC.password], (error, response) -> | ||
if error then callback error, false else callback null, true | ||
|
||
allProjects: (callback) -> | ||
@jiraRPC.call 'getProjectsNoSchemes', null, callback | ||
|
||
allVersions: (projectKey, callback) -> | ||
@jiraRPC.call 'getVersions', [projectKey], callback | ||
|
||
allComponents: (projectKey, callback) -> | ||
@jiraRPC.call 'getComponents', [projectKey], callback | ||
|
||
issueTypes: (projectID, callback) -> | ||
@jiraRPC.call 'getIssueTypesForProject', [projectID], callback | ||
|
||
subTaskIssueTypes: (projectID, callback) -> | ||
@jiraRPC.call 'getSubTaskIssueTypesForProject', [projectID], callback | ||
|
||
priorities: (callback) -> | ||
@jiraRPC.call 'getPriorities', null, callback | ||
|
||
statuses: (callback) -> | ||
@jiraRPC.call 'getStatuses', null, callback | ||
|
||
resolutions: (callback) -> | ||
@jiraRPC.call 'getResolutions', null, callback | ||
|
||
items: (projectKey, limit, callback) -> | ||
query = "project = #{ projectKey } ORDER BY updated DESC, key DESC" | ||
@jiraRPC.call 'getIssuesFromJqlSearch', [query, limit], callback | ||
|
||
availableActions: (issueKey, callback) -> | ||
@jiraRPC.call 'getAvailableActions', [issueKey], callback | ||
|
||
worklogs: (issueKey, callback) -> | ||
@jiraRPC.call 'getWorklogs', [issueKey], callback | ||
|
||
module.exports = new JiraAPI() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
rest = require 'restler' | ||
querystring = require 'querystring' | ||
url = require 'url' | ||
|
||
class JiraRPC | ||
constructor: (@username, @password, @location) -> | ||
@apiPath = url.resolve @location, 'rpc/json-rpc/jirasoapservice-v2' | ||
|
||
call: (methodName, params = [], callback) -> | ||
# We are authenticating via basic auth, so the token is not needed | ||
# But a placeholder value is required | ||
# The only method which does not require a token parameter is the login method | ||
if methodName != 'login' then params.unshift 'token123' | ||
|
||
body = | ||
jsonrpc: '2.0' | ||
method: methodName | ||
params: params | ||
id: null | ||
bodyData = JSON.stringify(body) | ||
options = | ||
data: bodyData | ||
username: @username | ||
password: @password | ||
headers: | ||
'Content-Type': 'application/json' | ||
'Content-Length': bodyData.length | ||
|
||
request = rest.post @apiPath, options | ||
request.on 'success', (data) -> | ||
if data.error | ||
return callback data.error.message, null | ||
else | ||
return callback null, data.result | ||
request.on 'error', (data, response) => | ||
error = 'Error with HTTP status code: ' + response.statusCode + '\n' | ||
error += 'Your credentials or location (' + @apiPath + ') may be incorrect, please try again.' | ||
return callback error, null | ||
|
||
|
||
class JiraREST | ||
constructor: (@username, @password, @location) -> | ||
@apiPath = url.resolve @location, 'rest/api/2.0.alpha1/' | ||
|
||
get: (methodName, params = {}, callback) -> | ||
query = querystring.stringify params | ||
options = | ||
username: @username | ||
password: @password | ||
|
||
path = url.resolve @apiPath, methodName + "?#{ query }" | ||
request = rest.get path, options | ||
request.on 'success', (data) -> | ||
return callback null, data | ||
request.on 'error', (data, response) => | ||
error = 'Error with HTTP status code: ' + response.statusCode + '\n' | ||
error += 'Your credentials or location (' + @apiPath + ') may be incorrect, please try again.' | ||
return callback error, null | ||
|
||
module.exports.JiraRPC = JiraRPC | ||
module.exports.JiraREST = JiraREST |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "node-jira", | ||
"description": "JIRA v4.3 SOAP Interface", | ||
"version": "0.0.1", | ||
"author": "Basil Shkara <basil@neat.io>", | ||
"keywords": ["jira"], | ||
"main" : "lib/jira", | ||
"dependencies": { | ||
"restler": ">=0.2.1" | ||
}, | ||
"directories" : { | ||
"lib" : "./lib" | ||
}, | ||
"engines": { | ||
"node": ">= 0.4.2" | ||
} | ||
} |