-
Notifications
You must be signed in to change notification settings - Fork 6
/
service.js
59 lines (53 loc) · 2.08 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
const assigneesMap = require('./consts').assignees
const github = require('./github')
const comments = require('./consts').comment
module.exports = {
async addAssignees(ctx, issue) {
const labels = issue.labels
const assignees = []
labels.forEach(label => {
if (label.name.indexOf('component:') > -1 && assigneesMap[label.name]) {
assignees.push(assigneesMap[label.name])
}
})
if (assignees.length) {
await github.addAssignees(issue, `[${ assignees.map(a => `"${ a }"`).join(', ') }]`)
}
ctx.body = `This issue is labelled. Added ${ assignees.length } assignees.`
},
async translate(ctx, issue) {
ctx.body += ' It\'s in Chinese.'
const { title, body } = issue
let newTitle = await github.translate(title)
newTitle = JSON.parse(newTitle.body)
if (newTitle.trans_result && newTitle.trans_result[0] && newTitle.trans_result[0].dst) {
await github.changeTitle(issue, newTitle.trans_result[0].dst)
}
ctx.body += ` Title changed: ${ newTitle.trans_result[0].dst }.`
let comment = ''
let translatedBody = await github.translate(body.replace(/<\!-- generated by https:\/\/eleme-issue\.surge\.sh DO NOT REMOVE -->/g, ''))
translatedBody = JSON.parse(translatedBody.body)
if (translatedBody.trans_result) {
translatedBody.trans_result.forEach((line, index) => {
comment += `${ line.dst.replace('] (', '](') }\\n${ index % 2 === 1 ? '\\n' : '' }`
})
}
if (comment.length > 0) {
comment = 'Translation of this issue:\\n\\n' + comment
await github.commentIssue(issue, comment.replace(/"/g, '\\"'))
ctx.body += ` Content translated: ${ comment }.`
}
},
async referToFaq(ctx, issue) {
const comment = comments.faq.en
ctx.body += ' Answer can be found in FAQ.'
await github.commentIssue(issue, comment)
await github.closeIssue(issue)
ctx.body += ' Commented and closed.'
},
async notifyEmptyFiddle(ctx, issue) {
let comment = comments.invalidFiddle.en
ctx.body += ' But the fiddle is invalid.'
await github.commentIssue(issue, comment)
}
}