Skip to content

Commit f503c87

Browse files
authored
[PRIVATE-REPO] docs: add stacked PR workflow to AGENTS.md (#27)
* feat: add use_badges parameter to build_table for private repo support - Add use_badges parameter to build_table function - Default (false) generates 3-column table without shields.io badges - When true, generates 4-column table with shields.io status badges - Update existing tests to use new default (no badges) - Add new tests for badges mode - Update main.rs call site to use new parameter * feat: add --badges flag to annotate command - Add --badges CLI flag to enable shields.io status badges - Default behavior now generates simpler table without badges - Works with private repositories by default * docs: update README for private repo support and --badges flag - Remove public visibility assumption from requirements - Add --badges flag documentation - Add example of new default table format - Explain GitHub's native PR autolinking feature * docs: add stacked PR workflow to AGENTS.md Dogfood gh-stack by documenting how to use it for stacked PRs in this repo.
1 parent fdadf62 commit f503c87

13 files changed

Lines changed: 267 additions & 113 deletions

AGENTS.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,35 @@ docs: update documentation
4747
chore: maintenance tasks
4848
```
4949

50+
## Stacked PRs
51+
52+
When creating stacked PRs, use `gh-stack` to manage and annotate them:
53+
54+
1. Create branches that build on each other:
55+
```bash
56+
git checkout -b feat/my-feature-part1
57+
# make changes, commit
58+
git checkout -b feat/my-feature-part2
59+
# make changes, commit
60+
```
61+
62+
2. Push branches and create PRs with proper base branches:
63+
```bash
64+
git push origin feat/my-feature-part1 feat/my-feature-part2
65+
gh pr create --base master --head feat/my-feature-part1 --title "[STACK-ID] part 1"
66+
gh pr create --base feat/my-feature-part1 --head feat/my-feature-part2 --title "[STACK-ID] part 2"
67+
```
68+
69+
3. Annotate PRs with stack info:
70+
```bash
71+
gh-stack annotate 'STACK-ID' -r 'luqven/gh-stack' --ci
72+
```
73+
74+
4. After rebasing, update the stack:
75+
```bash
76+
gh-stack autorebase 'STACK-ID' -r 'luqven/gh-stack' -C . --ci
77+
```
78+
5079
## Function Signatures
5180

5281
Pass primitives directly, keep arg count low:

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ This tool assumes that:
1515
- All PRs in a single "stack" all have a unique identifier in their title (I typically use a Jira ticket number for this).
1616
- All PRs in the stack live in a single GitHub repository.
1717
- All remote branches that these PRs represent have local branches named identically.
18-
- Your PRs are publicly viewable by all GitHub users.
19-
- This assumption is due to how the Markdown table is uses https://shields.io to render badges that auto-update based on your PR status.
20-
- example URL: https://img.shields.io/github/pulls/detail/state/{{your-user-or-org}}/{{your-repository}}/{{the-pr-number}}
2118

2219
It then looks for all PRs containing this identifier and builds a dependency graph in memory.
2320

@@ -107,9 +104,10 @@ $ gh-stack annotate 'stack-identifier' -r '<some/repo>' --prefix '#'
107104
# contents of `filename.txt`.
108105
$ gh-stack annotate 'stack-identifier' -p filename.txt
109106

110-
# Same as above, but precede the markdown table with the
111-
# contents of `filename.txt`.
112-
$ gh-stack annotate 'stack-identifier' -p filename.txt
107+
# Same as above, but with shields.io status badges (requires public repo).
108+
# By default, annotations use GitHub's native PR autolinking which works
109+
# with both public and private repositories.
110+
$ gh-stack annotate 'stack-identifier' --badges
113111

114112
# Automatically update the entire stack, both locally and remotely.
115113
# WARNING: This operation modifies local branches and force-pushes.
@@ -195,6 +193,19 @@ _This is a quick overview of the ways this tool could be used in practice._
195193
```
196194

197195
This (idempotently) adds a table like this to the description of every PR in the stack:
196+
197+
```markdown
198+
### Stacked PR Chain: EXAMPLE-13799
199+
| PR | Title | Merges Into |
200+
|:--:|:------|:-----------:|
201+
|#1|[EXAMPLE-13799] PR for branch `first`|-|
202+
|#2|[EXAMPLE-13799] PR for branch `second`|#1|
203+
|#3|[EXAMPLE-13799] PR for branch `third`|#2|
204+
```
205+
206+
GitHub automatically converts `#1`, `#2`, `#3` to clickable links. Hovering over them shows PR details including current status.
207+
208+
For public repositories, you can use `--badges` to add shields.io status badges:
198209
<img src="img/annotate.png" width="700" />
199210

200211
7. Make changes to a branch that rewrites commits in some way (amend, remove a commit, combine commits):

src/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ fn clap<'a, 'b>() -> App<'a, 'b> {
4141
.takes_value(true)
4242
.help("PR title prefix identifier to remove from the title");
4343

44+
let badges = Arg::with_name("badges")
45+
.long("badges")
46+
.takes_value(false)
47+
.help("Use shields.io badges for PR status (requires public repo visibility)");
48+
4449
let annotate = SubCommand::with_name("annotate")
4550
.about("Annotate the descriptions of all PRs in a stack with metadata about all PRs in the stack")
4651
.setting(AppSettings::ArgRequiredElseHelp)
@@ -49,6 +54,7 @@ fn clap<'a, 'b>() -> App<'a, 'b> {
4954
.arg(repository.clone())
5055
.arg(ci.clone())
5156
.arg(prefix.clone())
57+
.arg(badges.clone())
5258
.arg(Arg::with_name("prelude")
5359
.long("prelude")
5460
.short("p")
@@ -219,8 +225,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
219225
build_pr_stack_for_repo(&identifier, repository, &credentials, get_excluded(m))
220226
.await?;
221227

222-
let table =
223-
markdown::build_table(&stack, &identifier, m.value_of("prelude"), repository);
228+
let use_badges = m.is_present("badges");
229+
let table = markdown::build_table(
230+
&stack,
231+
&identifier,
232+
m.value_of("prelude"),
233+
repository,
234+
use_badges,
235+
);
224236

225237
for (pr, _) in stack.iter() {
226238
println!("{}: {}", pr.number(), pr.title());

0 commit comments

Comments
 (0)