Skip to content

Add a dry-run flag to gh pr create #8375

Description

@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 create will help people test their workflows/scripts without the need to do echos.

Additional context

#1145 suggested raising a PR for this particular case.

Activity

  1. williammartin commented on Nov 24, 2023

    @williammartin
    Member

    Hey @v1v thanks for creating this. As mentioned in #1145 we are open to adding dry-run to individual commands. Perhaps you can give a bit more detail about what you'd like to see as a result of providing --dry-run here? What kind of output would you want?

  2. added
    more-info-neededMore info needed from user/contributor
    and removed on Nov 24, 2023
  3. v1v commented on Nov 24, 2023

    @v1v
    ContributorAuthor

    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

  4. v1v commented on Nov 27, 2023

    @v1v
    ContributorAuthor

    After thinking a bit more about this idea, I'd like to propose a similar output to the one when running gh pr view:

    • cli/pkg/cmd/pr/view/view.go

      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)
    • cli/pkg/cmd/pr/view/view.go

      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?

  5. bombillazo commented on Dec 7, 2023

    @bombillazo

    I second this feature!

  6. added and removed
    more-info-neededMore info needed from user/contributor
    on Jan 16, 2024
  7. williammartin commented on Jan 16, 2024

    @williammartin
    Member

    I've just labelled this help wanted to indicate that we are happy to accept contributions for it, but I am aware you've already opened a PR for discussion @v1v 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIgh-prrelating to the gh pr commandhelp wantedContributions welcome

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions