Skip to content

Commit 67a9c81

Browse files
committed
FIX #14 Multiple random messages
1 parent 866c9e0 commit 67a9c81

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
const defaultConfig = {
2-
requestInfoReplyComment: 'The maintainers of this repository would appreciate it if you could provide more information.',
3-
requestInfoOn: {
4-
issue: true,
5-
pullRequest: true
6-
}
7-
}
1+
const getComment = require('./lib/getComment')
2+
const defaultConfig = require('./lib/defaultConfig')
83

94
module.exports = robot => {
105
robot.on('pull_request.opened', receive)
@@ -35,7 +30,8 @@ module.exports = robot => {
3530
}
3631
}
3732
if (!body || badTitle) {
38-
context.github.issues.createComment(context.issue({body: config.requestInfoReplyComment || defaultConfig.requestInfoReplyComment}))
33+
const comment = getComment(config.requestInfoReplyComment, defaultConfig.requestInfoReplyComment)
34+
context.github.issues.createComment(context.issue({body: comment}))
3935

4036
if (config.requestInfoLabelToAdd) {
4137
// Add label if there is one listed in the yaml file

lib/defaultConfig.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const defaultConfig = {
2+
requestInfoReplyComment: 'The maintainers of this repository would appreciate it if you could provide more information.',
3+
requestInfoOn: {
4+
issue: true,
5+
pullRequest: true
6+
}
7+
}
8+
9+
module.exports = defaultConfig

lib/getComment.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = getComment
2+
3+
function getComment (comment, defaultComment) {
4+
// comment can be either a string or an array
5+
6+
if (!comment) {
7+
comment = defaultComment
8+
}
9+
10+
if (typeof comment === 'string' || comment instanceof String) {
11+
return comment
12+
} else {
13+
const pos = getRandomInt(0, comment.length)
14+
return comment[pos] || defaultComment
15+
}
16+
}
17+
18+
function getRandomInt (min, max) {
19+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
20+
// The maximum is exclusive and the minimum is inclusive
21+
22+
min = Math.ceil(min)
23+
max = Math.floor(max)
24+
return Math.floor(Math.random() * (max - min)) + min
25+
}

0 commit comments

Comments
 (0)