Skip to content

Commit f3e223d

Browse files
author
Andrea Rossi
committed
attachToIssue method added, takes issueNum, file path and callback
1 parent e98573b commit f3e223d

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

lib/jira.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,59 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
969969

970970
});
971971
};
972-
972+
973+
// ## Add attachment to issue ##
974+
// ### Takes ###
975+
//
976+
// * issueId: the Id of the issue to delete
977+
// * path: local path to the attachment
978+
// * callback: for when it's done
979+
//
980+
// ### Returns ###
981+
// * error string
982+
// * success string
983+
//
984+
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#idp2051136)
985+
this.attachToIssue = function(issueNum, path, callback) {
986+
var self = this;
987+
var options = {
988+
rejectUnauthorized: this.strictSSL,
989+
uri: this.makeUri('/issue/' + issueNum + '/attachments'),
990+
method: 'POST',
991+
followAllRedirects: true,
992+
json: true,
993+
headers: {
994+
'x-atlassian-token': 'nocheck'
995+
}
996+
};
997+
998+
var form = new FormData();
999+
form.append('file', fs.createReadStream(path));
1000+
1001+
form.getLength(function(err, length) {
1002+
1003+
var form_request = self.request(options, function(error, response) {
1004+
if (error) {
1005+
callback(error, null);
1006+
return;
1007+
}
1008+
1009+
if (response.statusCode === 200) {
1010+
callback(null, "Success");
1011+
return;
1012+
}
1013+
1014+
callback(response.statusCode + ': Error while uploading');
1015+
1016+
});
1017+
1018+
form_request.setHeader('Content-Length', length);
1019+
form = form_request.form();
1020+
form.append('file', fs.createReadStream(path));
1021+
});
1022+
1023+
};
1024+
9731025
// ## List all Viewable Projects ##
9741026
// ### Takes ###
9751027
//

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
}
2323
],
2424
"dependencies": {
25-
"request": "<2.16.0"
25+
"request": "<2.16.0",
26+
"form-data": "0.0.10"
2627
},
2728
"scripts": {
2829
"test": "grunt test"

0 commit comments

Comments
 (0)