27
27
//
28
28
// ## Example ##
29
29
//
30
- // Find the status of an issue.
30
+ // Find the status of an issue. (this example provide also different types of authentication
31
31
//
32
- // JiraApi = require('jira').JiraApi;
33
- //
34
- // var jira = new JiraApi('https', config.host, config.port, config.user, config.password, '2.0.alpha1');
35
- // jira.findIssue(issueNumber, function(error, issue) {
36
- // console.log('Status: ' + issue.fields.status.name);
37
- // });
32
+ //const HttpProxyAgent = require("http-proxy-agent");
33
+ //const agent = new HttpProxyAgent("http://proxy");
34
+ //const options = {
35
+ // "agent": agent, // proxy setting
36
+ // rejectUnauthorized: this.strictSSL, // strict ssl option
37
+ // headers: {
38
+ // "Proxy-Authorization": "Bearer authentication_token", // proxy authentification
39
+ // "Authorization": 'Basic ' + Buffer.from(username + ':' + password).toString('base64') // basic authentication
40
+ // },
41
+ // oauth: { // in the case of oauth instead of basic
42
+ // consumer_key: oauth.consumer_key,
43
+ // consumer_secret: oauth.consumer_secret,
44
+ // token: oauth.access_token,
45
+ // token_secret: oauth.access_token_secret
46
+ // }
47
+ //}
48
+ //JiraApi = require('jira').JiraApi;
38
49
//
50
+ //var jira = new JiraApi('https', 'server.com', '443', '2.0.alpha1', true, 'jira', options);
51
+ //jira.findIssue(issueNumber, function(error, issue) {
52
+ // console.log('Status: ' + issue.fields.status.name);
53
+ //});
39
54
// Currently there is no explicit login call necessary as each API call uses Basic Authentication to authenticate.
40
55
//
41
56
// ## Options ##
44
59
// * `protocol<string>`: Typically 'http:' or 'https:'
45
60
// * `host<string>`: The hostname for your jira server
46
61
// * `port<int>`: The port your jira server is listening on (probably `80` or `443`)
47
- // * `user<string>`: The username to log in with
48
- // * `password<string>`: Keep it secret, keep it safe
49
62
// * `Jira API Version<string>`: Known to work with `2` and `2.0.alpha1`
50
63
// * `verbose<bool>`: Log some info to the console, usually for debugging
51
- // * `strictSSL<bool>`: Set to false if you have self-signed certs or something non-trustworthy
52
- // * `oauth`: A dictionary of `consumer_key`, `consumer_secret`, `access_token` and `access_token_secret` to be used for OAuth authentication.
53
64
// * `base`: Add base slug if your JIRA install is not at the root of the host
65
+ // * `options`: request Options standard parameter (see request doc)
54
66
//
55
67
// ## Implemented APIs ##
56
68
//
@@ -132,21 +144,14 @@ var url = require('url'),
132
144
logger = console ,
133
145
OAuth = require ( "oauth" ) ;
134
146
135
-
136
- var JiraApi = exports . JiraApi = function ( protocol , host , port , username , password , apiVersion , verbose , strictSSL , oauth , base ) {
147
+ var JiraApi = exports . JiraApi = function ( protocol , host , port , apiVersion , verbose , base , requestOptions ) {
137
148
this . protocol = protocol ;
138
149
this . host = host ;
139
150
this . port = port ;
140
- this . username = username ;
141
- this . password = password ;
142
151
this . apiVersion = apiVersion ;
143
152
this . base = base ;
144
- // Default strictSSL to true (previous behavior) but now allow it to be
145
- // modified
146
- if ( strictSSL == null ) {
147
- strictSSL = true ;
148
- }
149
- this . strictSSL = strictSSL ;
153
+ this . requestOptions = requestOptions === undefined ?{ } :requestOptions ;
154
+
150
155
// This is so we can fake during unit tests
151
156
this . request = require ( 'request' ) ;
152
157
if ( verbose !== true ) { logger = { log : function ( ) { } } ; }
@@ -177,20 +182,11 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
177
182
} ;
178
183
179
184
this . doRequest = function ( options , callback ) {
180
- if ( oauth && oauth . consumer_key && oauth . consumer_secret ) {
181
- options . oauth = {
182
- consumer_key : oauth . consumer_key ,
183
- consumer_secret : oauth . consumer_secret ,
184
- token : oauth . access_token ,
185
- token_secret : oauth . access_token_secret
186
- } ;
187
- } else if ( this . username && this . password ) {
188
- options . auth = {
189
- 'user' : this . username ,
190
- 'pass' : this . password
191
- } ;
192
- }
193
- this . request ( options , callback ) ;
185
+ clonedOptions = require ( 'clone-deep' ) ( this . requestOptions )
186
+ for ( var key in options ) {
187
+ if ( options . hasOwnProperty ( key ) ) clonedOptions [ key ] = options [ key ] ;
188
+ }
189
+ this . request ( clonedOptions , callback ) ;
194
190
} ;
195
191
196
192
} ;
@@ -211,7 +207,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
211
207
this . findIssue = function ( issueNumber , callback ) {
212
208
213
209
var options = {
214
- rejectUnauthorized : this . strictSSL ,
215
210
uri : this . makeUri ( '/issue/' + issueNumber ) ,
216
211
method : 'GET'
217
212
} ;
@@ -256,7 +251,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
256
251
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id288524)
257
252
this . getUnresolvedIssueCount = function ( version , callback ) {
258
253
var options = {
259
- rejectUnauthorized : this . strictSSL ,
260
254
uri : this . makeUri ( '/version/' + version + '/unresolvedIssueCount' ) ,
261
255
method : 'GET'
262
256
} ;
@@ -298,7 +292,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
298
292
this . getProject = function ( project , callback ) {
299
293
300
294
var options = {
301
- rejectUnauthorized : this . strictSSL ,
302
295
uri : this . makeUri ( '/project/' + project ) ,
303
296
method : 'GET'
304
297
} ;
@@ -345,7 +338,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
345
338
this . findRapidView = function ( projectName , callback ) {
346
339
347
340
var options = {
348
- rejectUnauthorized : this . strictSSL ,
349
341
uri : this . makeUri ( '/rapidviews/list' , 'rest/greenhopper/' ) ,
350
342
method : 'GET' ,
351
343
json : true
@@ -400,7 +392,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
400
392
this . getLastSprintForRapidView = function ( rapidViewId , callback ) {
401
393
402
394
var options = {
403
- rejectUnauthorized : this . strictSSL ,
404
395
uri : this . makeUri ( '/sprintquery/' + rapidViewId , 'rest/greenhopper/' ) ,
405
396
method : 'GET' ,
406
397
json :true
@@ -453,7 +444,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
453
444
this . getSprintIssues = function getSprintIssues ( rapidViewId , sprintId , callback ) {
454
445
455
446
var options = {
456
- rejectUnauthorized : this . strictSSL ,
457
447
uri : this . makeUri ( '/rapid/charts/sprintreport?rapidViewId=' + rapidViewId + '&sprintId=' + sprintId , 'rest/greenhopper/' ) ,
458
448
method : 'GET' ,
459
449
json : true
@@ -509,7 +499,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
509
499
this . addIssueToSprint = function ( issueId , sprintId , callback ) {
510
500
511
501
var options = {
512
- rejectUnauthorized : this . strictSSL ,
513
502
uri : this . makeUri ( '/sprint/' + sprintId + '/issues/add' , 'rest/greenhopper/' ) ,
514
503
method : 'PUT' ,
515
504
followAllRedirects : true ,
@@ -573,7 +562,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
573
562
this . issueLink = function ( link , callback ) {
574
563
575
564
var options = {
576
- rejectUnauthorized : this . strictSSL ,
577
565
uri : this . makeUri ( '/issueLink' ) ,
578
566
method : 'POST' ,
579
567
followAllRedirects : true ,
@@ -612,7 +600,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
612
600
this . getRemoteLinks = function getRemoteLinks ( issueNumber , callback ) {
613
601
614
602
var options = {
615
- rejectUnauthorized : this . strictSSL ,
616
603
uri : this . makeUri ( '/issue/' + issueNumber + '/remotelink' ) ,
617
604
method : 'GET' ,
618
605
json : true
@@ -649,7 +636,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
649
636
this . createRemoteLink = function createRemoteLink ( issueNumber , remoteLink , callback ) {
650
637
651
638
var options = {
652
- rejectUnauthorized : this . strictSSL ,
653
639
uri : this . makeUri ( '/issue/' + issueNumber + '/remotelink' ) ,
654
640
method : 'POST' ,
655
641
json : true ,
@@ -697,7 +683,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
697
683
this . getVersions = function ( project , callback ) {
698
684
699
685
var options = {
700
- rejectUnauthorized : this . strictSSL ,
701
686
uri : this . makeUri ( '/project/' + project + '/versions' ) ,
702
687
method : 'GET'
703
688
} ;
@@ -751,7 +736,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
751
736
this . createVersion = function ( version , callback ) {
752
737
753
738
var options = {
754
- rejectUnauthorized : this . strictSSL ,
755
739
uri : this . makeUri ( '/version' ) ,
756
740
method : 'POST' ,
757
741
followAllRedirects : true ,
@@ -811,7 +795,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
811
795
*/
812
796
this . updateVersion = function ( version , callback ) {
813
797
var options = {
814
- rejectUnauthorized : this . strictSSL ,
815
798
uri : this . makeUri ( '/version/' + version . id ) ,
816
799
method : 'PUT' ,
817
800
followAllRedirects : true ,
@@ -874,7 +857,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
874
857
}
875
858
876
859
var options = {
877
- rejectUnauthorized : this . strictSSL ,
878
860
uri : this . makeUri ( '/search' ) ,
879
861
method : 'POST' ,
880
862
json : true ,
@@ -934,7 +916,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
934
916
includeInactive = ( includeInactive !== undefined ) ? includeInactive : false ;
935
917
936
918
var options = {
937
- rejectUnauthorized : this . strictSSL ,
938
919
uri : this . makeUri (
939
920
'/user/search?username=' + username +
940
921
'&startAt=' + startAt +
@@ -985,7 +966,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
985
966
maxResults = ( maxResults !== undefined ) ? maxResults : 50 ;
986
967
987
968
var options = {
988
- rejectUnauthorized : this . strictSSL ,
989
969
uri : this . makeUri (
990
970
'/group?groupname=' + groupName +
991
971
'&expand=users[' + startAt + ':' + maxResults + ']' ) ,
@@ -1053,7 +1033,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1053
1033
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290028)
1054
1034
this . addNewIssue = function ( issue , callback ) {
1055
1035
var options = {
1056
- rejectUnauthorized : this . strictSSL ,
1057
1036
uri : this . makeUri ( '/issue' ) ,
1058
1037
method : 'POST' ,
1059
1038
followAllRedirects : true ,
@@ -1106,7 +1085,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1106
1085
this . addWatcher = function ( issueKey , username , callback ) {
1107
1086
1108
1087
var options = {
1109
- rejectUnauthorized : this . strictSSL ,
1110
1088
uri : this . makeUri ( '/issue/' + issueKey + '/watchers' ) ,
1111
1089
method : 'POST' ,
1112
1090
followAllRedirects : true ,
@@ -1143,7 +1121,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1143
1121
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290791)
1144
1122
this . deleteIssue = function ( issueNum , callback ) {
1145
1123
var options = {
1146
- rejectUnauthorized : this . strictSSL ,
1147
1124
uri : this . makeUri ( '/issue/' + issueNum ) ,
1148
1125
method : 'DELETE' ,
1149
1126
followAllRedirects : true ,
@@ -1181,7 +1158,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1181
1158
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290878)
1182
1159
this . updateIssue = function ( issueNum , issueUpdate , callback ) {
1183
1160
var options = {
1184
- rejectUnauthorized : this . strictSSL ,
1185
1161
uri : this . makeUri ( '/issue/' + issueNum ) ,
1186
1162
body : issueUpdate ,
1187
1163
method : 'PUT' ,
@@ -1242,7 +1218,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1242
1218
*/
1243
1219
this . listComponents = function ( project , callback ) {
1244
1220
var options = {
1245
- rejectUnauthorized : this . strictSSL ,
1246
1221
uri : this . makeUri ( '/project/' + project + '/components' ) ,
1247
1222
method : 'GET' ,
1248
1223
json : true
@@ -1282,7 +1257,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1282
1257
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290028)
1283
1258
this . addNewComponent = function ( component , callback ) {
1284
1259
var options = {
1285
- rejectUnauthorized : this . strictSSL ,
1286
1260
uri : this . makeUri ( '/component' ) ,
1287
1261
method : 'POST' ,
1288
1262
followAllRedirects : true ,
@@ -1325,7 +1299,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1325
1299
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290791)
1326
1300
this . deleteComponent = function ( componentNum , callback ) {
1327
1301
var options = {
1328
- rejectUnauthorized : this . strictSSL ,
1329
1302
uri : this . makeUri ( '/component/' + componentNum ) ,
1330
1303
method : 'DELETE' ,
1331
1304
followAllRedirects : true ,
@@ -1375,7 +1348,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1375
1348
*/
1376
1349
this . listFields = function ( callback ) {
1377
1350
var options = {
1378
- rejectUnauthorized : this . strictSSL ,
1379
1351
uri : this . makeUri ( '/field' ) ,
1380
1352
method : 'GET' ,
1381
1353
json : true
@@ -1423,7 +1395,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1423
1395
*/
1424
1396
this . listPriorities = function ( callback ) {
1425
1397
var options = {
1426
- rejectUnauthorized : this . strictSSL ,
1427
1398
uri : this . makeUri ( '/priority' ) ,
1428
1399
method : 'GET' ,
1429
1400
json : true
@@ -1500,7 +1471,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1500
1471
*/
1501
1472
this . listTransitions = function ( issueId , callback ) {
1502
1473
var options = {
1503
- rejectUnauthorized : this . strictSSL ,
1504
1474
uri : this . makeUri ( '/issue/' + issueId + '/transitions?expand=transitions.fields' ) ,
1505
1475
method : 'GET' ,
1506
1476
json : true
@@ -1541,7 +1511,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1541
1511
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290489)
1542
1512
this . transitionIssue = function ( issueNum , issueTransition , callback ) {
1543
1513
var options = {
1544
- rejectUnauthorized : this . strictSSL ,
1545
1514
uri : this . makeUri ( '/issue/' + issueNum + '/transitions' ) ,
1546
1515
body : issueTransition ,
1547
1516
method : 'POST' ,
@@ -1591,7 +1560,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1591
1560
*/
1592
1561
this . listProjects = function ( callback ) {
1593
1562
var options = {
1594
- rejectUnauthorized : this . strictSSL ,
1595
1563
uri : this . makeUri ( '/project' ) ,
1596
1564
method : 'GET' ,
1597
1565
json : true
@@ -1631,7 +1599,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1631
1599
// [Jira Doc](https://docs.atlassian.com/jira/REST/latest/#id108798)
1632
1600
this . addComment = function ( issueId , comment , callback ) {
1633
1601
var options = {
1634
- rejectUnauthorized : this . strictSSL ,
1635
1602
uri : this . makeUri ( '/issue/' + issueId + '/comment' ) ,
1636
1603
body : {
1637
1604
"body" : comment
@@ -1705,7 +1672,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1705
1672
newEstimate = false ;
1706
1673
}
1707
1674
var options = {
1708
- rejectUnauthorized : this . strictSSL ,
1709
1675
uri : this . makeUri ( '/issue/' + issueId + '/worklog' + ( newEstimate ? "?adjustEstimate=new&newEstimate=" + newEstimate : "" ) ) ,
1710
1676
body : worklog ,
1711
1677
method : 'POST' ,
@@ -1754,7 +1720,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1754
1720
this . deleteWorklog = function ( issueId , worklogId , callback ) {
1755
1721
1756
1722
var options = {
1757
- rejectUnauthorized : this . strictSSL ,
1758
1723
uri : this . makeUri ( '/issue/' + issueId + '/worklog/' + worklogId ) ,
1759
1724
method : 'DELETE' ,
1760
1725
followAllRedirects : true ,
@@ -1802,7 +1767,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1802
1767
*/
1803
1768
this . listIssueTypes = function ( callback ) {
1804
1769
var options = {
1805
- rejectUnauthorized : this . strictSSL ,
1806
1770
uri : this . makeUri ( '/issuetype' ) ,
1807
1771
method : 'GET' ,
1808
1772
json : true
@@ -1853,7 +1817,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1853
1817
*/
1854
1818
this . registerWebhook = function ( webhook , callback ) {
1855
1819
var options = {
1856
- rejectUnauthorized : this . strictSSL ,
1857
1820
uri : this . makeUri ( '/webhook' , 'rest/webhooks/' , '1.0' ) ,
1858
1821
method : 'POST' ,
1859
1822
json : true ,
@@ -1904,7 +1867,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1904
1867
*/
1905
1868
this . listWebhooks = function ( callback ) {
1906
1869
var options = {
1907
- rejectUnauthorized : this . strictSSL ,
1908
1870
uri : this . makeUri ( '/webhook' , 'rest/webhooks/' , '1.0' ) ,
1909
1871
method : 'GET' ,
1910
1872
json : true
@@ -1940,7 +1902,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1940
1902
// [Jira Doc](https://developer.atlassian.com/display/JIRADEV/JIRA+Webhooks+Overview)
1941
1903
this . getWebhook = function ( webhookID , callback ) {
1942
1904
var options = {
1943
- rejectUnauthorized : this . strictSSL ,
1944
1905
uri : this . makeUri ( '/webhook/' + webhookID , 'rest/webhooks/' , '1.0' ) ,
1945
1906
method : 'GET' ,
1946
1907
json : true
@@ -1976,7 +1937,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
1976
1937
// [Jira Doc](https://developer.atlassian.com/display/JIRADEV/JIRA+Webhooks+Overview)
1977
1938
this . deleteWebhook = function ( webhookID , callback ) {
1978
1939
var options = {
1979
- rejectUnauthorized : this . strictSSL ,
1980
1940
uri : this . makeUri ( '/webhook/' + webhookID , 'rest/webhooks/' , '1.0' ) ,
1981
1941
method : 'DELETE' ,
1982
1942
json : true
@@ -2025,7 +1985,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
2025
1985
*/
2026
1986
this . getCurrentUser = function ( callback ) {
2027
1987
var options = {
2028
- rejectUnauthorized : this . strictSSL ,
2029
1988
uri : this . makeUri ( '/session' , 'rest/auth/' , '1' ) ,
2030
1989
method : 'GET' ,
2031
1990
json : true
@@ -2116,7 +2075,6 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
2116
2075
*/
2117
2076
this . getBacklogForRapidView = function ( rapidViewId , callback ) {
2118
2077
var options = {
2119
- rejectUnauthorized : this . strictSSL ,
2120
2078
uri : this . makeUri ( '/xboard/plan/backlog/data?rapidViewId=' + rapidViewId , 'rest/greenhopper/' ) ,
2121
2079
method : 'GET' ,
2122
2080
json : true
0 commit comments