Skip to content

Commit efc81d4

Browse files
committed
Merge pull request #76 from itoche/remotelink
Remotelink support
2 parents 8e544fd + 6a8edac commit efc81d4

File tree

3 files changed

+177
-3
lines changed

3 files changed

+177
-3
lines changed

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,54 @@ or
2525
$ cd node-jira
2626
$ npm install
2727

28-
## Example ##
28+
## Examples ##
2929

30-
Find the status of an issue.
30+
### Create the JIRA client ###
3131

3232
JiraApi = require('jira').JiraApi;
33-
33+
3434
var jira = new JiraApi('https', config.host, config.port, config.user, config.password, '2.0.alpha1');
35+
36+
### Find the status of an issue ###
37+
3538
jira.findIssue(issueNumber, function(error, issue) {
3639
console.log('Status: ' + issue.fields.status.name);
3740
});
3841

42+
3943
Currently there is no explicit login call necessary as each API call uses Basic Authentication to authenticate.
4044

45+
### Get an issue remote links ###
46+
47+
Returns an array of remote links data.
48+
49+
jira.getRemoteLinks(issueKey, function(err, links) {
50+
if (!err) {
51+
console.log(issueKey + ' has ' + links.length + ' web links');
52+
}
53+
});
54+
55+
### Create a remote link on an issue ###
56+
57+
Returns an array of remote links data.
58+
59+
// create a web link to a GitHub issue
60+
var linkData = {
61+
"object": {
62+
"url" : "https://github.com/steves/node-jira/issues/1",
63+
"title": "Add getVersions and createVersion functions",
64+
"icon" : {
65+
"url16x16": "https://github.com/favicon.ico"
66+
}
67+
}
68+
};
69+
70+
jira.createRemoteLink(issueKey, linkData, function (err, link) {
71+
72+
});
73+
74+
More information can be found by checking [JIRA Developer documentation](https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+for+Remote+Issue+Links#JIRARESTAPIforRemoteIssueLinks-CreatingLinks).
75+
4176
## Options ##
4277

4378
JiraApi options:
@@ -84,6 +119,9 @@ JiraApi options:
84119
* Add a worklog
85120
* Add new estimate for worklog
86121
* Add a comment
122+
* Remote links (aka Web Links)
123+
* Create a remote link on an issue
124+
* Get all remote links of an issue
87125
* Transitions
88126
* List
89127
* Users

lib/jira.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,87 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
598598
});
599599
};
600600

601+
/**
602+
* Retrieves the remote links associated with the given issue.
603+
*
604+
* @param issueNumber - The internal id or key of the issue
605+
* @param callback
606+
*/
607+
this.getRemoteLinks = function getRemoteLinks(issueNumber, callback) {
608+
609+
var options = {
610+
rejectUnauthorized: this.strictSSL,
611+
uri: this.makeUri('/issue/' + issueNumber + '/remotelink'),
612+
method: 'GET',
613+
json: true
614+
};
615+
616+
this.doRequest(options, function(error, response) {
617+
618+
if (error) {
619+
callback(error, null);
620+
return;
621+
}
622+
623+
if (response.statusCode === 404) {
624+
callback('Invalid issue number.');
625+
return;
626+
}
627+
628+
if (response.statusCode !== 200) {
629+
callback(response.statusCode + ': Unable to connect to JIRA during request.');
630+
return;
631+
}
632+
633+
callback(null, response.body);
634+
635+
});
636+
};
637+
638+
/**
639+
* Retrieves the remote links associated with the given issue.
640+
*
641+
* @param issueNumber - The internal id (not the issue key) of the issue
642+
* @param callback
643+
*/
644+
this.createRemoteLink = function createRemoteLink(issueNumber, remoteLink, callback) {
645+
646+
var options = {
647+
rejectUnauthorized: this.strictSSL,
648+
uri: this.makeUri('/issue/' + issueNumber + '/remotelink'),
649+
method: 'POST',
650+
json: true,
651+
body: remoteLink
652+
};
653+
654+
this.doRequest(options, function(error, response) {
655+
656+
if (error) {
657+
callback(error, null);
658+
return;
659+
}
660+
661+
if (response.statusCode === 404) {
662+
callback('Cannot create remote link. Invalid issue.');
663+
return;
664+
}
665+
666+
if (response.statusCode === 400) {
667+
callback('Cannot create remote link. ' + response.body.errors.title);
668+
return;
669+
}
670+
671+
if (response.statusCode !== 200) {
672+
callback(response.statusCode + ': Unable to connect to JIRA during request.');
673+
return;
674+
}
675+
676+
callback(null, response.body);
677+
678+
});
679+
};
680+
681+
601682
// ## Get Versions for a project ##
602683
// ### Takes ###
603684
// * project: A project key

spec/jira.spec.coffee

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,3 +635,58 @@ describe "Node Jira Tests", ->
635635
# Successful Request
636636
@jira.request.mostRecentCall.args[1] null, statusCode:200, body: issues: ['test']
637637
expect(@cb).toHaveBeenCalledWith null, issues: ['test']
638+
639+
it "Finds the remote links of an issue", ->
640+
options =
641+
rejectUnauthorized: true
642+
uri: makeUrl "issue/1/remotelink"
643+
method: 'GET'
644+
json: true
645+
auth:
646+
user: 'test'
647+
pass: 'test'
648+
@jira.getRemoteLinks 1, @cb
649+
expect(@jira.request)
650+
.toHaveBeenCalledWith(options, jasmine.any(Function))
651+
652+
# Invalid issue number (different than unable to find??)
653+
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
654+
expect(@cb).toHaveBeenCalledWith 'Invalid issue number.'
655+
656+
# Unable to find issue
657+
@jira.request.mostRecentCall.args[1] null, statusCode:401, null
658+
expect(@cb).toHaveBeenCalledWith(
659+
'401: Unable to connect to JIRA during request.')
660+
661+
# Successful Request
662+
@jira.request.mostRecentCall.args[1] null,
663+
statusCode:200, body:"none"
664+
expect(@cb).toHaveBeenCalledWith(null, 'none')
665+
666+
it "Creates a remote link", ->
667+
options =
668+
rejectUnauthorized: true
669+
uri: makeUrl "issue/1/remotelink"
670+
method: 'POST'
671+
json: true
672+
body: 'test'
673+
auth:
674+
user: 'test'
675+
pass: 'test'
676+
677+
@jira.createRemoteLink 1, 'test', @cb
678+
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
679+
680+
# Invalid Issue
681+
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
682+
expect(@cb).toHaveBeenCalledWith 'Cannot create remote link. Invalid issue.'
683+
684+
response =
685+
statusCode:400
686+
body:
687+
errors:
688+
title: 'test'
689+
@jira.request.mostRecentCall.args[1] null, response
690+
expect(@cb).toHaveBeenCalledWith(
691+
'Cannot create remote link. test')
692+

0 commit comments

Comments
 (0)