Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mislav
Copy link
Contributor

@mislav mislav commented Jun 11, 2020

When :owner and :repo strings are found in request path (for REST requests) or --field, -F values, expand them with appropriate values for the current repository. This makes it easier to make requests against local repositories without having to spell out the full repository name.

Examples:

$ gh api repos/:owner}/:repo/releases

TODO:

  • Discuss: is this placeholder syntax understandable? I've borrowed it from hub, but I don't think it has any precedent elsewhere. GitHub's REST API documentation has placeholders in the repos/:owner/:repo syntax, which I think looks nice in URLs, but likely odd anywhere else (such as in a GraphQL query).
  • Mention placeholders in api command docs

Ref. #332

When `{owner}` and `{repo}` strings are found in request path (for REST
requests) or `query` (for GraphQL), they are replaced with values from
the repository of the current working directory.
@mislav mislav requested review from probablycorey and vilmibm June 11, 2020 13:05
Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

excellent 👍

@vilmibm
Copy link
Contributor

vilmibm commented Jun 11, 2020

Discuss: is this placeholder syntax understandable? I've borrowed it from hub, but I don't think it has any precedent elsewhere. GitHub's REST API documentation has placeholders in the repos/:owner/:repo syntax, which I think looks nice in URLs, but likely odd anywhere else (such as in a GraphQL query).

I don't have a better alternative to suggest and I see nothing wrong with the {owner} approach.

@vilmibm
Copy link
Contributor

vilmibm commented Jun 11, 2020

@mislav did you want to push commits for updating docs? or should I merge this?

Copy link
Contributor

@probablycorey probablycorey left a comment

Choose a reason for hiding this comment

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

This will be very handy. My only concern is the single {} around the vars. It is almost certainly fine, but it doesn't look like a replacement to me. For me, using the GitHub api doc format of /:user/:repo or double curlys /{{user}}/{{repo}} would be a stronger signal to recognize that they will be replaced.

@mislav
Copy link
Contributor Author

mislav commented Jun 11, 2020

@probablycorey Good point! How do you feel about this synax:

$ gh api repos/:owner/:repo/releases

# populate `:owner`, `:repo` into the query via GraphQL variables
$ gh api graphql -F owner=:owner -F repo=:repo -f query='
query(owner: $owner, name: $repo) {
  repository(owner: $owner, name: $repo) {
    releases { ... }
  }
}
'

Or I could get behind {{...}} as well, it's just that for a construct such as {{owner}}/{{repo}}, it can seem noisy:

$ gh api repos/{{owner}}/{{repo}}/releases

$ gh api graphql -f query='
{
  repository(owner: "{{owner}}", name: "{{repo}}") {
    releases { ... }
  }
}
'

@vilmibm I wanted to update the docs myself once we have resolution on the syntax.

@mislav
Copy link
Contributor Author

mislav commented Jun 11, 2020

We ended up on:

$ gh api repos/:owner/:repo/releases

$ gh api graphql -F owner=:owner -F repo=:repo -f query='
query($owner: String!, $repo: String!) {
  repository(owner: $owner, name: $repo) {
    releases { ... }
  }
}
'

@vilmibm vilmibm merged commit db74ea0 into trunk Jun 11, 2020
@mislav mislav deleted the api-repo-placeholders branch June 25, 2020 14:35
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.

4 participants