Skip to content
Open
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
18 changes: 9 additions & 9 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
// External dependencies
const fs = require("fs")
const path = require("path")
const yaml = require("js-yaml")
const express = require("express")
const { createWebhooksApi } = require("@octokit/webhooks")
const { createAppAuth } = require("@octokit/auth-app")
const { graphql } = require("@octokit/graphql")

// Local dependencies
const smeeClient = require(path.join(__dirname, "smee.js"))
const emojify = require(path.join(__dirname, "emojify.js"))
const hasCommand = require(path.join(__dirname, "command.js"))
const updateBodyMutationFor = require(path.join(__dirname, "mutations.js"))
const smeeClient = require("./smee")
const emojify = require("./emojify")
const hasCommand = require("./command")
const updateBodyMutationFor = require("./mutations")

// Setup
const port = 64897
const app = express()
const privateKey = fs.readFileSync("gh-app.pem", "utf8")
const config = JSON.parse(fs.readFileSync("config.json", "utf8"))
const config = require('../config.json')
var emojifierConfig = yaml.safeLoad(fs.readFileSync("emojifier-default.yml", "utf8"))

const smee = smeeClient(config.webproxy_url, port)
Expand All @@ -30,15 +29,16 @@ app.use(webhooks.middleware)

webhooks.on(["issue_comment.created", "issues.opened", "pull_request.opened"], async (event) => {
const { payload } = event
const auth = await createAppAuth({
const auth = createAppAuth({
id: config.github_app_id,
privateKey: privateKey,
installationId: payload.installation.id
})

const { token } = await auth({ type: "installation" });
const graphqlWithAuth = graphql.defaults({
request: {
hook: auth.hook
headers: {
authorization: `token ${token}`
}
})

Expand Down