Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

# gh (development version)

* gh now accepts lower-case methods i.e. both `gh::gh("get /users/hadley/repos")` and `gh::gh("GET /users/hadley/repos")` work (@maelle, #167).

* Response headers (`"response_headers"`) and response content
(`"response_content")` are now returned in error conditions so that error
handlers can use information, such as the rate limit reset header, when
Expand Down
8 changes: 5 additions & 3 deletions R/gh_request.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ gh_set_verb <- function(x) {
return(x)
}

x$method <- gsub("^([^/ ]+)\\s+.*$", "\\1", x$endpoint)
stopifnot(x$method %in% c("GET", "POST", "PATCH", "PUT", "DELETE"))
x$endpoint <- gsub("^[A-Z]+ ", "", x$endpoint)
# Method can be lower-case (e.g. copy-pasting from API docs in Firefox)
method <- gsub("^([^/ ]+)\\s+.*$", "\\1", x$endpoint)
x$endpoint <- gsub(sprintf("^%s+ ", method), "", x$endpoint)
# Now switch method to upper-case
x$method <- toupper(method)
x
}

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/_snaps/gh_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# gh_make_request() errors if unknown verb

Unknown HTTP verb: "GEEET"

4 changes: 4 additions & 0 deletions tests/testthat/test-gh_request.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ test_that("gh_set_url() ensures URL is in 'API form'", {
out <- gh_set_url(input)
expect_equal(out$api_url, "https://github.acme.com/api/v3")
})

test_that("gh_make_request() errors if unknown verb", {
expect_snapshot_error(gh("geeet /users/hadley/repos", .limit = 2))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-mock-repos.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test_that("repos, some basics", {
expect_false(res$has_wiki)

res <- gh(
TMPL("PATCH /repos/{owner}/{repo}"),
TMPL("patch /repos/{owner}/{repo}"),
owner = "gh-testing",
repo = test_repo,
name = test_repo,
Expand Down