knitr::opts_chunk$set( cache = TRUE, collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", eval = Sys.getenv("GITLAB_COM_TOKEN", unset = FALSE) # do not eval if token is not available )
Never dreamt of creating and managing your GitLab projects from R?
{gitlabr} is here to help you with that!
With {gitlabr}, you can interact with GitLab's API to manage your projects, issues, merge requests, pipelines, wikis, and more.
Now, the automation of your regular tasks with GitLab is just a few lines of R code away.
You can install the most recent stable version from CRAN using:
install.packages("gitlabr")
To install the development version using devtools, type:
install.packages("gitlabr", repos = "https://thinkr-open.r-universe.dev")
See the CONTRIBUTING.md for instructions on how to run tests locally and contributor information.
GitLab 11.6 or higher is generally recommended when using {gitlabr} version 2.0.0 or higher. This {gitlabr} version uses the GitLab API v4.
R code using {gitlabr} to perform some common GitLab actions can look like this
api
https://gitlab.com/-/profile/personal_access_tokens
GITLAB_COM_TOKEN
with usethis::edit_r_environ()
and restart your session library(gitlabr) # You can verify your token works # Sys.getenv("GITLAB_COM_TOKEN") # connect as a fixed user to a GitLab instance for the session set_gitlab_connection( gitlab_url = "https://gitlab.com", private_token = Sys.getenv("GITLAB_COM_TOKEN") )
max_page
, otherwise the entire GitLab.com will be downloaded here...owned = FALSE
to retrieve all projects except ours.# a tibble is returned, as is always by {gitlabr} functions gl_list_projects(max_page = 2, owned = FALSE)
ID = 20384533
on GitLab.commy_project <- 20384533 # repo.rtask",
main
, you need to specify it with gitlabr_options_set()
gitlabr_options_set("gitlabr.main", "master")
gl_list_files()
gl_list_files(project = my_project)
gl_list_issues()
gl_list_issues(project = my_project)
# create a new issue new_feature_issue <- gl_create_issue(project = my_project, title = "Implement new feature") # Your user ID my_id <- 0000000 # assign issue to me gl_assign_issue( project = my_project, issue_id = new_feature_issue$iid, assignee_id = my_id ) # Verify new issue is here gl_list_issues(project = my_project, state = "opened") # close issue gl_close_issue(project = my_project, issue_id = new_feature_issue$iid)$state
Note that recent version of GitLab may have anti-spam on opening issues, leading to ERROR with gl_create_issue()
if you abuse the API. You will need to open the issue manually in this case.
If an API request is not already available in {gitlabr}, function gitlab()
allows to use any request of the GitLab API https://docs.gitlab.com/ce/api/.
For instance, the API documentation shows how to create a new project in https://docs.gitlab.com/ce/api/projects.html#create-project:
POST
projects
name
or path
(if name
not set)default_branch
is an attribute that can be set if wanted, but not requiredThe corresponding use of gitlab()
is:
gitlab( req = "projects", verb = httr::POST, name = "toto", default_branch = "main" )
Implement whatever suits your needs !
unset_gitlab_connection()
{gitlabr} can also be used to create a .gitlab-ci.yml
file to test, build and check an R package, a bookdown, ... using GitLab's CI software. Use gitlabr::use_gitlab_ci()
with a specific type
in your project and your CI should be ready to start in the next commit.
There are pre-defined templates:
cat(paste("-", list.files("inst/gitlab-ci/"), collapse = "\n\n"))
vignette("a-gitlabr", package = "gitlabr")
You're welcome to contribute to {gitlabr} by editing the source code, adding more convenience functions, filing issues, etc. CONTRIBUTING.md compiles some information helpful in that process.
Please note that the gitlabr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Note that the {gitlabr} package was originally created by Jirka Lewandowski. The present repository is a fork to be able to continue development of this package.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.