-
Notifications
You must be signed in to change notification settings - Fork 0
Add webhook handler for PR label 'I2PR: Update PR' #1440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
## Features Added - **PR Label Webhook Handler**: Triggers createDependentPR job when PR is labeled with "I2PR: Update PR" - **Enhanced PullRequestPayloadSchema**: Added label, number, and sender fields to support label events - **Webhook Route Integration**: Added routing logic to handle PR labeled events ## Technical Implementation - Created `handlePullRequestLabelCreateDependentPR` handler to enqueue worker jobs - Extended webhook payload validation to include required fields for the dependent PR workflow - Added comprehensive tests covering both handler logic and route integration ## How It Works 1. GitHub sends webhook when PR gets labeled with "I2PR: Update PR" 2. Webhook validates payload and extracts: `repoFullName`, `pullNumber`, `githubLogin`, `githubInstallationId` 3. Handler enqueues `createDependentPR` job onto the workflow-jobs Redis queue 4. Worker (to be implemented in next PR) will process the job and create dependent branch/PR ## Test Coverage - [x] Handler validates required fields and throws appropriate errors - [x] Handler enqueues job with correct payload structure - [x] Route integration correctly routes labeled events to handler - [x] REDIS_URL environment validation This provides the webhook foundation for the createDependentPR workflow feature requested in Issue #1399. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
You have run out of free Bugbot PR reviews for this billing cycle. This will reset on January 19. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis PR adds webhook event handling for GitHub pull requests labeled with "i2pr: update pr". It introduces a new handler function that validates the payload, logs receipt of the event, and returns metadata without further processing. Type definitions are extended to support optional fields (PR number, label name, sender). Changes
Possibly related PRs
Suggested labels
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
lib/webhook/github/handlers/pullRequest/label.createDependentPR.handler.ts
Outdated
Show resolved
Hide resolved
…n- Remove job queue enqueue from handlePullRequestLabelCreateDependentPR\n- Validate payload and log receipt with context; return a small noop result\n- Update unit tests to assert noop behavior and remove Redis/job assertions\n\nThis scopes the PR to webhook routing only; worker job wiring will be added in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
lib/webhook/github/handlers/pullRequest/label.createDependentPR.handler.ts (1)
17-17: Consider using nullish coalescing (??) for the pullNumber fallback.The current code uses
||, which would skippayload.numberif it were0. While GitHub PR numbers are always positive integers (starting at 1), using??is more semantically correct and defensive:- const pullNumber = payload.number || payload.pull_request?.number + const pullNumber = payload.number ?? payload.pull_request?.number🔎 Proposed change
- const pullNumber = payload.number || payload.pull_request?.number + const pullNumber = payload.number ?? payload.pull_request?.number
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
__tests__/api/webhook/github.route.test.ts__tests__/lib/webhook/handlers/pullRequest/label.createDependentPR.handler.test.tsapp/api/webhook/github/route.tslib/webhook/github/handlers/pullRequest/label.createDependentPR.handler.tslib/webhook/github/types.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js,jsx,mts,mjs}
📄 CodeRabbit inference engine (.cursor/rules/code-structure.mdc)
Avoid barrel files: do not create files whose sole purpose is to re-export symbols from multiple modules; prefer importing from original module paths to maintain clear dependency graphs and better tree-shaking
Files:
__tests__/lib/webhook/handlers/pullRequest/label.createDependentPR.handler.test.ts__tests__/api/webhook/github.route.test.tsapp/api/webhook/github/route.tslib/webhook/github/handlers/pullRequest/label.createDependentPR.handler.tslib/webhook/github/types.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: youngchingjui
Repo: youngchingjui/issue-to-pr PR: 1282
File: shared/src/ports/events/publisher.ts:16-19
Timestamp: 2025-09-22T09:24:26.840Z
Learning: youngchingjui prefers to manage PR scope tightly and defer technical debt improvements to future PRs rather than expanding the current PR's scope, even for related consistency issues.
📚 Learning: 2025-09-12T01:44:51.070Z
Learnt from: youngchingjui
Repo: youngchingjui/issue-to-pr PR: 1241
File: app/api/webhook/github/route.ts:85-90
Timestamp: 2025-09-12T01:44:51.070Z
Learning: In the webhook handlers at app/api/webhook/github/route.ts, runWithInstallationId is intentionally not awaited to allow fire-and-forget background processing of long-running workflows, avoiding webhook timeouts. The team plans to migrate these to proper queues/workers in a separate issue later.
Applied to files:
__tests__/lib/webhook/handlers/pullRequest/label.createDependentPR.handler.test.ts__tests__/api/webhook/github.route.test.tsapp/api/webhook/github/route.tslib/webhook/github/handlers/pullRequest/label.createDependentPR.handler.ts
🧬 Code graph analysis (3)
__tests__/api/webhook/github.route.test.ts (3)
app/api/webhook/github/route.ts (1)
POST(61-361)lib/webhook/github/handlers/issue/label.autoResolveIssue.handler.ts (1)
handleIssueLabelAutoResolve(11-47)lib/webhook/github/handlers/pullRequest/label.createDependentPR.handler.ts (1)
handlePullRequestLabelCreateDependentPR(8-40)
app/api/webhook/github/route.ts (1)
lib/webhook/github/handlers/pullRequest/label.createDependentPR.handler.ts (1)
handlePullRequestLabelCreateDependentPR(8-40)
lib/webhook/github/handlers/pullRequest/label.createDependentPR.handler.ts (1)
lib/webhook/github/types.ts (1)
PullRequestPayload(51-51)
🔇 Additional comments (6)
app/api/webhook/github/route.ts (2)
14-14: LGTM! Import follows project conventions.The import path uses the path alias and matches the existing handler import patterns.
171-189: LGTM! PR label routing logic is well-structured.The implementation follows the existing pattern for issue label routing (lines 113-134), properly extracts the installationId (safe since
installationis required by the schema), normalizes the label name to lowercase, and routes to the appropriate handler. Unhandled labels are correctly ignored.__tests__/lib/webhook/handlers/pullRequest/label.createDependentPR.handler.test.ts (1)
1-56: LGTM! Comprehensive test coverage for the no-op handler.The test suite properly covers:
- The happy path: validates return shape and log message content
- The error path: validates that missing required fields throw an error
- Mock hygiene: uses
mockRestore()to clean up the console spylib/webhook/github/types.ts (1)
37-38: LGTM! Type extensions properly support PR label events.The added optional fields (
number,label,pull_request.number,sender) align with the shape of GitHub's PR labeled webhook payloads and follow the same patterns used inIssuesPayloadSchema(lines 27, 30). Making these fields optional correctly accommodates different PR event types.Also applies to: 42-42, 48-48
lib/webhook/github/handlers/pullRequest/label.createDependentPR.handler.ts (1)
8-40: LGTM! Handler correctly implements no-op validation boundary.The implementation properly:
- Validates all required fields with appropriate type checks
- Provides descriptive error messages
- Logs the receipt with full context (repo, PR number, user, installationId)
- Returns structured metadata for future use
The no-op approach aligns with the PR objectives to defer job enqueueing until worker schema support is ready.
__tests__/api/webhook/github.route.test.ts (1)
19-21: LGTM! Route integration test properly validates the PR label webhook flow.The test:
- Properly mocks the handler (lines 19-21)
- Creates a valid payload with all required fields including number, label, sender, and installation
- Generates a correct HMAC signature for webhook verification
- Verifies the handler is called exactly once with the expected arguments
- Follows the same pattern as the existing issue label test (lines 46-81)
Also applies to: 83-119
Summary
Implement webhook handling for PR labels to trigger the createDependentPR workflow when PRs are labeled with "I2PR: Update PR".
Features Implemented
🔗 Webhook Handler Foundation
handlePullRequestLabelCreateDependentPRenqueues createDependentPR jobsPullRequestPayloadSchemawithlabel,number, andsenderfields🎯 How It Works
createDependentPRjob with:repoFullName(e.g., "owner/repo")pullNumber(PR number)githubLogin(who applied the label)githubInstallationId(for GitHub App auth)🧪 Test Coverage
Technical Details
New Files
Modified Files
Example Usage
When a PR is labeled "I2PR: Update PR", this triggers:
Context & Sequence
This PR is part of breaking down the large PR #1413 into manageable pieces:
Testing
Addresses the webhook handling requirements from Issue #1399.
🤖 Generated with Claude Code
Update: Adjust handler to no-op per review feedback
createDependentPRjob name. To keep this PR scoped to webhook routing and avoid enqueueing unknown jobs, the handler now performs a no-op.handlePullRequestLabelCreateDependentPRno longer enqueues a job. It validates required fields, logs a clear message indicating the webhook was received, and returns a small{ status: "noop", ... }result.Rationale
Verification
__tests__/lib/webhook/handlers/pullRequest/label.createDependentPR.handler.test.ts__tests__/api/webhook/github.route.test.tsNext steps
createDependentPRjob type in the worker and wire up the actual enqueue logic.Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.