Skip to content

Commit f8ae35c

Browse files
author
Fabio
committed
added new methods:
- addNewComponent - deleteComponent
1 parent efc81d4 commit f8ae35c

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

docs/jira.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22

33
<html>
44
<head>
@@ -70,6 +70,7 @@ <h2 id="implemented-apis">Implemented APIs</h2>
7070
<li>Pulling a project</li>
7171
<li>List all projects viewable to the user</li>
7272
<li>List Components</li>
73+
<li>Add a new component</li>
7374
<li>List Fields</li>
7475
<li>List Priorities</li>
7576
</ul>

lib/jira.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,86 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
11671167

11681168
});
11691169
};
1170+
1171+
// ## Add component to Jira ##
1172+
// ### Takes ###
1173+
//
1174+
// * issue: Properly Formatted Component
1175+
// * callback: for when it's done
1176+
//
1177+
// ### Returns ###
1178+
// * error object (check out the Jira Doc)
1179+
// * success object
1180+
//
1181+
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290028)
1182+
this.addNewComponent = function (component, callback) {
1183+
var options = {
1184+
rejectUnauthorized: this.strictSSL,
1185+
uri: this.makeUri('/component'),
1186+
method: 'POST',
1187+
followAllRedirects: true,
1188+
json: true,
1189+
body: component
1190+
};
1191+
1192+
this.doRequest(options, function (error, response, body) {
1193+
1194+
if (error) {
1195+
callback(error, null);
1196+
return;
1197+
}
1198+
1199+
if (response.statusCode === 400) {
1200+
callback(body);
1201+
return;
1202+
}
1203+
1204+
if ((response.statusCode !== 200) && (response.statusCode !== 201)) {
1205+
callback(response.statusCode + ': Unable to connect to JIRA during search.');
1206+
return;
1207+
}
1208+
1209+
callback(null, body);
1210+
1211+
});
1212+
};
1213+
1214+
// ## Delete component to Jira ##
1215+
// ### Takes ###
1216+
//
1217+
// * componentId: the Id of the component to delete
1218+
// * callback: for when it's done
1219+
//
1220+
// ### Returns ###
1221+
// * error string
1222+
// * success object
1223+
//
1224+
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290791)
1225+
this.deleteComponent = function (componentNum, callback) {
1226+
var options = {
1227+
rejectUnauthorized: this.strictSSL,
1228+
uri: this.makeUri('/component/' + componentNum),
1229+
method: 'DELETE',
1230+
followAllRedirects: true,
1231+
json: true
1232+
};
1233+
1234+
this.doRequest(options, function (error, response) {
1235+
1236+
if (error) {
1237+
callback(error, null);
1238+
return;
1239+
}
1240+
1241+
if (response.statusCode === 204) {
1242+
callback(null, "Success");
1243+
return;
1244+
}
1245+
1246+
callback(response.statusCode + ': Error while deleting');
1247+
1248+
});
1249+
};
11701250

11711251
// ## List listFields ##
11721252
// ### Takes ###

0 commit comments

Comments
 (0)