diff --git a/lib/jira.js b/lib/jira.js index ce90137c..69450ab2 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -185,7 +185,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor 'pass': this.password }; } - this.request(options, callback); + return this.request(options, callback); }; }; @@ -1022,6 +1022,58 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor }); }; + + + // ## Add attachment to Jira issue ## + // ### Takes ### + // + // * issueId: the Id of the issue to delete + // * readStream: the readable stream which will be piped out as the attachment + // * callback: for when it's done + // + // ### Returns ### + // * error object (check out the Jira Doc) + // * success object + // + // [Jira Doc](https://docs.atlassian.com/jira/REST/latest/#d2e2894) + this.addAttachment = function(issueNum, readStream, callback) { + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/issue/' + issueNum + '/attachments'), + method: 'POST', + followAllRedirects: true, + headers: { 'X-Atlassian-Token': 'nocheck' }, + json: true + }; + + this.doRequest(options, function(error, response, body) { + + if (error) { + callback(error, null); + return; + } + + if (response.statusCode === 403) { + callback("Insufficient Permissions"); + return; + } + + if (response.statusCode === 404) { + callback("Not found"); + return; + } + + if (response.statusCode !== 200) { + callback(response.statusCode + ': Unable to connect to JIRA during upload.'); + return; + } + + callback(null, body); + + }).form().append('file', readStream); + }; + + // ## List Components ## // ### Takes ###