Skip to content

gh search prs should allow getting unfiltered --json when no fields are passed; and should imply --json with no fields when --jq is used and --json isn't explicitly set #10385

@0xdevalias

Description

@0xdevalias

Describe the feature or problem you’d like to solve

When running gh search prs with --json, I want to be able to get all of the json, without needing to manually specify each key:

⇒ gh search prs "Bump node-llama-cpp author:app/dependabot" --repo jehna/humanify --sort=created --order=asc --json | jq | subl

Specify one or more comma-separated fields for `--json`:
  assignees
  author
  authorAssociation
  body
  closedAt
  commentsCount
  createdAt
  id
  isDraft
  isLocked
  isPullRequest
  labels
  number
  repository
  state
  title
  updatedAt
  url

There doesn't even seem to be a 'magic field keyword' to imply "give me everything" currently:

⇒ gh search prs "Bump node-llama-cpp author:app/dependabot" --repo jehna/humanify --sort=created --order=asc --json '*' | jq | subl
Unknown JSON field: "*"

Available fields:
..snip..

If I omit --json entirely, it doesn't give me it in json:

⇒ gh search prs "Bump node-llama-cpp author:app/dependabot" --repo jehna/humanify --sort=created --order=asc | cat
jehna/humanify  25      merged  Bump node-llama-cpp from 3.0.0-beta.42 to 3.0.0-beta.44 dependencies    2024-08-11T18:55:54Z
jehna/humanify  110     closed  Bump node-llama-cpp from 3.0.0-beta.44 to 3.0.0-beta.45 dependencies    2024-09-23T02:16:40Z
..snip..

Apparently I can't specify --jq without also specifying --json, so I can't even attempt to hack around it by passing something like --jq '.':

⇒ gh search prs "Bump node-llama-cpp author:app/dependabot" --repo jehna/humanify --sort=created --order=asc --jq '.'

cannot use `--jq` without specifying `--json`

Proposed solution

  • When I pass --json with no fields, it should give me the unfiltered json.
  • When I pass --jq, but haven't specified --json explicitly; it should default to implying that --json was passed with no filter, and return the full json, which then has the --jq pattern applied to it.
  • When I pass --json with fields, it should continue to work as it currently does

A less desirable potential alternative is that there is some 'magic fields keyword' that implies 'give me the json unfiltered'; though personally, I would rather be able to just pass --json without any fields for that; or not even have to and have --jq imply it.

Additional context

Relevant snippets from the help text:

⇒ gh search prs -h

..snip..

  -q, --jq expression           Filter JSON output using a jq expression
      --json fields             Output JSON with the specified fields

..snip..

  -t, --template string         Format JSON output using a Go template; see "gh help formatting"

..snip..

JSON FIELDS
  assignees, author, authorAssociation, body, closedAt, commentsCount, createdAt,
  id, isDraft, isLocked, isPullRequest, labels, number, repository, state, title,
  updatedAt, url

..snip..

Tangentially Related

There have been a number of other json/jq Quality of Life issues I've opened recently; and some awesome PRs associated with some of them, made by @heaths . I'm not sure of the deeper specifics as to whether any of them would crossover with this at an implementation level; but from a user perspective, it's kind of weird/confusing feeling when different CLI commands seem to handle json/jq differently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-searchrelating to the gh search commandneeds-investigationCLI team needs to investigateneeds-productAn issue that requires prioritization considerations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions