R/get_description.R

Defines functions get_description

Documented in get_description

#' Get description of the package repo
#'
#' @inheritParams get_contents
#' @param branch master by default
#'
#' @return a tibble of basic information from the DESCRIPTION
#' @export
#'
#' @details
#' https://platform.github.community/t/query-repo-contents-with-graphql-api/1896
#' @examples
#' library("magrittr")
#' get_description(owner = "ropensci", repo = "ropenaq")
get_description <- function(owner, repo, branch = "master"){

  if(!is_package_repo(owner, repo)){
    stop("This repo is not a package repo, well it doesn't have NAMESPACE, man, R and DESCRIPTION.")
  }

  query <- paste0('query {
                  repository(name: "', repo,'", owner: "', owner,'") {
                  object(expression: "', branch, ':', "DESCRIPTION", '") {
                  ... on Blob {
                  text
                  }
                  }
                  }
}')

  qry <- ghql::Query$new()
  qry$query('foobar', query)


  temp_path <- paste0(tempdir(), "\\DESCRIPTION")

  create_client()$exec(qry$queries$foobar) %>%
    jqr::jq(".data.repository.object.text") %>%
    jsonlite::fromJSON() %>%
    writeLines(temp_path)

  description <- desc::description$new(file = temp_path)

  file.remove(temp_path)

  tibble::tibble(package = description$get("Package"),
                 repo = repo,
                 owner = owner,
                 branch = branch,
                 title = description$get("Title"),
                 maintainer = description$get_maintainer(),
                 authors = description$get_authors(),
                 dependencies = list(description$get_deps()),
                 system_requirements = description$get("SystemRequirements"),
                 description = description$get("Description"))

  }
maelle/ghrecipes documentation built on May 20, 2022, 5:18 a.m.