From 0dd961a1f2158e3d4b4d76accc8a8d109a25364a Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Wed, 6 Sep 2023 13:32:37 -0700 Subject: [PATCH 1/2] Allow repo creation when repo is a redirect * Check name of repo against provided spec, if they are different assume it's a redirect and allow repo creation. --- R/github.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/github.R b/R/github.R index 818366202..45ac3d954 100644 --- a/R/github.R +++ b/R/github.R @@ -268,6 +268,7 @@ check_no_origin <- function() { } check_no_github_repo <- function(owner, repo, host) { + spec <- glue("{owner}/{repo}") repo_found <- tryCatch( { repo_info <- gh::gh( @@ -275,14 +276,16 @@ check_no_github_repo <- function(owner, repo, host) { owner = owner, repo = repo, .api_url = host ) - TRUE + # FALSE if there is a redirect due to renamed repo + # so we should be able to push, otherwise + # TRUE if it really exists. #1893 + repo_info$full_name == spec }, "http_error_404" = function(err) FALSE ) if (!repo_found) { return(invisible()) } - spec <- glue("{owner}/{repo}") empirical_host <- parse_github_remotes(repo_info$html_url)$host ui_stop("Repo {ui_value(spec)} already exists on {ui_value(empirical_host)}") } From af2e5c7a62d75ea35bb175d5c297ec2c4548188e Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Tue, 23 Jul 2024 12:00:40 -0700 Subject: [PATCH 2/2] Tweaks from playing with this locally --- R/github.R | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/R/github.R b/R/github.R index 45ac3d954..1727a187c 100644 --- a/R/github.R +++ b/R/github.R @@ -271,14 +271,13 @@ check_no_github_repo <- function(owner, repo, host) { spec <- glue("{owner}/{repo}") repo_found <- tryCatch( { - repo_info <- gh::gh( - "/repos/{owner}/{repo}", - owner = owner, repo = repo, - .api_url = host - ) - # FALSE if there is a redirect due to renamed repo - # so we should be able to push, otherwise - # TRUE if it really exists. #1893 + repo_info <- gh::gh("/repos/{spec}", spec = spec, .api_url = host) + # when does repo_info$full_name != the spec we sent? + # this happens if you reuse the original name of a repo that has since + # been renamed + # there's no 404, because of the automatic redirect, but you CAN create + # a new repo with this name + # https://github.com/r-lib/usethis/issues/1893 repo_info$full_name == spec }, "http_error_404" = function(err) FALSE