Skip to content

Commit ad56830

Browse files
CopilotwillsmytheskarimCopilot
authored
docs: stack object in pull_request webhooks (#67)
* Initial plan * Add CI integration guide documenting stack object in pull_request webhook events Agent-Logs-Url: https://github.com/github/gh-stack/sessions/cf10db22-af0b-45c3-95d6-de9ef313d624 Co-authored-by: willsmythe <2503052+willsmythe@users.noreply.github.com> * clean up webhooks content * improve workflow code sample Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: willsmythe <2503052+willsmythe@users.noreply.github.com> Co-authored-by: Sameen Karim <skarim@github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent ad21053 commit ad56830

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

docs/astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export default defineConfig({
7171
label: 'Reference',
7272
items: [
7373
{ label: 'CLI Commands', slug: 'reference/cli' },
74+
{ label: 'Webhooks', slug: 'reference/webhooks' },
7475
],
7576
},
7677
{

docs/src/content/docs/faq.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,35 @@ Every PR in a stack is treated as if it is targeting the **base of the stack** (
7171

7272
GitHub Actions workflows trigger as if each PR in the stack is targeting the base of the stack (e.g., `main`). If you have a workflow configured to run on `pull_request` events targeting `main`, it will run for **every PR in the stack** — not just the bottom one.
7373

74+
### How do I access stack metadata in my GitHub Actions workflow?
75+
76+
For advanced use cases, you can access the stack's base ref and base SHA in workflow expressions via `github.event.pull_request.stack`. This property is only present when the PR belongs to a stack.
77+
78+
```yaml
79+
jobs:
80+
build:
81+
runs-on: ubuntu-latest
82+
steps:
83+
- uses: actions/checkout@v4
84+
85+
- name: Show stack info
86+
if: github.event.pull_request.stack != null
87+
run: |
88+
echo "Stack base ref: ${{ github.event.pull_request.stack.base.ref }}"
89+
echo "Stack base SHA: ${{ github.event.pull_request.stack.base.sha }}"
90+
91+
- name: Run a step only when the stack targets a release branch
92+
if: github.event.pull_request.stack != null && startsWith(github.event.pull_request.stack.base.ref, 'release/')
93+
run: echo "This stack targets a release branch"
94+
```
95+
96+
| Expression | Description |
97+
|------------|-------------|
98+
| `github.event.pull_request.stack.base.ref` | The branch the entire stack ultimately targets (e.g., `main`). |
99+
| `github.event.pull_request.stack.base.sha` | The HEAD SHA of that target branch at the time of the event. |
100+
101+
See the [Webhooks reference](/gh-stack/reference/webhooks/) for the full details on the `stack` object in webhook payloads.
102+
74103
### Do all previous PRs need to be passing checks before I can merge?
75104

76105
Yes. In order to merge a PR in the stack, **all PRs below it** must also have passing checks and meet all merge requirements. For example, in a stack of `main <- PR1 <- PR2 <- PR3`, if you want to merge PR #3, both PR #1 and PR #2 must have passing checks, required reviews, and satisfy all branch protection rules.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: Webhooks
3+
description: Reference for the stack object in pull_request webhook event payloads.
4+
---
5+
6+
When a pull request belongs to a stack, GitHub adds a `stack` property to the `pull_request` object in webhook event payloads. This lets apps and integrations inspect the stack's ultimate target branch — not just the direct parent branch of the PR.
7+
8+
The `stack` object is included in the `pull_request` webhook payload for all [pull request lifecycle events](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request).
9+
10+
11+
12+
## The `stack` Object
13+
14+
The `stack` object is nested inside the `pull_request` object and contains information about the stack's base branch:
15+
16+
```json
17+
{
18+
"action": "synchronize",
19+
"pull_request": {
20+
"number": 42,
21+
"title": "Add API routes",
22+
"base": {
23+
"ref": "feat/auth-layer",
24+
"sha": "abc123..."
25+
},
26+
"stack": {
27+
"base": {
28+
"ref": "main",
29+
"sha": "def456..."
30+
}
31+
}
32+
}
33+
}
34+
```
35+
36+
### Fields
37+
38+
| Field | Type | Description |
39+
|-------|------|-------------|
40+
| `pull_request.stack.base.ref` | `string` | The branch the entire stack ultimately targets (e.g., `main`). |
41+
| `pull_request.stack.base.sha` | `string` | The HEAD SHA of that target branch at the time of the event. |
42+
43+
`pull_request.base.ref` is the direct parent branch of an individual PR (the branch below it in the stack), while `pull_request.stack.base.ref` is the ultimate target of the entire stack. These differ for all PRs in the stack except the bottom one.
44+
45+
The `stack` object is **only present** when the pull request belongs to a stack. For standalone PRs, the field is null.
46+
47+
## GitHub Actions
48+
49+
GitHub Actions automatically evaluates workflow triggers using the stack's base branch. If a PR is part of a stack targeting `main`, any workflow configured to run on pull requests targeting `main` will run for every PR in the stack — no workflow changes are required.
50+
51+
The `stack` object is also available in GitHub Actions workflow expressions via `github.event.pull_request.stack`. See [How do I access stack metadata in my GitHub Actions workflow?](/gh-stack/faq/#how-do-i-access-stack-metadata-in-my-github-actions-workflow) in the FAQ for examples.

0 commit comments

Comments
 (0)