Skip to content

Commit 40fcd41

Browse files
jbachorikclaude
andcommitted
Filter out existing upstream PRs in /contribute-upstream
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 1d2054c commit 40fcd41

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

.claude/commands/contribute-upstream.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,21 @@ Also read the corresponding markdown report to understand the actual diff hunks
3232

3333
If there are zero candidates, tell the user and stop.
3434

35-
## Step 3: Group into PR Proposals
35+
## Step 3: Filter Out Existing PRs
3636

37-
Analyze the contributable hunks across all candidate files and group them into logical PR proposals. Guidelines:
37+
Before proposing new PRs, check what's already open from DataDog against upstream:
38+
39+
```bash
40+
gh pr list --repo async-profiler/async-profiler --author DataDog --state open --json number,title,body,files
41+
```
42+
43+
For each open PR, extract the list of files it touches. Then cross-reference with the candidate files from Step 2:
44+
45+
- If a candidate file is already fully covered by an open PR (i.e., the PR touches that file and addresses the same type of change), **exclude it** from proposals
46+
- If a candidate file is only partially covered (the open PR addresses some hunks but not others), keep the uncovered hunks as candidates
47+
- When presenting proposals in Step 4, mention any skipped files and the existing PR that covers them, so the user has full visibility
48+
49+
Analyze the remaining contributable hunks across candidate files and group them into logical PR proposals. Guidelines:
3850

3951
- **Related changes go together**: e.g., a bug fix touching `stackWalker.cpp` and `vmStructs.cpp` for the same issue = one PR
4052
- **Independent changes are separate**: unrelated fixes in different files = separate PRs
@@ -46,7 +58,7 @@ For each proposed PR, prepare:
4658
- The list of files and hunks it covers
4759
- A brief rationale explaining why this change benefits upstream
4860

49-
## Step 4: Present Proposals to User
61+
## Step 5: Present Proposals to User
5062

5163
Show the user a numbered list of proposed PRs with:
5264
- Title
@@ -58,11 +70,11 @@ Use `AskUserQuestion` with `multiSelect: true` to let the user pick which PRs to
5870

5971
If the user selects none, stop.
6072

61-
## Step 5: Create Selected PRs
73+
## Step 6: Create Selected PRs
6274

6375
For each selected PR, perform the following:
6476

65-
### 5a. Clone the Fork (once)
77+
### 6a. Clone the Fork (once)
6678

6779
Clone `git@github.com:DataDog/async-profiler.git` to a temp directory. Reuse this clone for all PRs.
6880

@@ -78,7 +90,7 @@ git checkout -b master
7890
git branch -D temp
7991
```
8092

81-
### 5b. Create Feature Branch
93+
### 6b. Create Feature Branch
8294

8395
For each PR, create a branch from upstream master:
8496

@@ -91,7 +103,7 @@ git checkout -b "$BRANCH_NAME"
91103

92104
Where `<slug>` is a short kebab-case description derived from the PR title.
93105

94-
### 5c. Port Changes
106+
### 6c. Port Changes
95107

96108
Apply only the relevant contributable hunks for this PR to the upstream files:
97109

@@ -100,7 +112,7 @@ Apply only the relevant contributable hunks for this PR to the upstream files:
100112
3. **Critical**: Ensure NO Datadog-specific references leak through (DD_, ddprof, Datadog, datadog, DDPROF, context.h, counters.h, tagger, QueueItem)
101113
4. If a hunk cannot be cleanly applied because the upstream file diverged, skip it and note it for the user
102114

103-
### 5d. Verify Build
115+
### 6d. Verify Build
104116

105117
Attempt a basic build check:
106118

@@ -111,7 +123,7 @@ make
111123

112124
If the build fails, analyze the error. If it's a simple fix (e.g., missing include), fix it. If it's complex, note it for the user and proceed anyway (the PR is draft).
113125

114-
### 5e. Commit and Push
126+
### 6e. Commit and Push
115127

116128
```bash
117129
cd "$FORK_DIR"
@@ -120,7 +132,7 @@ git commit -m "<concise description of the change>"
120132
git push origin "$BRANCH_NAME"
121133
```
122134

123-
### 5f. Open Draft PR
135+
### 6f. Open Draft PR
124136

125137
Use `gh` to create a draft PR against upstream. **Important**: Before creating the first PR, fetch the target project's PR template from the upstream repo (`gh api repos/async-profiler/async-profiler/contents/.github/PULL_REQUEST_TEMPLATE.md` and decode the base64 content). The PR body **must** follow that template exactly — use all its sections, checkboxes, and footer verbatim. Fill in each section with the relevant content for this change.
126138

@@ -134,7 +146,7 @@ gh pr create \
134146
--body "<body following the upstream PR template>"
135147
```
136148

137-
## Step 6: Report
149+
## Step 7: Report
138150

139151
After all selected PRs are created, show the user:
140152
- A summary table of created PRs with their URLs

0 commit comments

Comments
 (0)