Rename `context` to `gitHubContext`

This commit is contained in:
Pedro Pombeiro 2018-01-18 18:54:54 +01:00
parent 9f2b025232
commit 4026db0b15
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
5 changed files with 19 additions and 19 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -19,7 +19,7 @@ let githubConfig = null;
module.exports = {
github() { return githubAPI; },
api() { return githubAPI; },
config() { return githubConfig; },

View File

@ -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

View File

@ -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;