Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make repo_exists more specific #114

Open
maelle opened this issue Jan 25, 2019 · 1 comment
Open

Make repo_exists more specific #114

maelle opened this issue Jan 25, 2019 · 1 comment

Comments

@maelle
Copy link
Contributor

maelle commented Jan 25, 2019

Currently, repo_exists will return FALSE if there's no repo with the same name for the account... but also if there's something wrong with the API.

repo_exists <- function(username, repo) {
  !inherits(
    try(gh::gh("GET /repos/:owner/:repo",
      owner = username,
      repo = repo
    ),
    silent = TRUE
    ),
    "try-error"
  )
}
@JaiPizGon
Copy link

JaiPizGon commented Nov 22, 2019

Not really sure if this make what you want, I'm relatively new to R and I'm not sure what inherits and the "{username}" and "{repo}" to pass arguments to functions really do. I try to maintain the format of the function, however at the bottom of the comment is what I would write in my package.

Solution 1 trying to maintain the function in the same format as yours:

#' Determine whether the repo already exists
#' @param username account name
#' @param repo repo name
#' @details very much inspired by available::available_on_github()
#' @noRd
repo_exists <- function(username, repo) {
  check_repo <- function(username, repo) {
    # Check repository in the API where all the packages are listed
    res <- jsonlite::fromJSON("http://rpkg-api.gepuro.net/rpkg?q={username}/{name}")
    # Check exactly that the repository exists on github
    any(res$url == "https://github.com/{username}/{name}.git")
  }
  !inherits(
    try(check_repo(
      username = username,
      repo = repo
    ),
    silent = TRUE
    ),
    "try-error"
  )
}

Solution 2 as I would do it:

#' Determine whether the repo already exists
#' @param username account name
#' @param repo repo name
#' @details very much inspired by available::available_on_github()
#' @noRd
repo_exists <- function(username, repo) {
  # Check repository in the API where all the packages are listed
  res <- jsonlite::fromJSON(paste0("http://rpkg-api.gepuro.net/rpkg?q=",username,"/",repo))
  # Check exactly that the repository exists on github
  any(res$url == "https://github.com/{username}/{name}.git")
}

Hope it helps.

EDIT 1 && 2: sorry, first comment on github and didn't know how to highlight code
EDIT 3: Function can be changed easily to give information about if only the username or only the package exists and give an error message saying if the user should change only his/her username or only the name of his/her package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants