Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
v1v opened this issue Nov 24, 2023 · 5 comments · Fixed by #8376
Closed

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

v1v opened this issue Nov 24, 2023 · 5 comments · Fixed by #8376
Labels
enhancement a request to improve CLI gh-pr relating to the gh pr command help wanted Contributions welcome

Comments

@v1v
Copy link
Contributor

v1v commented Nov 24, 2023

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.

@v1v v1v added the enhancement a request to improve CLI label Nov 24, 2023
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label Nov 24, 2023
@williammartin
Copy link
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?

@v1v
Copy link
Contributor Author

v1v commented 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

@v1v
Copy link
Contributor Author

v1v commented Nov 27, 2023

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?

@bombillazo
Copy link

I second this feature!

@williammartin
Copy link
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 🚀

@williammartin williammartin added the gh-pr relating to the gh pr command label Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a request to improve CLI gh-pr relating to the gh pr command help wanted Contributions welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@williammartin @v1v @bombillazo @cliAutomation and others