Skip to content

Commit

Permalink
Upgrade probot (#95)
Browse files Browse the repository at this point in the history
* get tests passing

* simplify tests
  • Loading branch information
mfix22 authored Nov 14, 2020
1 parent ea787b8 commit f4107b9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 44 deletions.
54 changes: 26 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ const verifyPaymentPlan = require('./src/verify-payment-plan')
// Probot will also send errors to Sentry DNS: https://probot.github.io/docs/configuration/
Sentry.init({ dsn: process.env.SENTRY_DSN })

module.exports = async (robot) => {
robot.route('/').get('/health', (req, res) => res.send('OK'))
module.exports = async ({ app, getRouter }) => {
const router = getRouter('/')
router.get('/health', (req, res) => res.send('OK'))

if (process.env.NODE_ENV !== 'test') {
process.on('uncaughtException', (e) => {
robot.log.error(e)
app.log.error(e)
})
process.on('unhandledRejection', (e) => {
robot.log.error(e)
app.log.error(e)
})
}

Expand All @@ -53,30 +54,30 @@ module.exports = async (robot) => {
try {
switch (job.data.action) {
case COMMENT:
return await threadLabeled.process(robot)(job)
return await threadLabeled.process(app)(job)
case MERGE:
return await pullLabeled.process(robot)(job)
return await pullLabeled.process(app)(job)
case CLOSE:
default:
return await issueLabeled.process(robot)(job)
return await issueLabeled.process(app)(job)
}
} catch (error) {
if (process.env.NODE_ENV !== 'test') {
robot.log(error, job)
app.log(error, job)
}
throw error
}
})

queue.on('succeeded', (job, result) => {
robot.log.debug(`Job ${job.id} succeeded with result: ${JSON.stringify(result, null, 2)}`)
app.log.debug(`Job ${job.id} succeeded with result: ${JSON.stringify(result, null, 2)}`)
})

queue.on('failed', (job, err) => {
if (err.message === 'Retry job') {
return
}
robot.log.error(
app.log.error(
`Job ${job.id} with data ${JSON.stringify(job.data, null, 2)} failed with error ${
err.message
}`
Expand All @@ -91,23 +92,23 @@ module.exports = async (robot) => {

function wrapPaymentCheck(fn) {
return async (context) => {
if (await verifyPaymentPlan(robot, context)) {
if (await verifyPaymentPlan(app, context)) {
fn(context)
}
}
}

// Listeners
robot.on(
app.on(
// All pull requests are issues in GitHub REST V3
['issues.labeled', 'issues.unlabeled', 'pull_request.labeled', 'pull_request.unlabeled'],
wrapPaymentCheck(threadLabeled(queue))
)
robot.on(['issues.opened', 'pull_request.opened'], wrapPaymentCheck(threadOpened(queue)))
app.on(['issues.opened', 'pull_request.opened'], wrapPaymentCheck(threadOpened(queue)))

robot.on(['issues.labeled', 'issues.unlabeled'], wrapPaymentCheck(issueLabeled(queue)))
app.on(['issues.labeled', 'issues.unlabeled'], wrapPaymentCheck(issueLabeled(queue)))

robot.on(
app.on(
[
'pull_request.labeled',
'pull_request.unlabeled',
Expand All @@ -119,23 +120,20 @@ module.exports = async (robot) => {
)
// TODO rerun pull labeled job on `check_suite.completed`

robot.on(['issue_comment.created', 'issue_comment.edited'], wrapPaymentCheck(commentCreated()))
app.on(['issue_comment.created', 'issue_comment.edited'], wrapPaymentCheck(commentCreated()))

robot.on('pull_request.closed', wrapPaymentCheck(pullMerged.deleteBranch()))
robot.on('pull_request.closed', wrapPaymentCheck(pullMerged.createTag()))
app.on('pull_request.closed', wrapPaymentCheck(pullMerged.deleteBranch()))
app.on('pull_request.closed', wrapPaymentCheck(pullMerged.createTag()))

robot.on(
['pull_request.opened', 'pull_request.synchronize'],
wrapPaymentCheck(pullSynchronized())
)
app.on(['pull_request.opened', 'pull_request.synchronize'], wrapPaymentCheck(pullSynchronized()))

// Kill job when issue/pull is closed
robot.on(['issues.closed', 'pull_request.closed'], threadClosed(queue))
app.on(['issues.closed', 'pull_request.closed'], threadClosed(queue))

robot.on('issue_comment.deleted', commentDeleted(queue))
app.on('issue_comment.deleted', commentDeleted(queue))

robot.on(['installation.created'], installationCreated(robot))
robot.on(['installation_repositories.added', 'installation.created'], installationAdded(robot))
app.on(['installation.created'], installationCreated(app))
app.on(['installation_repositories.added', 'installation.created'], installationAdded(app))
// TODO 'marketplace_purchase.purchased'

// TODO use status updates to retrigger merge jobs
Expand All @@ -147,6 +145,6 @@ module.exports = async (robot) => {
// To get your app running against GitHub, see:
// https://probot.github.io/docs/development/

robot.queue = queue
robot.analytics = analytics
app.queue = queue
app.analytics = analytics
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lodash.merge": "^4.6.2",
"moment": "^2.29.1",
"ms": "^2.1.1",
"probot": "10.9.5",
"probot": "10.14.0",
"rexrex": "^1.3.0",
"smee-client": "^1.2.2",
"windsor-node": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ beforeEach(async () => {
},
}
}),
auth: () => Promise.resolve(github),
}

robot.state.octokit = github

app = robot.load(ranger)
app.auth = () => Promise.resolve(github)
queue = app.queue

jest.spyOn(app.analytics, 'identify')
Expand Down
45 changes: 31 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,16 @@
"@types/yargs" "^15.0.0"
chalk "^4.0.0"

"@octokit/auth-app@^2.4.14":
version "2.7.0"
resolved "https://registry.yarnpkg.com/@octokit/auth-app/-/auth-app-2.7.0.tgz#a1bec2f0da80c4435cdd3213020e7f7c4364c688"
integrity sha512-znx092EpYmtEr5UjRXrFGGinA3jWJNriKT/N3CZFbx53JfXNsHqKW8UogyuJwob55JAgEzwhRTra/yy6e+AcfQ==
"@octokit/auth-app@^2.10.0":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@octokit/auth-app/-/auth-app-2.10.1.tgz#187fe2432e6089f919fff8f5574dd2154c673962"
integrity sha512-WQAbhPtr+cuMcMCt0cu9NgY0XjEEEqeR3/A5hJK3KNdYglxRRf3+uKwNxcK9B3SgpS8Igi6UvatTmGow88w+cA==
dependencies:
"@octokit/request" "^5.3.0"
"@octokit/request-error" "^2.0.0"
"@octokit/types" "^5.0.0"
"@types/lru-cache" "^5.1.0"
deprecation "^2.3.1"
lru-cache "^6.0.0"
universal-github-app-jwt "^1.0.1"
universal-user-agent "^6.0.0"
Expand All @@ -871,10 +872,17 @@
dependencies:
"@octokit/types" "^2.0.0"

"@octokit/auth-unauthenticated@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@octokit/auth-unauthenticated/-/auth-unauthenticated-1.0.0.tgz#07ae30bb13c61deb61566ce79befc1096573c768"
integrity sha512-jVgSHBEmY1mA7WoK+LfEwtjhAd8VKt2AAWJcivZICDAoYe5iQJ9PaLF+5BxHQXZ1Gs85GU8hsZS/FyQa+0H7Ug==
"@octokit/auth-token@^2.4.2":
version "2.4.3"
resolved "https://registry.yarnpkg.com/@octokit/auth-token/-/auth-token-2.4.3.tgz#b868b5f2366533a7e62933eaa1181a8924228cc4"
integrity sha512-fdGoOQ3kQJh+hrilc0Plg50xSfaCKOeYN9t6dpJKXN9BxhhfquL0OzoQXg3spLYymL5rm29uPeI3KEXRaZQ9zg==
dependencies:
"@octokit/types" "^5.0.0"

"@octokit/auth-unauthenticated@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@octokit/auth-unauthenticated/-/auth-unauthenticated-2.0.0.tgz#020d9892f9d476b0e53852ddb405d33b26a5e098"
integrity sha512-AV2AMjEVVANyRtII09ksEIsIUWbyVrWXDBP4fZnbqfKjeW6feZkkAP7wjwChgLevRevu17w4KD0nzD5b6Nkrgw==
dependencies:
"@octokit/request-error" "^2.0.2"
"@octokit/types" "^5.0.0"
Expand Down Expand Up @@ -5755,6 +5763,16 @@ object.values@^1.1.1:
function-bind "^1.1.1"
has "^1.0.3"

octokit-auth-probot@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/octokit-auth-probot/-/octokit-auth-probot-1.2.0.tgz#8f221956a4834c276b2e86b26a5e1987bc7349ea"
integrity sha512-BTiQlM5Yf5RQOUyJnEuqI5umNjjTtKqs1AY4SPM4gD2Gjcp1fuS2MzyYHoGyb0bhsvqVzFB0TNM5VhzAGQsxuw==
dependencies:
"@octokit/auth-app" "^2.10.0"
"@octokit/auth-token" "^2.4.2"
"@octokit/auth-unauthenticated" "^2.0.0"
"@octokit/types" "^5.5.0"

[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/octokit-pagination-methods/-/octokit-pagination-methods-1.1.0.tgz#cf472edc9d551055f9ef73f6e42b4dbb4c80bea4"
Expand Down Expand Up @@ -6192,13 +6210,11 @@ pretty-format@^26.6.2:
ansi-styles "^4.0.0"
react-is "^17.0.1"

probot@10.9.5:
version "10.9.5"
resolved "https://registry.yarnpkg.com/probot/-/probot-10.9.5.tgz#10856bc50f33322f80fad744473c7b44c602c641"
integrity sha512-IQ/E2G5EDY3YlmBmg5B7Mi0nW+PRt4gEyDIDR2r+KZSzAbA2VHSAjaL4X2PP0uECsNzt5/BXTHexVAaHToa4kA==
probot@10.14.0:
version "10.14.0"
resolved "https://registry.yarnpkg.com/probot/-/probot-10.14.0.tgz#0f0ee621b7428b34b5898c8c79c394ebcb0d3c5a"
integrity sha512-nCsLiilJqdE/0GwWDWH/4pTMEgVJnGAqwVVO/9HIYhtl1p4YM1jUIsHCFks6Z6dBxQU/v4iDrYyxFgg2GwVwbQ==
dependencies:
"@octokit/auth-app" "^2.4.14"
"@octokit/auth-unauthenticated" "^1.0.0"
"@octokit/core" "^3.1.0"
"@octokit/graphql" "^4.2.0"
"@octokit/plugin-enterprise-compatibility" "^1.2.1"
Expand Down Expand Up @@ -6230,6 +6246,7 @@ [email protected]:
js-yaml "^3.13.1"
jsonwebtoken "^8.1.0"
lru-cache "^6.0.0"
octokit-auth-probot "^1.2.0"
octokit-pagination-methods "1.1.0"
pino "^6.5.0"
pino-http "^5.2.0"
Expand Down

0 comments on commit f4107b9

Please sign in to comment.