Skip to content

Add JSON output support to pr create - #13798

Open
natsu0529 wants to merge 4 commits into
cli:trunkfrom
natsu0529:add-json-jq-pr-create
Open

Add JSON output support to pr create#13798
natsu0529 wants to merge 4 commits into
cli:trunkfrom
natsu0529:add-json-jq-pr-create

Conversation

@natsu0529

@natsu0529 natsu0529 commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Fixes #11247.

Adds --json and --jq support to gh pr create without taking over the existing PR-template --template flag.

Details

  • Returns id, number, and url from pull request creation so they can be exported as JSON.
  • Adds a JSON flag helper for commands that need --json and --jq but cannot expose the output-formatting --template flag.
  • Covers command parsing, JSON output, jq filtering, and acceptance flow for PR creation.

Validation

  • go test ./pkg/cmdutil
  • go test ./pkg/cmd/pr/create
  • go test ./api
  • env -i HOME="$HOME" PATH="$PATH" USER="$USER" TMPDIR="${TMPDIR:-/tmp}" TERM=xterm-256color go test ./...
  • env -u NO_COLOR TERM=xterm-256color PATH="$(go env GOPATH)/bin:$PATH" make lint

Note: a first go test ./... run in the local shell failed because the shell environment had TERM=dumb, NO_COLOR=1, and PAGER=cat; rerunning in a clean terminal-like environment passed.

@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Jul 6, 2026
@natsu0529 natsu0529 changed the title [codex] Add JSON output support to pr create Add JSON output support to pr create Jul 6, 2026
@natsu0529 natsu0529 changed the title Add JSON output support to pr create Add JSON output support to pr create Jul 6, 2026
@natsu0529
natsu0529 marked this pull request as ready for review July 6, 2026 12:29
@natsu0529
natsu0529 requested a review from a team as a code owner July 6, 2026 12:29
@natsu0529
natsu0529 requested review from BagToad and Copilot July 6, 2026 12:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds JSON export capabilities to gh pr create while preserving its existing --template/-T PR-body-template flag, enabling scripts to reliably capture metadata (id/number/url) from newly created pull requests.

Changes:

  • Introduces a cmdutil.AddJSONAndJQFlags helper to support --json and --jq without also defining an output --template flag (and without shorthands).
  • Extends gh pr create to emit JSON (and optional jq-filtered output) for the created PR, exporting id, number, and url.
  • Updates API query + unit/acceptance coverage to include PR number and validate JSON/jq flows.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/cmdutil/json_flags.go Adds JSON+JQ-only flag helper and updates flag validation to optionally exclude --template from JSON flag handling.
pkg/cmdutil/json_flags_test.go Adds focused tests for the new JSON+JQ-only helper, including interaction with a host command’s own --template flag.
pkg/cmd/pr/create/create.go Wires --json/--jq into pr create, blocks incompatible --dry-run usage, and writes JSON output for created PRs.
pkg/cmd/pr/create/create_test.go Adds parsing and run-path tests validating JSON output, jq filtering, and interactions with PR-template --template.
api/queries_pr.go Ensures PR creation mutation returns number in addition to id and url.
acceptance/testdata/pr/pr-create-json-output.txtar Adds end-to-end acceptance coverage for pr create --json and --jq output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot removed the needs-triage needs to be reviewed label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --json and --jq to gh pr create

3 participants