This repository has been archived by the owner on Nov 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
service.js
64 lines (57 loc) · 1.52 KB
/
service.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
const request = require("request-promise-native");
class JIRAService {
constructor({ hostname, username, password }) {
this.jiraAPI = request.defaults({
baseUrl: `https://${username}:${password}@${hostname}/rest/api/latest`,
json: true
});
}
set opts({ hostname, username, password }) {
this.jiraAPI = request.defaults({
baseUrl: `https://${username}:${password}@${hostname}/rest/api/latest`,
json: true
});
}
async fetchMyJIRAIssues() {
const { issues = [] } = await this.jiraAPI({
url: "/search",
qs: {
jql: "assignee=currentuser()",
fields: "status,summary"
}
});
return Promise.all(
issues
.filter(issue => issue.fields.status.statusCategory.id !== 3)
.map(async ({ fields: { summary, status }, key }) => ({
summary,
key,
status: status.statusCategory,
transitions: await this.fetchTransitions(key)
}))
);
}
async fetchTransitions(id) {
const { transitions = [] } = await this.jiraAPI(`/issue/${id}/transitions`);
return transitions.map(({ id, name }) => ({ id, name }));
}
async doTransition(id, toState) {
let success;
try {
await this.jiraAPI.post({
url: `/issue/${id}/transitions`,
json: true,
body: {
transition: {
id: toState.toString()
}
}
});
success = true;
} catch (error) {
success = false;
}
return success;
}
}
module.exports = JIRAService;