-
Notifications
You must be signed in to change notification settings - Fork 3
/
jira.js
123 lines (88 loc) · 2.53 KB
/
jira.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Jira
* To define reusable methods to call the most used apis
*
* @author Mohammad Fares <[email protected]>
*/
/**
* Get a list of avaliable projects
*
* @return {Promise} resolve with [{id,key,name,type}, ..]
*/
function getProjects() {
return di.api.get('/rest/api/2/project').then(function(result) {
// The keys that we want to include
var keys = ['id', 'key', 'name'];
// Format the result
result = di.lodash.map(result, function(record) {
// Pick keys
record = di.lodash.pick(record, keys);
record.type = 'scrum';
return record;
});
return result;
});
};
/**
* Get a list of avaliable versions
*
* @param {String} projectIdOrKey
* @return {Promise} resolve with [{id,description,name,archived,released}, ..]
*/
function getVersions(projectIdOrKey) {
return di.api.get('/rest/api/2/project/:projectIdOrKey/versions', {
projectIdOrKey: projectIdOrKey
}).then(function(result) {
// The keys that we want to include
var keys = ['id', 'description', 'name', 'archived', 'released'];
// Format the result
result = di.lodash.map(result, function(record) {
// Set the empty keys to null
record = di.lodash.defaults(record, {'description': null});
// Pick keys
record = di.lodash.pick(record, keys);
return record;
});
// Reverse
result = di.lodash.reverse(result);
return result;
});
};
/**
* Get a list of all active issues
*
* - scrum: get the issues of the current sprint.
* - kanban: get all issues.
*
* @param {String} projectIdOrKey
* @param {String} type scrum, kanban
* @return {Promise}
*/
function getActiveIssues(projectIdOrKey, type) {
// Sprints based project
if (type == 'scrum') {
var query = `project = ${projectIdOrKey} AND sprint in openSprints()`;
} else {
var query = `project = ${projectIdOrKey}`;
}
return di.api.get('/rest/api/2/search', {
jql: query,
fields: 'project,summary,description,status'
}).then(function(result) {
// Format the result
result.issues = di.lodash.map(result.issues, function(object) {
// Add the summary
object.summary = object.fields.summary;
return object;
});
return result.issues;
})
};
////////////////////////////////////////////////////
// Module //////////////////////////////////////////
////////////////////////////////////////////////////
module.exports = {
getProjects: getProjects,
getVersions: getVersions,
getActiveIssues: getActiveIssues
};