Skip to content

Commit 0afdba7

Browse files
authored
fix(submit): move draft-to-ready prompt to Phase 3 (PRs) (#28)
* 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 * fix(submit): avoid duplicate API call when adopting draft PRs Extract `promptMarkPRReady` helper so `adoptExistingPR` can skip the redundant `GetPR` call since it already has the `Draft` field from `FindPRByHead`.
1 parent 9bc1881 commit 0afdba7

2 files changed

Lines changed: 46 additions & 14 deletions

File tree

cmd/submit.go

Lines changed: 46 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
@@ -459,9 +462,52 @@ func adoptExistingPR(ghClient *github.Client, cfg *config.Config, root *tree.Nod
459462
fmt.Printf("Warning: failed to update stack comment: %v\n", err)
460463
}
461464

465+
// If adopted PR is a draft and targets trunk, offer to publish
466+
if existingPR.Draft && base == trunk {
467+
promptMarkPRReady(ghClient, existingPR.Number, branch, trunk)
468+
}
469+
462470
return existingPR.Number, nil
463471
}
464472

473+
// maybeMarkPRReady checks if a PR is a draft targeting trunk and offers to publish it.
474+
// This handles the case where a PR was created as a draft (middle of stack) but now
475+
// targets trunk because its parent was merged.
476+
func maybeMarkPRReady(ghClient *github.Client, prNumber int, branch, base, trunk string) {
477+
// Only relevant if PR now targets trunk
478+
if base != trunk {
479+
return
480+
}
481+
482+
// Check if PR is a draft
483+
pr, err := ghClient.GetPR(prNumber)
484+
if err != nil || !pr.Draft {
485+
return
486+
}
487+
488+
promptMarkPRReady(ghClient, prNumber, branch, trunk)
489+
}
490+
491+
// promptMarkPRReady prompts to publish a draft PR and marks it ready if confirmed.
492+
// Called when we already know the PR is a draft targeting trunk.
493+
func promptMarkPRReady(ghClient *github.Client, prNumber int, branch, trunk string) {
494+
fmt.Printf("PR #%d (%s) is a draft and now targets %s.\n", prNumber, branch, trunk)
495+
496+
// Skip prompt if --yes flag is set or non-interactive
497+
shouldMarkReady := true
498+
if !submitYesFlag && prompt.IsInteractive() {
499+
shouldMarkReady, _ = prompt.Confirm("Mark as ready for review?", true) //nolint:errcheck // default is fine
500+
}
501+
502+
if shouldMarkReady {
503+
if readyErr := ghClient.MarkPRReady(prNumber); readyErr != nil {
504+
fmt.Printf("Warning: failed to mark PR ready: %v\n", readyErr)
505+
} else {
506+
fmt.Printf("PR #%d marked as ready for review.\n", prNumber)
507+
}
508+
}
509+
}
510+
465511
// generatePRBody creates a PR description from the commits between base and head.
466512
// For a single commit: returns the commit body.
467513
// 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)