gh icon indicating copy to clipboard operation
gh copied to clipboard

space in parameter messes with gh_next()

Open jayjacobs opened this issue 6 months ago • 0 comments

I may be scratching the surface on this elusive thing, but I am trying to run a github search, and the search requires different elements of the search query be separated by a space. I am trying to search for repositories with a keyword and after some created date.

The first query works great, but passing that into a second query causes the query string to be slightly modified and thus the search to be modified returning no results.

Everything works great (as expected) if the search parameter has no spaces in it (just using a keyword without date filter).

library(gh)
rez1 <- gh(endpoint = "/search/repositories", 
           .params=list(q="metasploit created:>2023-05-23T08:40:24Z"), 
           per_page = 100)
cat("total_count:", rez1$total_count, "\nlength:", length(rez1$items), "\n")
# total_count: 600 
# length: 100 

# has link header in response for pagination, notice the url encoding
> attr(rez1, "response")['link']
# <httr2_headers>
# link: <https://api.github.com/search/repositories?q=metasploit+created%3A%3E2023-05-23T08%3A40%3A24Z&per_page=100&page=2>; rel="next", <https://api.github.com/search/repositories?q=metasploit+created%3A%3E2023-05-23T08%3A40%3A24Z&per_page=100&page=6>; rel="last"

# look at what query we sent:
attr(rez1, "request")['query']
# $query
# $query$q
# [1] "metasploit created:>2023-05-23T08:40:24Z"
# 
# $query$per_page
# [1] 100


# get the next page
rez2 <- gh_next(rez1)

# the output here suggests the query has changed perhaps?
cat("total_count:", rez2$total_count, "\nlength:", length(rez2$items), "\n")
total_count: 0 
length: 0 

# no link header in response 
"link" %in% names(attr(rez2, "response"))
# [1] FALSE

# Look at what we sent, space is replaced by a +, rest of string is not url encoded. 
attr(rez2, "request")['query']
# $query
# $query$q
# [1] "metasploit+created:>2023-05-23T08:40:24Z"
# 
# $query$per_page
# [1] "100"
# 
# $query$page
# [1] "2"

sessioninfo::package_info("attached")
#  package * version date (UTC) lib source
#  gh      * 1.4.1   2024-03-28 [1] CRAN (R 4.4.0)
# 
#  [1] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library

sessioninfo::platform_info()
#  setting  value
#  version  R version 4.4.0 (2024-04-24)
#  os       macOS Sonoma 14.5
#  system   aarch64, darwin20
#  ui       RStudio
#  language (EN)
#  collate  en_US.UTF-8
#  ctype    en_US.UTF-8
#  tz       America/Chicago
#  date     2024-08-22
#  rstudio  2024.04.1+748 Chocolate Cosmos (desktop)
#  pandoc   NA

jayjacobs avatar Aug 22 '24 17:08 jayjacobs