Skip to content

Commit 04bac96

Browse files
authored
chore: document branch notification url (supabase#40168)
* chore: document branch notification url * chore: elaborate some parts
1 parent 1188196 commit 04bac96

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed

apps/docs/content/guides/deployment/branching/working-with-branches.mdx

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,177 @@ subtitle: 'Learn how to develop and manage your Supabase branches'
66

77
This guide covers how to work with Supabase branches effectively, including migration management, seeding behavior, and development workflows.
88

9+
## Subscribing to notifications
10+
11+
You can subscribe to webhook notifications when an action run completes on a persistent branch. The payload format follows the [webhook standards](https://www.standardwebhooks.com).
12+
13+
```json
14+
{
15+
"type": "run.completed",
16+
"timestamp": "2025-10-17T02:27:18.705861793Z",
17+
"data": {
18+
"project_ref": "xuqpsshjxdecrwdyuxvs",
19+
"details_url": "https://supabase.com/dashboard/project/xuqpsshjxdecrwdyuxvs/branches",
20+
"action_run": {
21+
"id": "d5f8b4298d0a4d37b99e255c7837e7af",
22+
"created_at": "2025-10-17T02:27:10.133329324Z"
23+
"steps": [
24+
{
25+
"name": "clone",
26+
"status": "exited",
27+
"updated_at": "2025-10-17T02:27:10.788435466Z"
28+
},
29+
{
30+
"name": "pull",
31+
"status": "exited",
32+
"updated_at": "2025-10-17T02:27:11.701742857Z"
33+
},
34+
{
35+
"name": "health",
36+
"status": "exited",
37+
"updated_at": "2025-10-17T02:27:12.79205717Z"
38+
},
39+
{
40+
"name": "configure",
41+
"status": "exited",
42+
"updated_at": "2025-10-17T02:27:13.726839657Z"
43+
},
44+
{
45+
"name": "migrate",
46+
"status": "exited",
47+
"updated_at": "2025-10-17T02:27:14.97017507Z"
48+
},
49+
{
50+
"name": "seed",
51+
"status": "exited",
52+
"updated_at": "2025-10-17T02:27:15.637684921Z"
53+
},
54+
{
55+
"name": "deploy",
56+
"status": "exited",
57+
"updated_at": "2025-10-17T02:27:18.604193114Z"
58+
}
59+
]
60+
}
61+
}
62+
}
63+
```
64+
65+
We recommend registering a single webhooks processor that dispatches events to downstream services based on the payload type. The easiest way to do that is by deploying an Edge Function. For example, the following Edge Function listens for run completed events to notify a Slack channel.
66+
67+
```typescript name=supabase/functions/notify-slack/index.ts
68+
// Setup type definitions for built-in Supabase Runtime APIs
69+
import 'jsr:@supabase/functions-js/edge-runtime.d.ts'
70+
71+
console.log('Branching notification booted!')
72+
const slack = Deno.env.get('SLACK_WEBHOOK_URL') ?? ''
73+
74+
Deno.serve(async (request) => {
75+
const body = await request.json()
76+
const blocks = [
77+
{
78+
type: 'header',
79+
text: {
80+
type: 'plain_text',
81+
text: `Action run ${body.data.action_run.failure ? 'failed' : 'completed'}`,
82+
emoji: true,
83+
},
84+
},
85+
{
86+
type: 'section',
87+
fields: [
88+
{
89+
type: 'mrkdwn',
90+
text: `*Branch ref:*\n${body.data.project_ref}`,
91+
},
92+
{
93+
type: 'mrkdwn',
94+
text: `*Run ID:*\n${body.data.action_run.id}`,
95+
},
96+
],
97+
},
98+
{
99+
type: 'section',
100+
fields: [
101+
{
102+
type: 'mrkdwn',
103+
text: `*Started at:*\n${body.data.action_run.created_at}`,
104+
},
105+
{
106+
type: 'mrkdwn',
107+
text: `*Completed at:*\n${body.timestamp}`,
108+
},
109+
],
110+
},
111+
{
112+
type: 'section',
113+
text: {
114+
type: 'mrkdwn',
115+
text: `<${body.data.details_url}|View logs>`,
116+
},
117+
},
118+
]
119+
const resp = await fetch(slack, {
120+
method: 'POST',
121+
body: JSON.stringify({
122+
blocks,
123+
}),
124+
})
125+
const message = await resp.text()
126+
return new Response(
127+
JSON.stringify({
128+
message,
129+
}),
130+
{
131+
status: 200,
132+
}
133+
)
134+
})
135+
```
136+
137+
<StepHikeCompact>
138+
<StepHikeCompact.Step step={1}>
139+
<StepHikeCompact.Details title="Setup Slack webhook URL" fullWidth>
140+
141+
Create a [Slack webhook URL](https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks/) and set it as Function secrets.
142+
143+
```markdown
144+
supabase secrets set --project-ref <branch-ref> SLACK_WEBHOOK_URL=<your-webhook-url>
145+
```
146+
147+
</StepHikeCompact.Details>
148+
149+
</StepHikeCompact.Step>
150+
151+
<StepHikeCompact.Step step={2}>
152+
<StepHikeCompact.Details title="Deploy your webhooks processor" fullWidth>
153+
154+
Create and deploy an Edge Function to process webhooks.
155+
156+
```markdown
157+
supabase functions deploy --project-ref <branch-ref> --use-api notify-slack
158+
```
159+
160+
</StepHikeCompact.Details>
161+
162+
</StepHikeCompact.Step>
163+
164+
<StepHikeCompact.Step step={3}>
165+
<StepHikeCompact.Details title="Update branch notification URL" fullWidth>
166+
167+
Update the notification URL of your target branch to point to your Edge Function.
168+
169+
```markdown
170+
supabase branches update <branch-ref> --notify-url https://<branch-ref>.supabase.co/functions/v1/notify-slack
171+
```
172+
173+
</StepHikeCompact.Details>
174+
175+
</StepHikeCompact.Step>
176+
</StepHikeCompact>
177+
178+
After completing the steps above, you should receive a Slack message whenever an action run completes on your target branch.
179+
9180
## Migration and seeding behavior
10181

11182
Migrations are run in sequential order. Each migration builds upon the previous one.

0 commit comments

Comments
 (0)