Skip to content

Commit

Permalink
Hardcode bot username rather than querying the GitHub API for it (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipj authored Mar 28, 2019
1 parent 690a55d commit 4f4ac43
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 56 deletions.
15 changes: 1 addition & 14 deletions lib/bot-username.js
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
const memoize = require('async').memoize

const githubClient = require('./github-client')

function requestGitHubForUsername (cb) {
githubClient.users.get({}, (err, currentUser) => {
if (err) {
return cb(err)
}
cb(null, currentUser.login)
})
}

exports.resolve = memoize(requestGitHubForUsername)
module.exports = 'nodejs-github-bot'
24 changes: 5 additions & 19 deletions scripts/trigger-jenkins-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ const { createPrComment } = require('../lib/github-comment')

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

function ifBotWasMentionedInCiComment (commentBody, cb) {
botUsername.resolve((err, username) => {
if (err) {
return cb(err)
}

const atBotName = new RegExp(`^@${username} run CI`, 'mi')
const wasMentioned = commentBody.match(atBotName) !== null

cb(null, wasMentioned)
})
function wasBotMentionedInCiComment (commentBody) {
const atBotName = new RegExp(`^@${botUsername} run CI`, 'mi')
return commentBody.match(atBotName) !== null
}

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

ifBotWasMentionedInCiComment(comment.body, (err, wasMentioned) => {
if (err) {
return logger.error(err, 'Error while checking if the bot username was mentioned in a comment')
}

if (!wasMentioned) return

if (wasBotMentionedInCiComment(comment.body)) {
triggerBuildIfValid(options)
})
}
}

function handlePullCreated (event, owner, repo) {
Expand Down
23 changes: 0 additions & 23 deletions test/unit/bot-username.test.js

This file was deleted.

0 comments on commit 4f4ac43

Please sign in to comment.