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

Specifically handle offline case in pr_init() #2063

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
ui_bullets(c("v" = "Pulling changes from {.val {remref}}."))
git_pull(remref = remref, verbose = FALSE)
}
} else {
ui_bullets(c(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already warned that we can't do this above

"!" = "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
Loading