Skip to content

Commit 4f4ac43

Browse files
authored
Hardcode bot username rather than querying the GitHub API for it (#227)
Refs #226 (comment)
1 parent 690a55d commit 4f4ac43

File tree

3 files changed

+6
-56
lines changed

3 files changed

+6
-56
lines changed

lib/bot-username.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
1-
const memoize = require('async').memoize
2-
3-
const githubClient = require('./github-client')
4-
5-
function requestGitHubForUsername (cb) {
6-
githubClient.users.get({}, (err, currentUser) => {
7-
if (err) {
8-
return cb(err)
9-
}
10-
cb(null, currentUser.login)
11-
})
12-
}
13-
14-
exports.resolve = memoize(requestGitHubForUsername)
1+
module.exports = 'nodejs-github-bot'

scripts/trigger-jenkins-build.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,9 @@ const { createPrComment } = require('../lib/github-comment')
88

99
const jenkinsApiCredentials = process.env.JENKINS_API_CREDENTIALS || ''
1010

11-
function ifBotWasMentionedInCiComment (commentBody, cb) {
12-
botUsername.resolve((err, username) => {
13-
if (err) {
14-
return cb(err)
15-
}
16-
17-
const atBotName = new RegExp(`^@${username} run CI`, 'mi')
18-
const wasMentioned = commentBody.match(atBotName) !== null
19-
20-
cb(null, wasMentioned)
21-
})
11+
function wasBotMentionedInCiComment (commentBody) {
12+
const atBotName = new RegExp(`^@${botUsername} run CI`, 'mi')
13+
return commentBody.match(atBotName) !== null
2214
}
2315

2416
// Name for the Jenkins job should be triggered for a given repository
@@ -123,15 +115,9 @@ function handleCommentCreated (event, owner, repo) {
123115
author: commentAuthor
124116
}
125117

126-
ifBotWasMentionedInCiComment(comment.body, (err, wasMentioned) => {
127-
if (err) {
128-
return logger.error(err, 'Error while checking if the bot username was mentioned in a comment')
129-
}
130-
131-
if (!wasMentioned) return
132-
118+
if (wasBotMentionedInCiComment(comment.body)) {
133119
triggerBuildIfValid(options)
134-
})
120+
}
135121
}
136122

137123
function handlePullCreated (event, owner, repo) {

test/unit/bot-username.test.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)