R/user-current-list-repos.R

#' List the repos that the authenticated user owns or has access to
#'
#' @md
#' @param api_endpoint URL prefix for your gitea server (no trailing '/')
#' @param gitea_token NOTE: we use `access_token` in the package
#' @return data frame
#' @export
#' @examples \dontrun{
#' user_current_list_repos()
#' }
user_current_list_repos <- function(api_endpoint = Sys.getenv("GITEA_BASE_URL"),
                                    gitea_token = Sys.getenv("GITEA_PAT")) {

  api_endpoint <- sub("/$", "", api_endpoint)

  gitea_url <- file.path(api_endpoint, "api/v1", sub("^/", "", "/user/repos"))

  httr::VERB(
    verb = "GET",
    url = gitea_url,
    query = list(access_token = gitea_token),
    encode = "json",
    httr::user_agent("crumpets r package <https://gitlab.com/hrbrmstr/crumpets")
  ) -> res

  httr::stop_for_status(res)

  out <- httr::content(res, as = "text")
  out <- jsonlite::fromJSON(out)

  out
}
hrbrmstr/crumpets documentation built on May 4, 2019, 8:40 a.m.