Skip to content

Commit 37626b8

Browse files
committed
Merge pull request #118 from fab1o/master
added new methods:
2 parents fceb2b6 + f8ae35c commit 37626b8

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
@@ -1168,6 +1168,86 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
11681168

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

11721252
// ## List listFields ##
11731253
// ### Takes ###

0 commit comments

Comments
 (0)