From cdec42c0b19858e14c7032d94ed4a9b4c5216b09 Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Fri, 18 Jan 2019 16:42:22 +0100 Subject: [PATCH] Remove entry from `pendingChecks` on `check_suite.completed` - to gracefully handle concurrent bots --- src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/index.ts b/src/index.ts index 0af6652..7a678e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ const pendingChecks: any = [] export = (app: Application) => { app.on(['check_suite.requested'], async (context) => { await checkSuiteAsync(context, context.payload.check_suite) }) + app.on(['check_suite.completed'], async (context) => { delete pendingChecks[context.payload.check_suite.head_sha] }) app.on(['check_run.rerequested'], async (context) => { const { check_suite } = context.payload.check_run await checkSuiteAsync(context, check_suite) @@ -103,6 +104,11 @@ async function queueCheckAsync (context: Context, checkSuite: Octokit.ChecksCrea context.log.info(`Starting analysis of ${files.length} files (before: ${before}, head: ${headSHA})`) let check = pendingChecks[headSHA] + if (!check) { + // Check must have been finished by another bot instance, do nothing + return + } + const packageFilenameRegex = /^(.*\/)?package\.json(.orig)?$/g if (!check.output) {