Skip to content

Add the api --preview flag to opt into GitHub API previews - #3077

Merged
mislav merged 1 commit into
trunkfrom
api-preview
Mar 4, 2021
Merged

mislav merged 1 commit into
trunkfrom
api-preview

Conversation

@mislav

@mislav mislav commented Mar 3, 2021 •

Copy link
Copy Markdown
Contributor

This was previously available manually via the -H flag, but it was verbose, especially when opting into multiple previews.

Before:

gh api -H 'Accept: application/vnd.github.nebula-preview+json, application/vnd.github.baptiste-preview, application/vnd.github.squirrel-girl-preview'

Now:

gh api -p nebula,baptiste -p squirrel-girl

I feel like this shorter version lends itself really well to usage via aliases.

Questions:

  • Is "preview" fine, or too ambiguous of a word in this context?
  • Is -p fine as a shorthand or would we want to use it for something else in the near future?

This was previously available manually via the `-H` flag, but it was
verbose, especially when opting into multiple previews.
@mislav
mislav requested a review from a team March 3, 2021 19:16
@samcoe

samcoe commented Mar 3, 2021

Copy link
Copy Markdown
Contributor

This is a nice improvement. The preview headers are quite verbose.

I think "preview"/"p" are both good since that is what the docs call them and I can't think of another use for the "p" shorthand.

From my understanding these previews are only available in the REST API, do we want to add a note about that to the documentation?

@samcoe samcoe 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.

I left a couple questions but nothing blocking 👍

Comment thread pkg/cmd/api/api.go
}

func previewNamesToMIMETypes(names []string) string {
types := []string{fmt.Sprintf("application/vnd.github.%s-preview+json", names[0])}

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.

What is the reason why +json is only appended to the first preview header? I was unable to find anything in the media types docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Accept headers can list multiple MIME types, and is sufficient that only one of them specifies the json format, while the others are merely to activate additional previews and need not repeat +json any further.

@vilmibm vilmibm 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.

so excited for this; i do a lot locally with projects and this is going to help a ton.

@mislav
mislav merged commit 1eefb6b into trunk Mar 4, 2021
@mislav
mislav deleted the api-preview branch March 4, 2021 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants