knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
To run the code in this vignette you'll need to have a GitLab account and you need to generate a personal access token (PAT). See the GitLab documentation on how to generate PATs. In the Scopes section you only need to tick the api box.
https://gitlab.com/-/profile/personal_access_tokens
api
scope) GITLAB_COM_TOKEN
R code using 'gitlabr' to perform some easy, common GitLab actions can look like this:
library(gitlabr) # Store your token in .Renviron and restart your session usethis::edit_r_environ() # Add: GITLAB_COM_TOKEN=YourTokenHere # You can verify it worked Sys.getenv("GITLAB_COM_TOKEN") # connect as a fixed user to a GitLab instance set_gitlab_connection( gitlab_url = "https://gitlab.com/", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) gl_list_groups(page = 1) # Returns all groups you have access to gl_list_projects(page = 1) # Returns all projects on GitLab, so we limit to just the first page of results. # It's unlikely that you'll want to use 'gitlabr' to interact with all the projects on GitLab, so a better approach is to define the project you want to work on. This is done by finding the the project ID on GitLab.com (it is listed right below the project name on the repo front page). # Here we use the [project "repo.rtask"](https://gitlab.com/statnmap/repo.rtask) my_project <- 20384533 gl_list_files(project = my_project) # create a new issue new_feature_issue <- gl_create_issue( title = "Implement new feature", project = my_project ) # statnmap user ID my_id <- 4809823 # assign issue to me gl_assign_issue( assignee_id = example_user$id, issue_id = new_feature_issue$iid, project = my_project ) # List opened issues gl_list_issues( state = "opened", project = my_project ) # close the issue gl_close_issue( issue_id = new_feature_issue$iid, project = my_project )$state
tibble
to integrate seamless into dplyr's data manipulation mindset (often called the "tidyverse")page
and per_page
if necessary.This is the recommended way of using 'gitlabr'.
In order to avoid the repeated specification of gitlab_con()
in the parameter style, you can also set a global variable managed by 'gitlabr' to use a specific connection function for every call:
set_gitlab_connection(my_gitlab) gl_create_issue(project = my_project, "Implement new feature")
gl_create_issue()
is an example function here, the principle works for all convenience functions of 'gitlabr' starting with gl_*()
Note that the set style is not purely functional, since set_gitlab_connection()
changes a saved global variable affecting the results of all future gitlab()
calls.
You can reset this variable to the default value using unset_gitlab_connection()
.
All convenience wrappers accept a parameter gitlab_con()
specifying the function to use for the actual API call.
Hence, you can pass a GitLab connection (as returned by gl_connection()
) with the R function call:
my_gitlab <- gl_connection( gitlab_url = "https://about.gitlab.com/", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) gl_create_issue("Implement new feature", project = my_project, gitlab_con = my_gitlab)
Again, gl_create_issue()
is an example function here, the principle style works for all convenience functions of 'gitlabr' listed in the "Convenience function list" below or user-defined functions as described in the section "Writing custom GitLab request functions".
'gitlabr' can also be used to create a .gitlab-ci.yml
file to test, build and check an R package using GitLab's CI software. See the use_gitlab_ci()
and related functions for documentation.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.