Skip to content

Commit

Permalink
remove jsTree depedency
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Sidi committed Jul 21, 2018
1 parent 1747af1 commit 07136f6
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 437 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -34,3 +34,4 @@ vignettes/*.pdf
*.knit.md
.Rproj.user

*.DS_Store
4 changes: 2 additions & 2 deletions DESCRIPTION
Expand Up @@ -9,11 +9,11 @@ Description: Managing, inspecting and sourcing remote repositories such as githu
Depends:
R (>= 2.3.0)
Imports:
jsonlite,jsTree,miniUI,shiny,httr,utils,tools,plyr,crayon
httr,utils,crayon,tools,rstudioapi
License: GPL-2 | GPL-3
URL: https://github.com/metrumresearchgroup/vcs
BugReports: https://github.com/metrumresearchgroup/options/issues
LazyData: true
NeedsCompilation: no
Packaged: 2017-06-08 14:00:00 UTC; Yoni
RoxygenNote: 6.0.1.9000
RoxygenNote: 6.0.1
29 changes: 0 additions & 29 deletions NAMESPACE
Expand Up @@ -8,8 +8,6 @@ export(grepr)
export(gsubr)
export(list_repos)
export(ls_remote)
export(navigate_remote)
export(sasha)
export(setwd_remote)
export(source_remote)
export(sparse_checkout)
Expand All @@ -21,33 +19,6 @@ importFrom(httr,add_headers)
importFrom(httr,content)
importFrom(httr,http_error)
importFrom(httr,parse_url)
importFrom(jsTree,jsTree)
importFrom(jsTree,jsTreeOutput)
importFrom(jsTree,renderJsTree)
importFrom(jsonlite,fromJSON)
importFrom(miniUI,gadgetTitleBar)
importFrom(miniUI,miniContentPanel)
importFrom(miniUI,miniPage)
importFrom(miniUI,miniTitleBarButton)
importFrom(shiny,actionButton)
importFrom(shiny,conditionalPanel)
importFrom(shiny,eventReactive)
importFrom(shiny,isolate)
importFrom(shiny,observeEvent)
importFrom(shiny,paneViewer)
importFrom(shiny,radioButtons)
importFrom(shiny,reactiveValues)
importFrom(shiny,renderPrint)
importFrom(shiny,renderUI)
importFrom(shiny,runGadget)
importFrom(shiny,selectInput)
importFrom(shiny,sidebarLayout)
importFrom(shiny,sidebarPanel)
importFrom(shiny,stopApp)
importFrom(shiny,textInput)
importFrom(shiny,uiOutput)
importFrom(shiny,verbatimTextOutput)
importFrom(shiny,wellPanel)
importFrom(tools,file_path_as_absolute)
importFrom(utils,head)
importFrom(utils,tail)
45 changes: 20 additions & 25 deletions R/grep_remote.R
Expand Up @@ -3,10 +3,12 @@
#' @param pattern character, string containing a regular expression
#' @param path character, path to search, see details
#' @param recursive boolean, Should the listing recurse into directories? passed to list.files, Default: FALSE
#' @param whole_word boolean, if TRUE then the pattern will be wrapped with \\bpattern\\b internally, Default: FALSE
#' @param ... arguments passed to grep
#' @param whole_word boolean, if TRUE then the pattern will be
#' wrapped with \\bpattern\\b internally, Default: FALSE
#' @param padding integer, number of rows to return in addition to the query line, Default: 5
#' @param use_crayon boolean, use crayon colors in console output, Default: TRUE
#' @param ... arguments passed to grep
#' @param marker boolean, use rstudioapi marker, Default: interactive()
#' @return grepr(value = FALSE) returns a vector of the indices of the elements of x
#' that yielded a match (or not, for invert = TRUE.
#' This will be an integer vector unless the input is a long vector, when it will be a double vector.
Expand All @@ -26,14 +28,21 @@
#' grepr(pattern = 'importFrom',path = remotepath,value=TRUE)
#' grepr(pattern = 'importFrom',path = remotepath,value=TRUE,padding=3)
#' grepr(pattern = 'tags$script',
#' path = list(path = 'timelyportfolio/vueR',subdir='R|inst',vcs='github'),
#' path = list(path = 'timelyportfolio/vueR',subdir='R|inst',vcs='github',PAT = Sys.getenv('GITHUB_PAT')),
#' padding=3,value=TRUE,fixed=TRUE)}
#' @export
#' @importFrom httr content GET parse_url
#' @importFrom utils tail head
#' @importFrom crayon green red
#' @importFrom jsTree jsTree
grepr <- function(pattern,path,recursive=FALSE, whole_word = FALSE, padding=0,use_crayon = TRUE, interactive=FALSE,marker = FALSE, ...){
grepr <- function(pattern,
path,
recursive=FALSE,
... ,
whole_word = FALSE,
padding=1,
use_crayon = TRUE,
marker = interactive()
){

if(marker)
use_crayon <- FALSE
Expand Down Expand Up @@ -69,7 +78,9 @@ grepr <- function(pattern,path,recursive=FALSE, whole_word = FALSE, padding=0,us
out=sapply(fl,function(x){
args=grepVars
args$pattern=pattern
if(is.null(args$value)||interactive) args$value=FALSE
if(is.null(args$value)){
args$value <- FALSE
}

args$x=switch(vcs,
local= {readLines(x,warn = FALSE)},
Expand All @@ -79,7 +90,7 @@ grepr <- function(pattern,path,recursive=FALSE, whole_word = FALSE, padding=0,us
s <- httr::content(
httr::GET(x,
httr::add_headers(
Authorization = sprintf('token %s',Sys.getenv('GHE_PAT'))
Authorization = sprintf('token %s',path$PAT)
)
)
)
Expand Down Expand Up @@ -122,7 +133,7 @@ grepr <- function(pattern,path,recursive=FALSE, whole_word = FALSE, padding=0,us
}
gdx=sapply(g,function(x,pad,nmax) seq(from=pmax(1,x-pad),to=pmin(nmax,x+pad)),pad=padding,nmax=length(args$x))
out=unique(unlist(sapply(gdx,function(i){
if(use_crayon&!interactive){
if(use_crayon){
ifelse(i%in%g0,{

this_pat <- regexpr(pattern, args$x[i])
Expand All @@ -146,22 +157,6 @@ grepr <- function(pattern,path,recursive=FALSE, whole_word = FALSE, padding=0,us
}
})

if(interactive & vcs%in%c('ghe','github','bitbucket') ){

s0 <- out[sapply(out,length)>0]

NAMES <- gsub(sprintf('^(.*?)%s/|\\?(.*?)$',path$branch),'',names(s0))

tree <- jsTree::jsTree$new(ls_remote(path$path,vcs=vcs))

tree$current_nodestate <- tree$data%in%NAMES
tree$add_vcs(remote_repo = path$path,vcs = vcs,remote_branch = 'master')
tree$raw_token <- ghe_raw_token(path = path$path,file = tree$data[1],myPAT = Sys.getenv('GHE_PAT'))
tree$preview_search <- pattern

tree$show()

}else{
out <- out[sapply(out,length)>0]

if(!marker){
Expand All @@ -173,7 +168,7 @@ grepr <- function(pattern,path,recursive=FALSE, whole_word = FALSE, padding=0,us
}

invisible(out)
}


}

Expand Down
31 changes: 18 additions & 13 deletions R/ls_remote.R
Expand Up @@ -21,18 +21,25 @@
#' #'master' branch
#' ls_remote('metrumrg/qapply',vcs='bitbucket')
#'
ls_remote <- function(path=getwd(),branch='master',subdir=NULL,vcs='github', full.names=FALSE){
ls_remote <- function(
path=getwd(),
branch='master',
subdir=NULL,
vcs='github',
full.names=FALSE,
PAT = Sys.getenv('GITHUB_PAT')
){

this_wd <- getwd()

switch(vcs,
ghe={

myPAT <- Sys.getenv('GHE_PAT')


get_git <- sprintf('https://ghe.metrumrg.com/api/v3/repos/%s/git/trees/%s?recursive=1',path,branch)

x <- httr::GET(get_git,
httr::add_headers(
Authorization = sprintf('token %s',myPAT)
Authorization = sprintf('token %s',PAT)
)
)

Expand Down Expand Up @@ -62,15 +69,13 @@ ls_remote <- function(path=getwd(),branch='master',subdir=NULL,vcs='github', ful

},
github={

myPAT <- Sys.getenv('GITHUB_PAT')


uri_git <- sprintf('https://api.github.com/repos/%s',path)
get_git <- sprintf('https://api.github.com/repos/%s/git/trees/%s%s',path,branch,'?recursive=1')

if(nzchar(myPAT)){
uri_git <- sprintf('%s?access_token=%s',uri_git,Sys.getenv('GITHUB_PAT'))
get_git <- sprintf('%s&access_token=%s',get_git,Sys.getenv('GITHUB_PAT'))
if(nzchar(PAT)){
uri_git <- sprintf('%s?access_token=%s',uri_git,PAT)
get_git <- sprintf('%s&access_token=%s',get_git,PAT)
}

chk_git <- httr::http_error(uri_git)
Expand All @@ -92,8 +97,8 @@ ls_remote <- function(path=getwd(),branch='master',subdir=NULL,vcs='github', ful

raw_git <- sprintf('https://raw.githubusercontent.com/%s/%s/%s',path,branch,s)

if(nzchar(myPAT)){
dlPAT <- gsub('^(.*?)\\?','',httr::content(httr::GET(sprintf('https://api.github.com/repos/%s/contents/%s?access_token=%s',path,s[1],myPAT)))$download_url)
if(nzchar(PAT)){
dlPAT <- gsub('^(.*?)\\?','',httr::content(httr::GET(sprintf('https://api.github.com/repos/%s/contents/%s?access_token=%s',path,s[1],PAT)))$download_url)
if(!dlPAT%in%raw_git)
raw_git <- sprintf('%s?%s',raw_git,dlPAT)
}
Expand Down
3 changes: 2 additions & 1 deletion R/make_marker.R
Expand Up @@ -16,8 +16,9 @@ make_marker <- function(pattern,x){

lapply(x[[nx]],function(xx){
r <- as.numeric(gsub('\\D','',gsub(':(.*?)$','',xx)))
type <- ifelse(grepl('\\[',gsub(':(.*?)$','',xx)),'info','usage')
l <- gsub('^(.*?):','',xx)
list(type='info',file=new_nx,line=r,column=1,message=l)
list(type=type,file=new_nx,line=r,column=1,message=l)
})
}),recursive = FALSE),
basePath = getwd(),
Expand Down
30 changes: 0 additions & 30 deletions R/navigate_remote.R

This file was deleted.

0 comments on commit 07136f6

Please sign in to comment.