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

Add function to copy files from another svn repo #66

Open
graceannobrien opened this issue Jan 11, 2024 · 0 comments
Open

Add function to copy files from another svn repo #66

graceannobrien opened this issue Jan 11, 2024 · 0 comments
Assignees

Comments

@graceannobrien
Copy link
Collaborator

Example yaml (from-old.yaml)

pk_da:
  from: old-repo/script/data-assembly/pk-da.Rmd
  to: script/data-assembly/pk-da.Rmd

Example code to loop through from-old.yaml:

user <- "username"

files_to_grab <- yaml::read_yaml(here::here("script", "from-old.yaml"))

for(file.i in names(files_to_grab)) {
  
  if(file.exists(files_to_grab[[file.i]]$to)){next}
  
  command.i <-
    glue::glue(
      "svn export svn+ssh://{user}@mc1.metrumrg.com/common/repo/{files_to_grab[[file.i]]$from} {files_to_grab[[file.i]]$to}"  
    )
  
  system(command.i)
}

Example QC helper:

qc_helper <- function(.file, .username){
  
  from_old <- yaml::read_yaml(here::here("script/from-old.yaml")) %>% bind_rows()
  
  .from <- from_old %>% filter(to == .file) %>% pull(from)
  
  if(length(.from) == 0){
    stop(.file, " not found in yaml under 'to'")
  }
  
  from_temp <- tempfile(fileext = paste0(".", tools::file_ext(.from)))
  
  try(suppressWarnings(file.remove(from_temp)))
  
  svn_command <-
    glue::glue("svn export svn+ssh://{.username}@mc1.metrumrg.com/common/repo/{.from} {from_temp}")
  
  try_command <- try(system(svn_command))
  
  if(inherits(try_command, "try-error")){
    stop("Command ", svn_command)
  }
  
  diffobj::diffFile(
    target = from_temp,
    current = .file, 
    color.mode = "rgb",
    mode = "sidebyside",
    tar.banner = paste0("Old - ", basename(.file)),
    cur.banner = paste0("New - ", basename(.file))
  )
  
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants