pkgload::load_all()

source("dev/testor_tools.R")

Create a bookdown project on Forge

You will need a environment variable named "FORGE_THINKR_TOKEN" with your token.

GitLab connection

gitlab_forge_url <- "https://forge.thinkr.fr"

set_gitlab_connection(
  gitlab_url = gitlab_forge_url,
  private_token = Sys.getenv("FORGE_THINKR_TOKEN")
)

Create a new empty project if it does not exist

project_name <- "example-bookdown"

project_url <- gl_list_group_projects(27) %>% # thinkrverse
  filter(name == project_name) %>% 
  pull(path_with_namespace)

if (length(project_url) != 0) {

  message("The project already exists")

} else {

  project_info <- gl_new_project(
    name = project_name,
    default_branch = "main",
    namespace_id = 27, # thinkrverse
    initialize_with_readme = TRUE
  )

  project_url <- project_info$path_with_namespace

}

Clone locally

## Create tmp dir
tmpdir <- tempfile(pattern = "book-")
dir.create(tmpdir)
project_path <- file.path(tmpdir, project_name)

## Clone in tmp dir
clone_locally(
  project_name = project_url, 
  group_url = gitlab_forge_url, 
  project_path = project_path,
  open = FALSE
)

Create the bookdown skeleton

## Create bookdown
bookdown::create_bs4_book(
  path = project_path
)

## Try to render bookdown
bookdown::render_book(
  input = project_path
)

Push to the repo

push_to_repo(
  project_path, 
  message = 'Init bookdown repo'
)

Delete the project

project_id <- gl_get_project_id(
  project_name = project_name
)

gitlab(req = paste0("projects/", project_id),
       verb = httr::DELETE)

## Clean the tmpdir
unlink(project_path, recursive = TRUE)

Create a bookdown project on GitLab

You will need a environment variable named "GITLAB_COM_TOKEN" with your token.

GitLab connection

gitlab_url <- "https://gitlab.com"

## Set connection
set_gitlab_connection(
  gitlab_url = gitlab_url,
  private_token = Sys.getenv("GITLAB_COM_TOKEN")
)

Create a new empty project

project_name <- "example-bookdown"

project_url <- gl_list_group_projects(15567755) %>% # thinkr-open
  filter(name == project_name) %>% 
  pull(path_with_namespace)

if (length(project_url) != 0) {

  message("The project already exists")

} else {

  project_info <- gl_new_project(
    name = project_name,
    default_branch = "main",
    namespace_id = 15567755, # thinkr-open
    initialize_with_readme = TRUE
  )

  project_url <- project_info$path_with_namespace

}

Clone locally

## Create tmp dir
tmpdir <- tempfile(pattern = "book-")
dir.create(tmpdir)
project_path <- file.path(tmpdir, project_name)

## Clone in tmp dir
clone_locally(
  project_name = project_info$path, 
  group_url = "https://gitlab.com/thinkr-open", 
  project_path = project_path,
  open = FALSE
)

Create th bookdown skeleton

## Create bookdown
bookdown::create_bs4_book(
  path = project_path
)

## Try to render bookdown
bookdown::render_book(
  input = project_path
)

Push to the repo

push_to_repo(
  project_path, 
  message = 'Init bookdown repo'
)

Delete the project if needed

project_id <- gl_get_project_id(
  project_name = project_name
)

gitlab(req = paste0("projects/", project_id),
       verb = httr::DELETE)

## Clean the tmpdir
unlink(project_path, recursive = TRUE)


statnmap/gitlabr documentation built on May 19, 2024, 12:22 p.m.