api command: support {owner} and {repo} placeholders#1165
Conversation
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.
I don't have a better alternative to suggest and I see nothing wrong with the |
|
@mislav did you want to push commits for updating docs? or should I merge this? |
There was a problem hiding this comment.
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.
|
@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 $ 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. |
|
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 { ... }
}
}
' |
When
:ownerand:repostrings are found in request path (for REST requests) or--field, -Fvalues, 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:
TODO:
repos/:owner/:reposyntax, which I think looks nice in URLs, but likely odd anywhere else (such as in a GraphQL query).apicommand docsRef. #332