Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardcode bot username rather than querying the GitHub API for it #227

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.