githubr icon indicating copy to clipboard operation
githubr copied to clipboard

Add support for submodules

Open brian-bot opened this issue 5 years ago • 2 comments

Currently, the client breaks if a repository has a reference to a submodule (as discovered by @jgockley62). More information to be added here once available.

brian-bot avatar Sep 01 '20 21:09 brian-bot

Currently using the /repos/{owner}/{repo}/git/trees/{tree_sha} API - might need to switch to /repos/{owner}/{repo}/contents/{path} or some combination of the two.

Additionally, the mechanism by which the client constructs permanent links for HTML and raw references is a bit clunky and might be able to be fixed by this switch as well.

brian-bot avatar Sep 01 '20 21:09 brian-bot

So I was playing around with the code a bit here: https://github.com/brian-bot/githubr/blob/9e392bb9f0eaf29355fbfc679856b258f7e9630d/R/getCommitTree.R#L11

I found a way to insert A link.... it's not functional and doesn't wouldn't work to pull info from a sub module but may prevent an error when pulling another piece of info.

# Are There Sub Modules
if( isTRUE('.gitmodules' %in% sapply(myRepo@apiResponses$tree$tree, function(x){x[["path"]]})) ){
  
  #Pull the git modules File
  SubMods <- system('git config -f .gitmodules -l', intern=TRUE)
  
  #Find the indexs of the submodules
  url = sapply(myRepo@apiResponses$tree$tree, function(x){x[["url"]]})
  ind <- c( which( 'NULL' == as.character(url) ) )
  
  #Find the pathnames of the submodules
  pathIDs = as.character(sapply(myRepo@apiResponses$tree$tree, function(x){x[["path"]]}))[ind]
  
  #Clean Subodule Object
  for( i in 1:length(SubMods) ){
    SubMods[i] <- unlist(stringr::str_split(SubMods[i], '[=]'))[2]
  } 
  
  #Buld a path-to-link object
  IND <- c(1:length(SubMods))
  Translate <- SubMods[ IND[which(IND %% 2 == 0)] ]
  names(Translate) <- SubMods[ IND[which(IND %% 2 != 0)] ]
  
  #Pull the repo data
  type  = sapply(myRepo@apiResponses$tree$tree, function(x){x[["type"]]})
  path = sapply(myRepo@apiResponses$tree$tree, function(x){x[["path"]]})
  sha  = sapply(myRepo@apiResponses$tree$tree, function(x){x[["sha"]]})
  url = sapply(myRepo@apiResponses$tree$tree, function(x){x[["url"]]})
  
  #Place URLs for sub modules in the url object
  for( i in 1:length( Translate ) ){
    url[ which( path == names(Translate[i]) ) ] <- as.character(Translate[i])
  }
  
  thisTree <- data.frame(type,
                         path,
                         sha,
                         url,
                         stringsAsFactors=FALSE
                        )
}else{
  thisTree <- data.frame(type  = sapply(myRepo@apiResponses$tree$tree, function(x){x[["type"]]}),
                         path = sapply(myRepo@apiResponses$tree$tree, function(x){x[["path"]]}),
                         sha  = sapply(myRepo@apiResponses$tree$tree, function(x){x[["sha"]]}),
                         url = sapply(myRepo@apiResponses$tree$tree, function(x){x[["url"]]}),
                         stringsAsFactors=FALSE)
}

jgockley62 avatar Sep 02 '20 00:09 jgockley62