Repository navigation
Add a dry-run flag to gh pr create #8375
Description
Activity
- addedmore-info-neededMore info needed from user/contributorMore info needed from user/contributorand removedneeds-triageneeds to be reviewedneeds to be reviewed
on Nov 24, 2023 what you'd like to see as a result of providing --dry-run here?
Sure, I'd like to see what parameters would be used if the PR was created.
What kind of output would you want?
If I use the same output from https://github.com/cli/cli/pull/5098/files#diff-e15aeab65f4100441b2e8a9a3cdb63ebcaf971bb0b0c839cd790bb752a3ec35eR261
Given a branch that has already been pushed to the origin When `pr create --draft --fill-first --body 'my super-body' --dry-run --label external --label core --reviewer v1v` Then the below output will be printed Would have created a Pull Request with: title: feat: support dry-run in gh pr create draft: true labels: [external core] reviewers: [v1v] -- my super-body
I just made a quick PR to support the above, see #8376
After thinking a bit more about this idea, I'd like to propose a similar output to the one when running
gh pr view:Lines 139 to 171 in 06e438b
reviewers := prReviewerList(*pr, cs) assignees := prAssigneeList(*pr) labels := prLabelList(*pr, cs) projects := prProjectList(*pr) fmt.Fprintf(out, "title:\t%s\n", pr.Title) fmt.Fprintf(out, "state:\t%s\n", prStateWithDraft(pr)) fmt.Fprintf(out, "author:\t%s\n", pr.Author.Login) fmt.Fprintf(out, "labels:\t%s\n", labels) fmt.Fprintf(out, "assignees:\t%s\n", assignees) fmt.Fprintf(out, "reviewers:\t%s\n", reviewers) fmt.Fprintf(out, "projects:\t%s\n", projects) var milestoneTitle string if pr.Milestone != nil { milestoneTitle = pr.Milestone.Title } fmt.Fprintf(out, "milestone:\t%s\n", milestoneTitle) fmt.Fprintf(out, "number:\t%d\n", pr.Number) fmt.Fprintf(out, "url:\t%s\n", pr.URL) fmt.Fprintf(out, "additions:\t%s\n", cs.Green(strconv.Itoa(pr.Additions))) fmt.Fprintf(out, "deletions:\t%s\n", cs.Red(strconv.Itoa(pr.Deletions))) var autoMerge string if pr.AutoMergeRequest == nil { autoMerge = "disabled" } else { autoMerge = fmt.Sprintf("enabled\t%s\t%s", pr.AutoMergeRequest.EnabledBy.Login, strings.ToLower(pr.AutoMergeRequest.MergeMethod)) } fmt.Fprintf(out, "auto-merge:\t%s\n", autoMerge) fmt.Fprintln(out, "--") fmt.Fprintln(out, pr.Body) Lines 180 to 271 in 06e438b
// Header (Title and State) fmt.Fprintf(out, "%s #%d\n", cs.Bold(pr.Title), pr.Number) fmt.Fprintf(out, "%s • %s wants to merge %s into %s from %s • %s\n", shared.StateTitleWithColor(cs, *pr), pr.Author.Login, text.Pluralize(pr.Commits.TotalCount, "commit"), pr.BaseRefName, pr.HeadRefName, text.FuzzyAgo(opts.Now(), pr.CreatedAt), ) // added/removed fmt.Fprintf(out, "%s %s", cs.Green("+"+strconv.Itoa(pr.Additions)), cs.Red("-"+strconv.Itoa(pr.Deletions)), ) // checks checks := pr.ChecksStatus() if summary := shared.PrCheckStatusSummaryWithColor(cs, checks); summary != "" { fmt.Fprintf(out, " • %s\n", summary) } else { fmt.Fprintln(out) } // Reactions if reactions := shared.ReactionGroupList(pr.ReactionGroups); reactions != "" { fmt.Fprint(out, reactions) fmt.Fprintln(out) } // Metadata if reviewers := prReviewerList(*pr, cs); reviewers != "" { fmt.Fprint(out, cs.Bold("Reviewers: ")) fmt.Fprintln(out, reviewers) } if assignees := prAssigneeList(*pr); assignees != "" { fmt.Fprint(out, cs.Bold("Assignees: ")) fmt.Fprintln(out, assignees) } if labels := prLabelList(*pr, cs); labels != "" { fmt.Fprint(out, cs.Bold("Labels: ")) fmt.Fprintln(out, labels) } if projects := prProjectList(*pr); projects != "" { fmt.Fprint(out, cs.Bold("Projects: ")) fmt.Fprintln(out, projects) } if pr.Milestone != nil { fmt.Fprint(out, cs.Bold("Milestone: ")) fmt.Fprintln(out, pr.Milestone.Title) } // Auto-Merge status autoMerge := pr.AutoMergeRequest if autoMerge != nil { var mergeMethod string switch autoMerge.MergeMethod { case "MERGE": mergeMethod = "a merge commit" case "REBASE": mergeMethod = "rebase and merge" case "SQUASH": mergeMethod = "squash and merge" default: mergeMethod = fmt.Sprintf("an unknown merge method (%s)", autoMerge.MergeMethod) } fmt.Fprintf(out, "%s %s by %s, using %s\n", cs.Bold("Auto-merge:"), cs.Green("enabled"), autoMerge.EnabledBy.Login, mergeMethod, ) } // Body var md string var err error if pr.Body == "" { md = fmt.Sprintf("\n %s\n\n", cs.Gray("No description provided")) } else { md, err = markdown.Render(pr.Body, markdown.WithTheme(opts.IO.TerminalTheme()), markdown.WithWrap(opts.IO.TerminalWidth())) if err != nil { return err } } fmt.Fprintf(out, "\n%s\n", md)
There are a few fields that won't be available, but overall it might help with having a similar UI experience.
What do you think?
I second this feature!
- addedhelp wantedContributions welcomeContributions welcomeand removedmore-info-neededMore info needed from user/contributorMore info needed from user/contributor
on Jan 16, 2024 I've just labelled this
help wantedto indicate that we are happy to accept contributions for it, but I am aware you've already opened a PR for discussion @v1v 🚀
Describe the feature or problem you’d like to solve
I can test my scripts without the need to use echos by flags.
Proposed solution
How will it benefit CLI and its users?
Introducing a --dry-run flag to
gh pr createwill help people test their workflows/scripts without the need to do echos.Additional context
#1145 suggested raising a PR for this particular case.