forked from r-lib/usethis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Harden use_github() re: partial setup (r-lib#516)
* Break use_github flow into smaller pieces Now checks individual for origin remote (i.e. is there a GitHub repo), description fields, and push-ability for master. Fixes r-lib#221 * Be consistent with create_from_github(), use_tidy_thanks() We're trying to standardize on "repo_spec" to refer to a "owner/repo" combination * Open repo in browser after we (hopefully) have pushed * Add more tips for getting the git situation sorted out for use_github() * Remove `base_path` and `path` arguments from git and github helpers * Consistent approach to multi-line ui_stop() * More consistent if {} else {} style
- Loading branch information
Showing
19 changed files
with
252 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ Imports: | |
rlang, | ||
rprojroot (>= 1.2), | ||
rstudioapi, | ||
stats, | ||
utils, | ||
whisker, | ||
withr, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
## suppress the warning about multiple remotes, which is triggered by | ||
## the common "origin" and "upstream" situation, e.g., fork and clone | ||
gh_tree_remote <- function(path) { | ||
suppressWarnings(gh::gh_tree_remote(path)) | ||
github_remotes <- function() { | ||
remotes <- git_remotes() | ||
if (length(remotes) == 0) return(NULL) | ||
m <- vapply(remotes, function(x) grepl("github", x), logical(1)) | ||
if (length(m) == 0) return(NULL) | ||
remotes[m] | ||
} | ||
|
||
## Git remotes --> filter for GitHub --> owner, repo, repo_spec | ||
github_owner <- function(path = proj_get()) { | ||
gh_tree_remote(path)[["username"]] | ||
github_origin <- function() { | ||
r <- github_remotes() | ||
if (length(r) == 0) return(NULL) | ||
parse_github_remotes(r)[["origin"]] | ||
} | ||
|
||
github_repo <- function(path = proj_get()) { | ||
gh_tree_remote(path)[["repo"]] | ||
github_owner <- function() { | ||
github_origin()[["owner"]] | ||
} | ||
|
||
github_repo_spec <- function(path = proj_get()) { | ||
paste0(gh_tree_remote(path), collapse = "/") | ||
github_repo <- function() { | ||
github_origin()[["repo"]] | ||
} | ||
|
||
github_repo_spec <- function() { | ||
paste0(github_origin(), collapse = "/") | ||
} | ||
|
||
## repo_spec --> owner, repo | ||
## TODO: could use more general facilities for parsing GitHub URL/spec | ||
parse_repo_spec <- function(repo_spec) { | ||
repo_split <- strsplit(repo_spec, "/")[[1]] | ||
if (length(repo_split) != 2) { | ||
|
@@ -29,3 +35,16 @@ parse_repo_spec <- function(repo_spec) { | |
|
||
spec_owner <- function(repo_spec) parse_repo_spec(repo_spec)$owner | ||
spec_repo <- function(repo_spec) parse_repo_spec(repo_spec)$repo | ||
|
||
## named vector or list of Git remote URLs --> named list of (owner, repo) | ||
parse_github_remotes <- function(x) { | ||
# https://github.com/r-lib/devtools.git --> rlib, devtools | ||
# https://github.com/r-lib/devtools --> rlib, devtools | ||
# [email protected]:r-lib/devtools.git --> rlib, devtools | ||
re <- "github[^/:]*[/:]([^/]+)/(.*?)(?:\\.git)?$" | ||
## on R < 3.4.2, regexec() fails to apply as.character() to first 2 args, | ||
## though it is documented | ||
m <- regexec(re, as.character(x)) | ||
match <- stats::setNames(regmatches(as.character(x), m), names(x)) | ||
lapply(match, function(y) list(owner = y[[2]], repo = y[[3]])) | ||
} |
Oops, something went wrong.