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

Accommodating custom GitHub URL's #506

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
76344c5
Added param for alternate github repo path
ghuiber Jun 24, 2014
e9e19a2
Fixed defaults for alternate github repo path
ghuiber Jun 24, 2014
6e38904
Changed repo_path to github_url
ghuiber Jun 25, 2014
4fa78d3
Deleted two devtools.c files.
ghuiber Jun 25, 2014
761c8bd
Added install_github_enterprise()
ghuiber Jun 26, 2014
de5aea5
Fixed small typo
ghuiber Jun 26, 2014
3b30f91
Markup fixed, links checked, rebuilt
ghuiber Jun 26, 2014
3a879c0
Fixed my install-github.r, rebuilt.
ghuiber Jun 27, 2014
d2e7ee9
Deleted the two devtools.c files.
ghuiber Jun 27, 2014
9adbfd2
Fixed doc for install_github_enterprise()
ghuiber Jun 27, 2014
1f9b796
Updated parameter sets for install_github[_enterprise]() and the outp…
ghuiber Jul 1, 2014
aba1e87
Rebuild docs for install_github[_enterprise]()
ghuiber Jul 1, 2014
2123613
Fixed the install_url() call
ghuiber Jul 1, 2014
600ffcd
Fixed has_devel.r to match change by @krlmlr
ghuiber Jul 3, 2014
a50212c
Merge remote-tracking branch 'upstream/master'
ghuiber Jul 14, 2014
2f99c35
Set github_url to API v3 redirect
ghuiber Jul 16, 2014
2b815b9
Merge remote-tracking branch 'upstream/master'
ghuiber Jul 16, 2014
c0af286
Deleted man/svn_path.Rd
ghuiber Jul 23, 2014
b78b21e
Merge remote-tracking branch 'upstream/master'
ghuiber Aug 8, 2014
fe65692
Took another crack at implementing API v3 archive URL on enterprise s…
ghuiber Aug 14, 2014
60343ce
Less typing, right URL
ghuiber Aug 15, 2014
9f8bbac
Fixed url param in github_ref.github_pull()
ghuiber Aug 19, 2014
3f02765
Quick fix
ghuiber Aug 21, 2014
2e64563
New Rd file for install_github_enterprise()
ghuiber Aug 21, 2014
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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export(dev_meta)
export(dev_mode)
export(dev_packages)
export(devtest)
export(devtools_git_enterprise)
export(document)
export(eval_clean)
export(evalq_clean)
Expand All @@ -54,6 +55,7 @@ export(install_bitbucket)
export(install_deps)
export(install_git)
export(install_github)
export(install_github_enterprise)
export(install_gitorious)
export(install_local)
export(install_svn)
Expand Down
2 changes: 1 addition & 1 deletion R/decompress.r
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ getrootdir <- function(file_list) {

my_unzip <- function(src, target, unzip = getOption("unzip")) {
if (unzip == "internal") {
unzip(src, exdir = target)
return(unzip(src, exdir = target))
}

args <- paste(
Expand Down
107 changes: 92 additions & 15 deletions R/install-github.r
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#' supply to this argument. This is safer than using a password because
#' you can easily delete a PAT without affecting any others. Defaults to
#' the \code{GITHUB_PAT} environment variable.
#' @param github_url Defaults to NULL, so the default archive URL is served
#' from the GitHub API. You can set it to your custom Enterprise GitHub URL.
#' @param ... Other arguments passed on to \code{\link{install}}.
#' @param dependencies By default, installs all dependencies so that you can
#' build vignettes and use all functionality of the package.
Expand Down Expand Up @@ -45,16 +47,66 @@
#' }
install_github <- function(repo, username = NULL,
ref = "master", subdir = NULL,
auth_token = github_pat(), ...,
auth_token = github_pat(),
github_url=NULL, ...,
dependencies = TRUE) {

invisible(vapply(repo, install_github_single, FUN.VALUE = logical(1),
username = username, ref = ref, subdir = subdir, auth_token = auth_token,
..., dependencies = dependencies))
username = username, ref = ref, subdir = subdir,
auth_token = auth_token, github_url = github_url, ...,
dependencies = dependencies))
}

github_get_conn <- function(repo, username = NULL, ref = "master",
subdir = NULL, auth_token = NULL, ...) {
#' Convenience wrapper for \code{\link{install_github}}.
#'
#' This function allows you to install a package built
#' with \code{devtools} from a repo with a custom URL.
#'
#' @param repo Repository address in the format
#' \code{[username/]repo[/subdir][@@ref|#pull]}. Alternatively, you can
#' specify \code{username}, \code{subdir}, \code{ref} or \code{pull} using the
#' respective parameters (see below); if both is specified, the values in
#' \code{repo} take precedence.
#' @param username User name. Deprecate: please include username in the
#' \code{repo}
#' @param ref Desired git reference. Could be a commit, tag, or branch
#' name, or a call to \code{\link{github_pull}}. Defaults to \code{"master"}.
#' @param subdir subdirectory within repo that contains the R package.
#' @param auth_token To install from a private repo, generate a personal
#' access token (PAT) in \url{https://github.com/settings/applications} and
#' supply to this argument. This is safer than using a password because
#' you can easily delete a PAT without affecting any others. Defaults to
#' the \code{GITHUB_PAT} environment variable.
#' @param github_url Defaults to NULL, so the default archive URL is served
#' from the GitHub API. You can set it to your custom Enterprise GitHub URL.
#' @param ... Other arguments passed on to \code{\link{install}}.
#' @param dependencies By default, installs all dependencies so that you can
#' build vignettes and use all functionality of the package.
#' @export
#' @family package installation
#' @examples
#' \dontrun{
#' # To install from a private repo, use auth_token as described
#' # at ?install_github and either set the github_url parameter
#' # or let the ?devtools_git_enterprise helper retrieve it from
#' # the GITHUB_URL environment variable if it is set.
#' # Best practice is the latter.
#' install_github_enterprise("username/packagename", github_url = "https://github.scm.xyz.com")
#'
#' }
install_github_enterprise <- function(repo, username = NULL,
ref = "master", subdir = NULL,
auth_token = github_pat(),
github_url=devtools_git_enterprise(), ...,
dependencies = TRUE) {
install_github(repo, username = username, ref = ref, subdir = subdir,
auth_token = auth_token, github_url = github_url, ...,
dependencies = dependencies)
}

github_get_conn <- function(repo, username = NULL,
ref = "master", subdir = NULL,
auth_token = github_pat(), github_url=NULL, ...) {

params <- github_parse_path(repo)

Expand Down Expand Up @@ -86,7 +138,8 @@ github_get_conn <- function(repo, username = NULL, ref = "master",
repo = repo,
username = username,
ref = ref,
subdir = subdir
subdir = subdir,
url = github_url
)

param <- modifyList(param, github_ref(param$ref, param))
Expand All @@ -97,16 +150,20 @@ github_get_conn <- function(repo, username = NULL, ref = "master",
"from",
paste(username, collapse = ", "))

param$url <- paste(
"https://api.github.com", "repos", param$username, param$repo,
"zipball", param$ref, sep = "/")

url <- paste("https://api.github.com", "repos",sep="/")
# If github_url is given, a private repo is assumed.
if(!is.null(github_url)) {
url <- paste(github_url,"api/v3/repos",sep="/")
}
param$url <- paste(url, param$username, param$repo,
"zipball", param$ref, sep = "/")
param
}

install_github_single <- function(repo, username = NULL, ref = "master",
subdir = NULL, auth_token = NULL, ...) {
conn <- github_get_conn(repo, username, ref, subdir, auth_token, ...)
install_github_single <- function(repo, username = NULL, ref = "master",
subdir = NULL, auth_token = NULL,
github_url=NULL, ...) {
conn <- github_get_conn(repo, username, ref, subdir, auth_token, github_url, ...)
message(conn$msg)

# define before_install function that captures the arguments to
Expand Down Expand Up @@ -137,13 +194,13 @@ install_github_single <- function(repo, username = NULL, ref = "master",
append_field("SHA1", github_extract_sha1(bundle))
append_field("Subdir", conn$subdir)
}

# The downloaded file is always named by the package's name with extension .zip.
# install_github("shiny", "rstudio", "v/0/2/1")
# URL: https://api.github.com/repos/rstudio/shiny/zipball/v/0/2/1
# Output file: shiny.zip
install_url(conn$url, name = paste(conn$repo, ".zip", sep = ""), subdir = conn$subdir,
config = conn$auth, before_install = github_before_install, ...)
config = conn$auth, before_install = github_before_install, ...)
}

#' Resolve a token to a GitHub reference
Expand Down Expand Up @@ -171,6 +228,11 @@ github_pull <- function(pull) structure(pull, class = "github_pull")
# Retrieve the username and ref for a pull request
github_ref.github_pull <- function(x, param) {
host <- "https://api.github.com"

# resolve to custom URL if set
if(!is.null(param$url)) {
host <- paste(param$url,"api/v3",sep="/")
}
# GET /repos/:user/:repo/pulls/:number
path <- paste("repos", param$username, param$repo, "pulls", x, sep = "/")
r <- GET(host, path = path)
Expand Down Expand Up @@ -216,6 +278,7 @@ github_parse_path <- function(path) {
github_rx <- sprintf("^(?:%s%s%s%s|(.*))$",
username_rx, repo_rx, subdir_rx, ref_or_pull_rx)


param_names <- c("username", "repo", "subdir", "ref", "pull", "invalid")
replace <- setNames(sprintf("\\%d", seq_along(param_names)), param_names)
params <- lapply(replace, function(r) gsub(github_rx, r, path, perl = TRUE))
Expand All @@ -231,6 +294,20 @@ github_parse_path <- function(path) {
params
}

#' Retrieve Enterprise Github URL.
#'
#' Looks in env var \code{GITHUB_URL}.
#'
#' @keywords internal
#' @export
devtools_git_enterprise <- function() {
url <- Sys.getenv('GITHUB_URL')
if (identical(url, "")) return(NULL)

message("Using custom GitHub URL from envvar GITHUB_URL")
url
}

#' Retrieve Github personal access token.
#'
#' Looks in env var \code{GITHUB_PAT}.
Expand Down
12 changes: 12 additions & 0 deletions man/devtools_git_enterprise.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{devtools_git_enterprise}
\alias{devtools_git_enterprise}
\title{Retrieve Enterprise Github URL.}
\usage{
devtools_git_enterprise()
}
\description{
Looks in env var \code{GITHUB_URL}.
}
\keyword{internal}

1 change: 1 addition & 0 deletions man/install.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ not always completely possible, see \code{\link{reload}} for caveats.
set.

Other package installation: \code{\link{install_bitbucket}};
\code{\link{install_github_enterprise}};
\code{\link{install_github}};
\code{\link{install_gitorious}};
\code{\link{install_git}}; \code{\link{install_svn}};
Expand Down
3 changes: 2 additions & 1 deletion man/install_bitbucket.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ install_bitbucket(c("testrepo", "testrepo2"))
Bitbucket API docs:
\url{https://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs}

Other package installation: \code{\link{install_github}};
Other package installation: \code{\link{install_github_enterprise}};
\code{\link{install_github}};
\code{\link{install_gitorious}};
\code{\link{install_git}}; \code{\link{install_svn}};
\code{\link{install_url}}; \code{\link{install_version}};
Expand Down
1 change: 1 addition & 0 deletions man/install_git.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ install_git("git://github.com/hadley/stringr.git", branch = "stringr-0.2")
}
\seealso{
Other package installation: \code{\link{install_bitbucket}};
\code{\link{install_github_enterprise}};
\code{\link{install_github}};
\code{\link{install_gitorious}};
\code{\link{install_svn}}; \code{\link{install_url}};
Expand Down
6 changes: 5 additions & 1 deletion man/install_github.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\title{Attempts to install a package directly from github.}
\usage{
install_github(repo, username = NULL, ref = "master", subdir = NULL,
auth_token = github_pat(), ..., dependencies = TRUE)
auth_token = github_pat(), github_url = NULL, ..., dependencies = TRUE)
}
\arguments{
\item{repo}{Repository address in the format
Expand All @@ -27,6 +27,9 @@ supply to this argument. This is safer than using a password because
you can easily delete a PAT without affecting any others. Defaults to
the \code{GITHUB_PAT} environment variable.}

\item{github_url}{Defaults to NULL, so the default archive URL is served
from the GitHub API. You can set it to your custom Enterprise GitHub URL.}

\item{...}{Other arguments passed on to \code{\link{install}}.}

\item{dependencies}{By default, installs all dependencies so that you can
Expand Down Expand Up @@ -60,6 +63,7 @@ install_github("hadley/private", auth_token = "abc")
\code{\link{github_pull}}

Other package installation: \code{\link{install_bitbucket}};
\code{\link{install_github_enterprise}};
\code{\link{install_gitorious}};
\code{\link{install_git}}; \code{\link{install_svn}};
\code{\link{install_url}}; \code{\link{install_version}};
Expand Down
62 changes: 62 additions & 0 deletions man/install_github_enterprise.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{install_github_enterprise}
\alias{install_github_enterprise}
\title{Convenience wrapper for \code{\link{install_github}}.}
\usage{
install_github_enterprise(repo, username = NULL, ref = "master",
subdir = NULL, auth_token = github_pat(),
github_url = devtools_git_enterprise(), ..., dependencies = TRUE)
}
\arguments{
\item{repo}{Repository address in the format
\code{[username/]repo[/subdir][@ref|#pull]}. Alternatively, you can
specify \code{username}, \code{subdir}, \code{ref} or \code{pull} using the
respective parameters (see below); if both is specified, the values in
\code{repo} take precedence.}

\item{username}{User name. Deprecate: please include username in the
\code{repo}}

\item{ref}{Desired git reference. Could be a commit, tag, or branch
name, or a call to \code{\link{github_pull}}. Defaults to \code{"master"}.}

\item{subdir}{subdirectory within repo that contains the R package.}

\item{auth_token}{To install from a private repo, generate a personal
access token (PAT) in \url{https://github.com/settings/applications} and
supply to this argument. This is safer than using a password because
you can easily delete a PAT without affecting any others. Defaults to
the \code{GITHUB_PAT} environment variable.}

\item{github_url}{Defaults to NULL, so the default archive URL is served
from the GitHub API. You can set it to your custom Enterprise GitHub URL.}

\item{...}{Other arguments passed on to \code{\link{install}}.}

\item{dependencies}{By default, installs all dependencies so that you can
build vignettes and use all functionality of the package.}
}
\description{
This function allows you to install a package built
with \code{devtools} from a repo with a custom URL.
}
\examples{
\dontrun{
# To install from a private repo, use auth_token as described
# at ?install_github and either set the github_url parameter
# or let the ?devtools_git_enterprise helper retrieve it from
# the GITHUB_URL environment variable if it is set.
# Best practice is the latter.
install_github_enterprise("username/packagename", github_url = "https://github.scm.xyz.com")

}
}
\seealso{
Other package installation: \code{\link{install_bitbucket}};
\code{\link{install_github}};
\code{\link{install_gitorious}};
\code{\link{install_git}}; \code{\link{install_svn}};
\code{\link{install_url}}; \code{\link{install_version}};
\code{\link{install}}
}

1 change: 1 addition & 0 deletions man/install_gitorious.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ install_gitorious("r-mpc-package")
}
\seealso{
Other package installation: \code{\link{install_bitbucket}};
\code{\link{install_github_enterprise}};
\code{\link{install_github}}; \code{\link{install_git}};
\code{\link{install_svn}}; \code{\link{install_url}};
\code{\link{install_version}}; \code{\link{install}}
Expand Down
1 change: 1 addition & 0 deletions man/install_svn.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ install_svn(c("https://github.com/hadley/devtools", "https://github.com/hadley/s
}
\seealso{
Other package installation: \code{\link{install_bitbucket}};
\code{\link{install_github_enterprise}};
\code{\link{install_github}};
\code{\link{install_gitorious}};
\code{\link{install_git}}; \code{\link{install_url}};
Expand Down
1 change: 1 addition & 0 deletions man/install_url.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ a single command.
}
\seealso{
Other package installation: \code{\link{install_bitbucket}};
\code{\link{install_github_enterprise}};
\code{\link{install_github}};
\code{\link{install_gitorious}};
\code{\link{install_git}}; \code{\link{install_svn}};
Expand Down
24 changes: 13 additions & 11 deletions man/install_version.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@ archived source tarballs and tries to install an older version instead.}
\code{"http://cran.us.r-project.org"}. For more details on
supported URL schemes see \code{\link{url}}.

Can be \code{NULL} to install from local files
(with extension \file{.tar.gz} for source packages).
Can be \code{NULL} to install from local files, directories or URLs:
this will be inferred by extension from \code{pkgs} if of length one.
}

\item{type}{character, indicating the type of package to download and
install.

Possible values are (currently) \code{"source"}, \code{"mac.binary"}
and \code{"win.binary"}: the binary types can be listed and
downloaded but not installed on other platforms.
Possible values are (currently) \code{"source"},
\code{"mac.binary"}, \code{"mac.binary.mavericks"} and
\code{"win.binary"}: the binary types can be listed and downloaded
but not installed on other platforms.

The default is the appropriate binary type on Windows and on the
CRAN binary OS X distribution, otherwise \code{"source"}. For
the platforms where binary packages are the default, an alternative
is \code{"both"} which means \sQuote{try binary if available,
otherwise try source}. (This will only choose the binary package if
its version number is no older than the source version. In
interactive use it will ask before attempting to install source
CRAN binary OS X distributions, otherwise \code{"source"}. For the
platforms where binary packages are the default, an alternative is
\code{"both"} which means \sQuote{try binary if available and
current, otherwise try source}. (This will only choose the binary
package if its version number is no older than the source version.
In interactive use it will ask before attempting to install source
packages.)
}
}
Expand All @@ -53,6 +54,7 @@ Jeremy Stephens
}
\seealso{
Other package installation: \code{\link{install_bitbucket}};
\code{\link{install_github_enterprise}};
\code{\link{install_github}};
\code{\link{install_gitorious}};
\code{\link{install_git}}; \code{\link{install_svn}};
Expand Down