forked from telefonicaid/scrumit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigbrother.js
82 lines (73 loc) · 2.38 KB
/
bigbrother.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
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const jiraconfig = require('./jiraconfig')
if (jiraconfig.jiraUserName) {
const JiraClient = require('jira-connector')
const jira = new JiraClient({
host: 'jirapdi.tid.es',
basic_auth: {
username: jiraconfig.jiraUserName,
password: jiraconfig.jiraPassword
}
})
module.exports.askTo = function (user) {
return new Promise((fulfill, reject) => {
let question = 'Hi ' + user + ', currently JIRA says you are working on these issues...\n'
opts = {jql: 'assignee=' + user + ' and status = "In Progress"'}
console.log(opts.jql)
jira.search.search(opts, (error, issues) => {
if (error) {
console.log(error)
reject(error)
}
console.log(issues)
var issuesList = issues.issues
if (issuesList.length == 0) {
console.log('Rejecting with...' + issues.warningMessages)
reject(issues.warningMessages)
}
console.log(issues)
var issuesList = issues.issues
for (const index in issuesList) {
const issueQuestion = issuesList[index].key + ' -> ' + issuesList[index].fields.summary
console.log(issueQuestion)
question += '\n ' + issueQuestion
}
if (issuesList.length > 2) {
question += "\n More than 2 issues? please, don't make me cry...."
}
question += '\n Tell me what you are currently working on... ^_^ '
fulfill(question)
})
})
}
module.exports.getUsername = function (realname) {
console.log('[getUsername] ' + realname)
return new Promise((fulfill, reject) => {
const opts = {username: realname}
console.log('[getUsername] opts=' + opts + ' ' + realname)
jira.user.search(opts, (error, user) => {
console.log('[getUsername] Response: ' + error + ', ' + user)
if (error) {
reject('not found')
}
if (user.length > 0) {
fulfill(user[0].key)
} else {
reject('empty, why?')
}
})
})
}
} else {
module.exports.askTo = function (user) {
return new Promise((fulfill, reject) => {
fulfill('Hi ' + user + ', tell me what you are currently working on...\n')
return
})
}
module.exports.getUsername = function (realname) {
return new Promise((fulfill, reject) => {
return 'unknown'
})
}
}