From 23b83ef39de415c787ecfab5647d4f82112d5a98 Mon Sep 17 00:00:00 2001 From: Tomas Brambora Date: Fri, 26 Sep 2014 12:09:53 +0800 Subject: [PATCH 1/4] Creating a resource returns HTTP 201. --- lib/jira.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jira.js b/lib/jira.js index e919d9da..06d9f5db 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -668,7 +668,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor return; } - if (response.statusCode !== 200) { + if (response.statusCode !== 201) { callback(response.statusCode + ': Unable to connect to JIRA during request.'); return; } From 35d308804e4457397c00b419e8c2cce7bfa58750 Mon Sep 17 00:00:00 2001 From: Tomas Brambora Date: Mon, 13 Oct 2014 16:53:00 +0800 Subject: [PATCH 2/4] Check for 200 *and* 201 when creating remote issue. --- lib/jira.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jira.js b/lib/jira.js index 06d9f5db..4c0b2a38 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -668,7 +668,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor return; } - if (response.statusCode !== 201) { + if ([200, 201].indexOf(response.statusCode) < 0) { callback(response.statusCode + ': Unable to connect to JIRA during request.'); return; } From ae29bf9421a1af1103fdf7f0ecf61856cf236e5b Mon Sep 17 00:00:00 2001 From: Tomas Brambora Date: Wed, 3 Dec 2014 15:46:48 +0800 Subject: [PATCH 3/4] Added `deleteRemoteLink` method. --- lib/jira.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/jira.js b/lib/jira.js index 4c0b2a38..65b7baf5 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -678,6 +678,50 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor }); }; + /** + * Deletes the remote links associated with the given issue. + * + * @param issueNumber - The internal id (not the issue key) of the issue + * @param globalId - The global id of the remote link + * @param callback + */ + this.deleteRemoteLink = function deleteRemoteLink(issueNumber, remoteLinkGID, callback) { + + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/issue/' + issueNumber + '/remotelink'), + method: 'DELETE', + qs: {globalId: remoteLinkGID}, + json: true + }; + + this.doRequest(options, function(error, response) { + + if (error) { + callback(error, null); + return; + } + + if (response.statusCode === 404) { + callback('Cannot delete remote link. Invalid issue.'); + return; + } + + if (response.statusCode === 400) { + callback('Cannot create remote link. ' + response.body.errors.title); + return; + } + + if ([200, 201].indexOf(response.statusCode) < 0) { + callback(response.statusCode + ': Unable to connect to JIRA during request.'); + return; + } + + callback(null, response.body); + + }); + }; + // ## Get Versions for a project ## // ### Takes ### From 15b3156f67b7429a987c731868b94aa91bc77ebc Mon Sep 17 00:00:00 2001 From: Tomas Brambora Date: Wed, 3 Dec 2014 16:40:08 +0800 Subject: [PATCH 4/4] Simplified success response code handling. --- lib/jira.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jira.js b/lib/jira.js index 65b7baf5..867deb61 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -668,7 +668,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor return; } - if ([200, 201].indexOf(response.statusCode) < 0) { + if (response.statusCode / 100 | 0 != 2) { callback(response.statusCode + ': Unable to connect to JIRA during request.'); return; } @@ -712,7 +712,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor return; } - if ([200, 201].indexOf(response.statusCode) < 0) { + if (response.statusCode / 100 | 0 != 2) { callback(response.statusCode + ': Unable to connect to JIRA during request.'); return; }