diff --git a/scripts/assign-new-pr-to-review.js b/scripts/assign-new-pr-to-review.js index 03d04a5..162c328 100644 --- a/scripts/assign-new-pr-to-review.js +++ b/scripts/assign-new-pr-to-review.js @@ -16,7 +16,7 @@ module.exports = function(robot) { - const context = require('./github-context.js'); + const gitHubContext = require('./github-context.js'); return robot.on("github-repo-event", function(repo_event) { const githubPayload = repo_event.payload; @@ -24,21 +24,21 @@ module.exports = function(robot) { switch(repo_event.eventType) { case "pull_request": // Make sure we don't listen to our own messages - if (context.equalsRobotName(robot, githubPayload.pull_request.user.login)) { return; } + if (gitHubContext.equalsRobotName(robot, githubPayload.pull_request.user.login)) { return; } var { action } = githubPayload; if (action === "opened") { // A new PR was opened - return assignPullRequestToReview(context, githubPayload, robot); + return assignPullRequestToReview(gitHubContext, githubPayload, robot); } break; } }); }; -async function assignPullRequestToReview(context, githubPayload, robot) { - const github = context.github(); - const githubConfig = context.config(); +async function assignPullRequestToReview(gitHubContext, githubPayload, robot) { + const github = gitHubContext.api(); + const githubConfig = gitHubContext.config(); const ownerName = githubPayload.repository.owner.login; const repoName = githubPayload.repository.name; const prNumber = githubPayload.pull_request.number; diff --git a/scripts/bot-initialization.js b/scripts/bot-initialization.js index d64026c..99b4a16 100644 --- a/scripts/bot-initialization.js +++ b/scripts/bot-initialization.js @@ -9,11 +9,11 @@ module.exports = function(robot) { robot.brain.on('loaded', function() { - const context = require('./github-context.js'); + const gitHubContext = require('./github-context.js'); appID = robot.brain.get("github-app_id"); if (appID) { - context.initialize(robot, appID); + gitHubContext.initialize(robot, appID); robot.logger.debug("Bot ready"); } else { diff --git a/scripts/github-context.js b/scripts/github-context.js index bc73845..7fa578f 100644 --- a/scripts/github-context.js +++ b/scripts/github-context.js @@ -19,7 +19,7 @@ let githubConfig = null; module.exports = { - github() { return githubAPI; }, + api() { return githubAPI; }, config() { return githubConfig; }, diff --git a/scripts/github-installation.js b/scripts/github-installation.js index cad2e7b..25de660 100644 --- a/scripts/github-installation.js +++ b/scripts/github-installation.js @@ -10,7 +10,7 @@ module.exports = function(robot) { - const context = require('./github-context.js'); + const gitHubContext = require('./github-context.js'); return robot.on("github-repo-event", async function(repo_event) { const githubPayload = repo_event.payload; @@ -20,7 +20,7 @@ module.exports = function(robot) { switch(repo_event.eventType) { case "integration_installation": // Make sure we don't listen to our own messages - if (context.equalsRobotName(robot, githubPayload.sender.login)) { return; } + if (gitHubContext.equalsRobotName(robot, githubPayload.sender.login)) { return; } var { action } = githubPayload; switch (action) { @@ -32,7 +32,7 @@ module.exports = function(robot) { robot.brain.set('github-app_id', githubPayload.installation.app_id); robot.brain.set('github-app_repositories', githubPayload.repositories.map((x) => x.full_name).join()); - context.initialize(robot, githubPayload.installation.app_id); + gitHubContext.initialize(robot, githubPayload.installation.app_id); var perms = githubPayload.installation.permissions; if (perms.repository_projects !== 'write') { robot.logger.error(formatPermMessage('repository_projects', 'write')); } @@ -44,7 +44,7 @@ module.exports = function(robot) { robot.logger.error("Please enable 'pull_request' events in the app configuration on github.com"); } - await createAccessToken(robot, context.github(), githubPayload.installation.id); + await createAccessToken(robot, gitHubContext.api(), githubPayload.installation.id); break; case "deleted": // App was uninstalled from an organization diff --git a/scripts/greet-new-contributor.js b/scripts/greet-new-contributor.js index 0456b91..fffcd85 100644 --- a/scripts/greet-new-contributor.js +++ b/scripts/greet-new-contributor.js @@ -11,7 +11,7 @@ module.exports = function(robot) { - const context = require('./github-context.js'); + const gitHubContext = require('./github-context.js'); return robot.on("github-repo-event", function(repo_event) { const githubPayload = repo_event.payload; @@ -19,22 +19,22 @@ module.exports = function(robot) { switch(repo_event.eventType) { case "pull_request": // Make sure we don't listen to our own messages - if (context.equalsRobotName(robot, githubPayload.pull_request.user.login)) { return; } + if (gitHubContext.equalsRobotName(robot, githubPayload.pull_request.user.login)) { return; } var { action } = githubPayload; if (action === "opened") { // A new PR was opened - return greetNewContributor(context, githubPayload, robot); + return greetNewContributor(gitHubContext, githubPayload, robot); } break; } }); }; -async function greetNewContributor(context, githubPayload, robot) { +async function greetNewContributor(gitHubContext, githubPayload, robot) { // TODO: Read the welcome message from a (per-repo?) file (e.g. status-react.welcome-msg.md) - const github = context.github(); - const welcomeMessage = context.config()['pull-requests']['welcome-bot'].message; + const github = gitHubContext.api(); + const welcomeMessage = gitHubContext.config()['pull-requests']['welcome-bot'].message; const ownerName = githubPayload.repository.owner.login; const repoName = githubPayload.repository.name; const prNumber = githubPayload.pull_request.number;