R/global_env.R

Defines functions unset_gitlab_connection get_gitlab_connection set_gitlab_connection

Documented in set_gitlab_connection unset_gitlab_connection

gitlabr_env <- new.env()
GITLAB_CON <- "gitlab_con"

## set to NULL in the beginning
assign(GITLAB_CON, NULL, gitlabr_env)

#' Get/set a gitlab connection for all calls
#' 
#' This sets the default value of \code{gitlab_con} 
#' in a call to \code{\link{gitlab}}
#' 
#' @param gitlab_con A function used for gitlab API calls, such
#' as \code{\link{gitlab}} or as returned by \code{\link{gl_connection}}.
#' @param ... if gitlab_con is NULL, a new connection is created used the parameters
#' is ... using \code{\link{gl_connection}}
#' 
#' @export
#' 
#' @examples \dontrun{
#' set_gitlab_connection("http://gitlab.example.com", private_token = "123####89")
#' }
set_gitlab_connection <- function(gitlab_con = NULL, ...) {
  stopifnot(is.null(gitlab_con) || is.function(gitlab_con))
  if (is.null(gitlab_con) && length(list(...)) > 0) {
    gitlab_con <- gl_connection(...)
  }
  assign(GITLAB_CON, gitlab_con, gitlabr_env)
}

get_gitlab_connection <- function() {
  get(GITLAB_CON, envir = gitlabr_env)
}

#' @rdname set_gitlab_connection
#' @export
unset_gitlab_connection <- function() {
  set_gitlab_connection(NULL)
}
statnmap/gitlab2r documentation built on Aug. 8, 2020, 12:07 a.m.