{"record":{"id":"34746ed10a965f7b","repo":"koala73/worldmonitor","slug":"a-pull-request-payload-is-required","errorCode":null,"errorMessage":"a pull_request payload is required","messagePattern":"a pull_request payload is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/check-stacked-merge.mjs","lineNumber":365,"sourceCode":"      if (pull.number != null) {\n        issueClient.comment(pull.number, formatOrphanComment({\n          pull, mergeSha, defaultBranch, parents, reason: verdict.reason,\n        }));\n      }\n    }\n  }\n\n  return {\n    ...verdict,\n    parents,\n    existingIssue,\n    exitCode: verdict.ok ? 0 : 1,\n    ...(!verdict.ok && { annotation: postMergeAnnotation(verdict, mergeSha, defaultBranch) }),\n  };\n}\n\nexport function checkClosedPull({ event, gh, git, issues, sleep } = {}) {\n  if (!event?.pull_request) throw new Error('a pull_request payload is required');\n  const repository = repositoryFromEvent(event);\n  const queue = [event.pull_request];\n  const visited = new Set();\n  const results = [];\n  for (const pull of queue) {\n    if (visited.has(pull.number)) continue;\n    visited.add(pull.number);\n    const result = checkStackedMerge({\n      mode: 'post-merge', event: { ...event, pull_request: pull }, gh, git, issues, sleep,\n    });\n    results.push({ pullNumber: pull.number, ...result });\n    if (!pull.head?.ref || pull.head.repo?.full_name !== repository) continue;\n    const children = flattenGhPages(gh([\n      'api', '--paginate', '--slurp',\n      `repos/${repository}/pulls?state=closed&base=${encodeURIComponent(pull.head.ref)}`,\n    ]));\n    queue.push(...children.filter((child) => isMergedPull(child)\n      && (!child.base?.repo?.full_name || child.base.repo.full_name === repository)));","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/scripts/check-stacked-merge.mjs#L347-L383","documentation":"checkClosedPull validates that the GitHub webhook event object passed in actually contains a pull_request payload before analyzing a merged/closed PR stack. The library throws this when event exists (or is undefined) but event.pull_request is missing, because every downstream step (repository resolution, queue traversal, verdict computation) depends on PR fields like number and merge info. It is an upfront contract check on the caller-supplied event.","triggerScenarios":"Calling checkClosedPull({ event }) where event is a non-pull_request GitHub event (e.g. push, issues), where event is an empty object {}, or where event is undefined/null and the default {} destructure applies.","commonSituations":"Wiring the handler to the wrong GitHub Actions event name (e.g. 'push' instead of 'pull_request'), reading the event JSON from a path that contains a different payload, or a workflow_dispatch invocation where no pull_request context exists.","solutions":["Trigger the workflow on pull_request (or pass a pull_request webhook payload) so event.pull_request is populated.","If loading event JSON manually, point at the correct github.event_path file containing a pull_request payload.","Guard the call: only invoke checkClosedPull when event?.pull_request is truthy, or skip with a clear log for non-PR events."],"exampleFix":"// before\ncheckClosedPull({ event: github.event, gh, git, issues, sleep });\n// after\nif (github.event?.pull_request) {\n  checkClosedPull({ event: github.event, gh, git, issues, sleep });\n}","handlingStrategy":"validation","validationCode":"if (!event?.pull_request) { console.warn('not a pull_request event; skipping'); return; }\ncheckClosedPull({ event, gh, git, issues, sleep });","typeGuard":"function isPullRequestEvent(event) {\n  return typeof event === 'object' && event !== null && typeof event.pull_request === 'object' && event.pull_request !== null;\n}","tryCatchPattern":"try {\n  checkClosedPull({ event, gh, git, issues, sleep });\n} catch (e) {\n  if (e.message === 'a pull_request payload is required') return skipNonPrEvent();\n  throw e;\n}","preventionTips":["Restrict the workflow trigger to pull_request events (on: pull_request).","Assert the event shape in a smoke test before invoking library helpers.","Log event.action/event_name when debugging wrong-payload wiring."],"tags":["github","validation","missing-payload"],"backgroundTag":"missing-required-argument","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}