GitHub webhook handler
Build a pattern that receives GitHub events, routes them by type, and logs formatted summaries.
In this tutorial, you build a pattern that acts as a GitHub webhook endpoint. It receives push, pull request, and issue events, routes each to different logic using a Switch node, extracts the relevant data, and responds with a 200 OK. By the end, you have a deployed webhook handler that processes real GitHub events.
What you will build
A single pattern with the following flow:
- On Webhook — receives the incoming GitHub event
- Get Property — extracts the
X-GitHub-Eventheader to determine the event type - Switch — routes execution to the correct branch based on the event type
- Get Property / Format — extracts and formats event-specific data
- Log — writes a summary message to the console
- Respond To Webhook — sends a 200 OK back to GitHub
When a push event arrives, the console displays something like:
Push to octocat/Hello-World: Updated README.mdBefore you begin
Make sure you have:
- An active DRAGOPS account
- A GitHub repository where you can configure webhooks (or a tool like
curlto simulate events) - Familiarity with creating patterns, wiring nodes, and deploying (see Your first pattern)
Step 1: Create the pattern
- Open the DRAGOPS dashboard.
- Select New Pattern.
- Enter the name "GitHub Webhook Handler" and select Create.
Step 2: Add the webhook trigger
- Remove the default On Start node by selecting it and pressing Delete or Backspace.
- Right-click on the canvas to open the node search menu.
- Search for "On Webhook" and add it to the canvas.
The On Webhook node provides output pins for Body, Headers, Query, and Method. GitHub sends the event payload in the body and identifies the event type in the X-GitHub-Event header.
Step 3: Extract the event type from headers
The event type is not in the body — GitHub sends it as a request header. You need to read it from the headers object.
- Right-click on the canvas and search for "Get Property". Add the node to the canvas.
- Select the node to open the Inspector Panel on the left side. Set the Key to
x-github-event. - Wire On Webhook's Headers output pin to Get Property's Object input pin.
- Wire the execution flow from On Webhook to Get Property.
This node extracts the value of the x-github-event header (for example, push, pull_request, or issues).
Step 4: Route with a Switch node
A Switch node compares a value against multiple cases and runs the matching branch. This is cleaner than chaining multiple Branch nodes.
- Right-click on the canvas and search for "Switch".
- Add the Switch node to the canvas, to the right of Get Property.
- Select the Switch node and configure three cases in the Inspector Panel:
- Case 1:
push - Case 2:
pull_request - Case 3:
issues
- Case 1:
- Wire Get Property's Value output pin to Switch's Value input pin.
- Wire the execution flow from Get Property to Switch.
The Switch node now has four execution output pins: one for each case and a Default output for unrecognized event types.
Step 5: Handle push events
When a push event arrives, extract the repository name and the latest commit message.
- Add a Get Property node. Set the Key to
repository. Wire On Webhook's Body output pin to its Object input pin. - Add another Get Property node. Set the Key to
full_name. Wire the previous Get Property's Value output pin to its Object input pin. - Add a Get Property node. Set the Key to
head_commit. Wire On Webhook's Body output pin to its Object input pin. - Add another Get Property node. Set the Key to
message. Wire the previous Get Property's Value output pin to its Object input pin. - Add a Format node. Set the Template to
Push to {0}: {1}. - Wire the repository
full_namevalue to Format's first input. - Wire the commit
messagevalue to Format's second input. - Add a Log node. Wire Format's Result output pin to Log's Message input pin.
- Wire the execution flow: Switch's push output pin to the first Get Property, then chain execution through to Log.
Step 6: Handle pull request events
When a pull request event arrives, extract the PR title and the author.
- Add a Get Property node. Set the Key to
pull_request. Wire On Webhook's Body output pin to its Object input pin. - Add a Get Property node. Set the Key to
title. Wire the previous Get Property's Value output pin to its Object input pin. - Add another Get Property node. Set the Key to
user. Wire thepull_requestGet Property's Value output pin to its Object input pin. - Add another Get Property node. Set the Key to
login. Wire the previous Get Property's Value output pin to its Object input pin. - Add a Format node. Set the Template to
Pull request by {0}: {1}. - Wire the
loginvalue to Format's first input. - Wire the
titlevalue to Format's second input. - Add a Log node. Wire Format's Result output pin to Log's Message input pin.
- Wire the execution flow: Switch's pull_request output pin through the chain to Log.
Step 7: Handle issue events
When an issue event arrives, extract the issue title and the action (opened, closed, etc.).
- Add a Get Property node. Set the Key to
action. Wire On Webhook's Body output pin to its Object input pin. - Add a Get Property node. Set the Key to
issue. Wire On Webhook's Body output pin to its Object input pin. - Add another Get Property node. Set the Key to
title. Wire the previous Get Property's Value output pin to its Object input pin. - Add a Format node. Set the Template to
Issue {0}: {1}. - Wire the
actionvalue to Format's first input. - Wire the
titlevalue to Format's second input. - Add a Log node. Wire Format's Result output pin to Log's Message input pin.
- Wire the execution flow: Switch's issues output pin through the chain to Log.
Step 8: Handle unrecognized events
Add a fallback for events you did not explicitly handle.
- Add a Format node. Set the Template to
Received unhandled event type: {0}. - Wire the event type Get Property's Value output pin (from Step 3) to Format's first input.
- Add a Log node. Wire Format's Result to Log's Message input pin.
- Wire the execution flow: Switch's Default output pin to the Format node, then to Log.
Step 9: Respond to GitHub
GitHub expects a timely HTTP response. Without one, it marks the delivery as failed and may retry. Add a Respond To Webhook node at the end of every branch.
- Right-click on the canvas and search for "Respond To Webhook". Add a node for each execution branch (push, pull_request, issues, and default).
- Set the Status Code to
200on each. - Add a String literal with the value
okand wire it to each Respond To Webhook's Body input pin. - Wire the execution flow from the final Log node in each branch to the corresponding Respond To Webhook node.
Alternatively, you can converge all branches into a single Respond To Webhook node by wiring each branch's final Log execution output pin to the same Respond To Webhook node.
Step 10: Test in the editor
Test each event type with sample data to verify the routing works.
Test a push event
- Select Run in the toolbar.
- Enter the following test data:
{
"body": {
"head_commit": {
"message": "Updated README.md"
},
"repository": {
"full_name": "octocat/Hello-World"
}
},
"headers": {
"x-github-event": "push"
},
"query": {},
"method": "POST"
}- Select Run. The console should display:
Push to octocat/Hello-World: Updated README.md.
Test a pull request event
- Select Run again with this data:
{
"body": {
"pull_request": {
"title": "Add dark mode support",
"user": {
"login": "octocat"
}
}
},
"headers": {
"x-github-event": "pull_request"
},
"query": {},
"method": "POST"
}- The console should display:
Pull request by octocat: Add dark mode support.
Test an issue event
- Select Run with this data:
{
"body": {
"action": "opened",
"issue": {
"title": "Bug: Login page not loading"
}
},
"headers": {
"x-github-event": "issues"
},
"query": {},
"method": "POST"
}- The console should display:
Issue opened: Bug: Login page not loading.
Step 11: Deploy and connect to GitHub
- Select Deploy in the toolbar.
- Copy the webhook URL from the Triggers panel.
- In your GitHub repository, go to Settings > Webhooks > Add webhook.
- Paste the webhook URL into the Payload URL field.
- Set Content type to
application/json. - Under Which events would you like to trigger this webhook?, select Let me select individual events and check Pushes, Pull requests, and Issues.
- Select Add webhook.
GitHub sends a ping event to verify the URL is reachable. Since the pattern handles this through the default Switch branch, you should see a log entry: Received unhandled event type: ping.
Step 12: Verify with a real event
Create a test issue or push a commit to the repository. Then open the Deployments page in the DRAGOPS dashboard, select the "GitHub Webhook Handler" deployment, and check the execution history. The latest execution should show the formatted summary message for the event you triggered.
What you learned
- How to read request headers using Get Property on the Headers output pin
- How to route execution to different branches with a Switch node
- How to extract nested data from JSON objects using chained Get Property nodes
- How to send an HTTP response back to the caller with Respond To Webhook
- How to connect a deployed pattern to a real GitHub webhook
What is next?
Scheduled data pipeline
Build a pattern that fetches, filters, and transforms API data on a schedule.
Handle errors
Add Try / Catch and Retry to make your webhook handler more resilient.
Send custom webhook responses
Return custom status codes, headers, and bodies from webhook patterns.
Triggers
Learn about all trigger types including webhooks, schedules, and pattern calls.