Skip to content

Commit

Permalink
Specifically handle offline case in pr_init()
Browse files Browse the repository at this point in the history
I realised that we're checking whether or not the host is online further down, so we might as well use that a little earlier to give a more informative message.
  • Loading branch information
hadley committed Sep 20, 2024
1 parent 2cc9e5a commit b10b76c
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions R/pr.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,30 +167,41 @@ pr_init <- function(branch) {
cfg <- github_remote_config(github_get = NA)
check_for_bad_config(cfg)
tr <- target_repo(cfg, ask = FALSE)
online <- is_online(tr$host)

Check warning on line 170 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L170

Added line #L170 was not covered by tests

maybe_good_configs <- c("maybe_ours_or_theirs", "maybe_fork")
if (cfg$type %in% maybe_good_configs) {
if (!online) {

Check warning on line 172 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L172

Added line #L172 was not covered by tests
ui_bullets(c(
"x" = 'Unable to confirm the GitHub remote configuration is
"pull request ready".',
"i" = "You probably need to configure a personal access token for
{.val {tr$host}}.",
"i" = "See {.run usethis::gh_token_help()} for help with that.",
"i" = "(Or maybe we're just offline?)"
"x" = "You are not currently online.",
"i" = "You can still create a local branch, but you won't be able to setup
or push to the remote branch."

Check warning on line 176 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L174-L176

Added lines #L174 - L176 were not covered by tests
))
if (ui_github_remote_config_wat(cfg)) {
if (ui_nah("Do you want to continue?")) {

Check warning on line 178 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L178

Added line #L178 was not covered by tests
ui_bullets(c("x" = "Cancelling."))
return(invisible())
}
} else {
maybe_good_configs <- c("maybe_ours_or_theirs", "maybe_fork")
if (cfg$type %in% maybe_good_configs) {
ui_bullets(c(
"x" = 'Unable to confirm the GitHub remote configuration is
"pull request ready".',
"i" = "You probably need to configure a personal access token for
{.val {tr$host}}.",
"i" = "See {.run usethis::gh_token_help()} for help with that.",
))
if (ui_github_remote_config_wat(cfg)) {
ui_bullets(c("x" = "Cancelling."))
return(invisible())

Check warning on line 194 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L183-L194

Added lines #L183 - L194 were not covered by tests
}
}
}

default_branch <- git_default_branch()
default_branch <- if (online) git_default_branch() else guess_local_default_branch()

Check warning on line 199 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L199

Added line #L199 was not covered by tests
challenge_non_default_branch(
"Are you sure you want to create a PR branch based on a non-default branch?",
default_branch = default_branch
)

online <- is_online(tr$host)
if (online) {
# this is not pr_pull_source_override() because:
# a) we may NOT be on default branch (although we probably are)
Expand All @@ -213,10 +224,6 @@ pr_init <- function(branch) {
ui_bullets(c("v" = "Pulling changes from {.val {remref}}."))
git_pull(remref = remref, verbose = FALSE)
}
} else {
ui_bullets(c(
"!" = "Unable to pull changes for current branch, since we are offline."
))
}

ui_bullets(c("v" = "Creating and switching to local branch {.val {branch}}."))
Expand Down

0 comments on commit b10b76c

Please sign in to comment.