Skip to content
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

Adding expand renderedFields to findIssue. Implemented createMeta function #93

Open
wants to merge 6 commits 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
154 changes: 150 additions & 4 deletions lib/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor

var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri('/issue/' + issueNumber),
uri: this.makeUri('/issue/' + issueNumber + '?expand=renderedFields'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this the default option? I think there should be a way to specify this value.

method: 'GET'
};

Expand All @@ -224,15 +224,160 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
}

if (response.statusCode !== 200) {
callback(response.statusCode + ': Unable to connect to JIRA during findIssueStatus.');
callback(response.statusCode + ': Unable to connect to JIRA during findIssue.');
return;
}

if (body === undefined) {
callback('Response body was undefined.');
return;
}

callback(null, JSON.parse(body));

});
};

// ## Find the keys of all properties for the comment ##
// ### Takes ###
//
// * commentId: the comment from which keys will be returned.
// * callback: for when it's done
//
// ### Returns ###
//
// * error: string of the error
// * issue: an object of the issue
//
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e5287)
this.getCommentPropertyKeys = function(commentId, callback) {
var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri(
'/comment/' + commentId + '/properties'),
method: 'GET'
};

this.doRequest(options, function(error, response, body) {

if (error) {
callback(error, null);
return;
}

if (response.statusCode === 404) {
callback('Invalid issue number.');
return;
}

if (response.statusCode !== 200) {
callback(response.statusCode + ': Unable to connect to JIRA during getCommentPropertyKeys.');
return;
}

if (body === undefined) {
callback('Response body was undefined.');
return;
}
callback(null, JSON.parse(body));

});
}

// ## Finds the value of the property with a given
// key from the comment identified by the key or by the id ##
// ### Takes ###
//
// * commentId: the comment from which keys will be returned.
// * propertyKey: the key of the property.
// * callback: for when it's done
//
// ### Returns ###
//
// * error: string of the error
// * issue: an object of the issue
//
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e5317)
this.getCommentPropertyValue = function(commentId, propertyKey, callback) {
var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri(
'/comment/' + commentId + '/properties/' + propertyKey),
method: 'GET'
};

this.doRequest(options, function(error, response, body) {

if (error) {
callback(error, null);
return;
}

if (response.statusCode === 404) {
callback('Invalid issue number.');
return;
}

if (response.statusCode !== 200) {
callback(response.statusCode + ': Unable to connect to JIRA during getCommentPropertyValue.');
return;
}

if (body === undefined) {
callback('Response body was undefined.');
return;
}
callback(null, JSON.parse(body));

});
}

// ## Get Meta data for creating an issue ##
// ### Takes ###
//
// * projectKey: the key for the desired project
// * callback: for when it's done
//
// ### Returns ###
//
// * error: string of the error
// * meta: an object of the meta data for creating issues.
//
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e4547)
this.createMeta = function(projectKey, callback) {

var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri(
'/issue/createmeta' +
'?projectKeys=' + projectKey +
'&expand=projects.issuetypes.fields'),
method: 'GET'
// Node, the API support filtering by projectIds, issuetypeIds, issuetypeNames
// I'm only using the projectKeys filter (and only ONE projectKey)
};

this.doRequest(options, function(error, response, body) {

if (error) {
callback(error, null);
return;
}

if (response.statusCode === 404) {
callback('Invalid issue number.');
return;
}

if (response.statusCode !== 200) {
callback(response.statusCode + ': Unable to connect to JIRA during createMeta.');
return;
}

if (body === undefined) {
callback('Response body was undefined.');
return;
}
callback(null, JSON.parse(body));

});
Expand Down Expand Up @@ -878,7 +1023,8 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
jql: searchString,
startAt: optional.startAt || 0,
maxResults: optional.maxResults || 50,
fields: optional.fields || ["summary", "status", "assignee", "description"]
fields: optional.fields || ["summary", "status", "assignee", "description"],
expand: optional.expand
}
};

Expand Down Expand Up @@ -1475,7 +1621,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
callback("Invalid Fields: " + JSON.stringify(body));
return;
};

callback(response.statusCode + ': Error while adding comment');
});
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jira",
"version": "0.9.2",
"name": "jira-greenqloud",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clean this up?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw this now, do you still want this cleaned up?

"version": "0.9.3",
"description": "Wrapper for the JIRA API",
"author": "Steven Surowiec <steven.surowiec@gmail.com>",
"contributors": [
Expand Down
23 changes: 11 additions & 12 deletions spec/jira.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe "Node Jira Tests", ->
.toHaveBeenCalledWith(options, jasmine.any(Function))

it "Sets OAuth oauth for the requests if oauth is passed in", ->
options =
oauth =
options =
oauth =
consumer_key: 'ck'
consumer_secret: 'cs'
access_token: 'ac'
Expand Down Expand Up @@ -65,7 +65,7 @@ describe "Node Jira Tests", ->
it "Finds an issue", ->
options =
rejectUnauthorized: true
uri: makeUrl "issue/1"
uri: makeUrl "issue/1?expand=renderedFields"
method: 'GET'
auth:
user: 'test'
Expand All @@ -81,7 +81,7 @@ describe "Node Jira Tests", ->
# Unable to find issue
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during findIssueStatus.')
'401: Unable to connect to JIRA during findIssue.')

# Successful Request
@jira.request.mostRecentCall.args[1] null,
Expand Down Expand Up @@ -109,7 +109,7 @@ describe "Node Jira Tests", ->
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
expect(@cb).toHaveBeenCalledWith(
'401: Unable to connect to JIRA during findIssueStatus.')

# Successful Request
@jira.request.mostRecentCall.args[1] null,
statusCode:200, '{"issuesUnresolvedCount":1}'
Expand Down Expand Up @@ -151,7 +151,7 @@ describe "Node Jira Tests", ->
expect(@jira.request)
.toHaveBeenCalledWith options, jasmine.any(Function)

# Invalid URL
# Invalid URL
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid URL'

Expand Down Expand Up @@ -180,7 +180,7 @@ describe "Node Jira Tests", ->
@jira.getLastSprintForRapidView 1, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)

# Invalid URL
# Invalid URL
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid URL'

Expand All @@ -195,7 +195,7 @@ describe "Node Jira Tests", ->
sprints: [name: 'ABC']

expect(@cb).toHaveBeenCalledWith null, name: 'ABC'

it "Adds an issue to a sprint", ->
options =
rejectUnauthorized: true
Expand All @@ -212,7 +212,7 @@ describe "Node Jira Tests", ->
@jira.addIssueToSprint 2, 1, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)

# Invalid URL
# Invalid URL
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Invalid URL'

Expand Down Expand Up @@ -363,7 +363,7 @@ describe "Node Jira Tests", ->
spyOn @jira, 'searchJira'
expected = "assignee = test AND status in (Open, \"In Progress\",
Reopened)"

@jira.getUsersIssues 'test', true, @cb
expect(@jira.searchJira).toHaveBeenCalledWith expected, {},
jasmine.any(Function)
Expand Down Expand Up @@ -396,7 +396,7 @@ describe "Node Jira Tests", ->
it "Gets ALL a specified User's Issues", ->
spyOn @jira, 'searchJira'
expected = "assignee = test"

@jira.getUsersIssues 'test', false, @cb
expect(@jira.searchJira).toHaveBeenCalledWith expected, {},
jasmine.any(Function)
Expand Down Expand Up @@ -689,4 +689,3 @@ describe "Node Jira Tests", ->
@jira.request.mostRecentCall.args[1] null, response
expect(@cb).toHaveBeenCalledWith(
'Cannot create remote link. test')