Skip to content

Commit d8c54a6

Browse files
committed
fix(submit): move draft-to-ready prompt to Phase 3 (PRs)
The prompt for publishing a draft PR was previously shown during `sync` when retargeting branches after their parent was merged. This moves the prompt to Phase 3 of `submit`, which is the more appropriate place since it's a PR operation, not a sync operation. The prompt now appears when: - Updating an existing draft PR whose base is now trunk - Adopting a draft PR that targets trunk
1 parent 6853355 commit d8c54a6

2 files changed

Lines changed: 40 additions & 14 deletions

File tree

cmd/submit.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ func doSubmitPRs(g *git.Git, cfg *config.Config, root *tree.Node, branches []*tr
235235
if err := ghClient.GenerateAndPostStackComment(root, b.Name, trunk, existingPR); err != nil {
236236
fmt.Printf("Warning: failed to update stack comment for PR #%d: %v\n", existingPR, err)
237237
}
238+
239+
// If PR is a draft and now targets trunk, offer to publish
240+
maybeMarkPRReady(ghClient, existingPR, b.Name, parent, trunk)
238241
}
239242
} else if !updateOnly {
240243
// Create new PR
@@ -450,9 +453,46 @@ func adoptExistingPR(ghClient *github.Client, cfg *config.Config, root *tree.Nod
450453
fmt.Printf("Warning: failed to update stack comment: %v\n", err)
451454
}
452455

456+
// If adopted PR is a draft and targets trunk, offer to publish
457+
if existingPR.Draft && base == trunk {
458+
maybeMarkPRReady(ghClient, existingPR.Number, branch, base, trunk)
459+
}
460+
453461
return existingPR.Number, nil
454462
}
455463

464+
// maybeMarkPRReady checks if a PR is a draft targeting trunk and offers to publish it.
465+
// This handles the case where a PR was created as a draft (middle of stack) but now
466+
// targets trunk because its parent was merged.
467+
func maybeMarkPRReady(ghClient *github.Client, prNumber int, branch, base, trunk string) {
468+
// Only relevant if PR now targets trunk
469+
if base != trunk {
470+
return
471+
}
472+
473+
// Check if PR is a draft
474+
pr, err := ghClient.GetPR(prNumber)
475+
if err != nil || !pr.Draft {
476+
return
477+
}
478+
479+
fmt.Printf("PR #%d (%s) is a draft and now targets %s.\n", prNumber, branch, trunk)
480+
481+
// Skip prompt if --yes flag is set or non-interactive
482+
shouldMarkReady := true
483+
if !submitYesFlag && prompt.IsInteractive() {
484+
shouldMarkReady, _ = prompt.Confirm("Mark as ready for review?", true) //nolint:errcheck // default is fine
485+
}
486+
487+
if shouldMarkReady {
488+
if readyErr := ghClient.MarkPRReady(prNumber); readyErr != nil {
489+
fmt.Printf("Warning: failed to mark PR ready: %v\n", readyErr)
490+
} else {
491+
fmt.Printf("PR #%d marked as ready for review.\n", prNumber)
492+
}
493+
}
494+
}
495+
456496
// generatePRBody creates a PR description from the commits between base and head.
457497
// For a single commit: returns the commit body.
458498
// For multiple commits: returns each commit as a markdown section.

cmd/sync.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,6 @@ func runSync(cmd *cobra.Command, args []string) error {
298298
if updateErr := gh.UpdatePRBase(rt.childPR, trunk); updateErr != nil {
299299
fmt.Printf("Warning: failed to update PR #%d base: %v\n", rt.childPR, updateErr)
300300
}
301-
302-
// Check if this was a draft and now targets trunk - offer to publish
303-
pr, getPRErr := gh.GetPR(rt.childPR)
304-
if getPRErr == nil && pr.Draft {
305-
fmt.Printf("PR #%d (%s) now targets %s.\n", rt.childPR, rt.childName, trunk)
306-
ready, _ := prompt.Confirm("Mark as ready for review?", true) //nolint:errcheck // default is fine
307-
if ready {
308-
if readyErr := gh.MarkPRReady(rt.childPR); readyErr != nil {
309-
fmt.Printf("Warning: failed to mark PR ready: %v\n", readyErr)
310-
} else {
311-
fmt.Printf("PR #%d marked as ready for review.\n", rt.childPR)
312-
}
313-
}
314-
}
315301
}
316302

317303
// Rebase using --onto if we have a fork point

0 commit comments

Comments
 (0)