gh
gh copied to clipboard
Handle API substitution format?
i.e. gh::gh("/repos/hadley/dplyr")
gives:
...
"statuses_url": "https://api.github.com/repos/hadley/dplyr/statuses/{sha}",
...
"git_commits_url": "https://api.github.com/repos/hadley/dplyr/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/hadley/dplyr/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/hadley/dplyr/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/hadley/dplyr/contents/{+path}",
"compare_url": "https://api.github.com/repos/hadley/dplyr/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/hadley/dplyr/merges",
...
Although it's not clear whether that's quite consistent enough to be parseable.
Oh, https://developer.github.com/v3/#hypermedia says these are URI templates, as described in https://tools.ietf.org/html/rfc6570.
So we probably need a uritemplate micropackage
Yes, these can be potentially useful, to walk the network of GH objects, although I am not entirely sure how we would do that, especially without proper classes for repos, users, PRs, etc.
THere is even a test suite: https://github.com/uri-templates/uritemplate-test
In the short term, I was mostly thinking that this might be another source of copy-and-paste urls.
OK, maybe I'll write an uritemplate package. I guess Ropensci could use that, too, assuming it is used by other APIs as well. Is it @sckott?
haven't seen templates very often in servers, but I'm going to implement them in my request
pkg and in webmockr
, so started https://github.com/ropenscilabs/urltemplate a while back but not useable yet
@sckott Cool!
I've accidentally made considerable progress towards this in:
- 05f0b49152602274ad3f416abd880c8df03a0268
- 6a821910ad8e5ec7381d747b329edb8f498b7386
because the main API documentation uses URI templates now.
However this form does not currently work:
gh::gh(
"https://api.github.com/repos/tidyverse/dplyr/branches{/branch}",
branch = "master"
)
#> Error in gh_process_response(raw):
#> GitHub API error (404): 404 Not Found
#> Message: Not Found
#> Read more at https://docs.github.com/rest
#>
#> URL not found: https://api.github.com/repos/tidyverse/dplyr/branches%7B/branch%7D?branch=master
i.e. with the /
inside the final {}
(indicating that the entire suffix is optional). This form never appears in the docs, so my simple approach to URI templates doesn't anticipate that.
Also now in httr2::req_template()
, so I suspect we can close this issue.