-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathREADME.Rmd
189 lines (132 loc) · 6.71 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
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
)
```
# {gitlabr} <img src="man/figures/logo.png" align="right" alt="" width="120" />
<!-- badges: start -->
[](https://cran.r-project.org/package=gitlabr)

[](https://app.codecov.io/gh/ThinkR-open/gitlabr)
[](https://github.com/ThinkR-open/gitlabr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
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.
## Installation
You can install the most recent stable version from CRAN using:
```{r, eval=FALSE}
install.packages("gitlabr")
```
To install the development version using [devtools](https://cran.r-project.org/package=devtools), type:
```{r, eval=FALSE}
install.packages("gitlabr", repos = "https://thinkr-open.r-universe.dev")
```
See the [CONTRIBUTING.md](https://github.com/ThinkR-open/gitlabr/blob/main/CONTRIBUTING.md) for instructions on how to run tests locally and contributor information.
## Recommended GitLab versions
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.
## Quick Start Example
R code using {gitlabr} to perform some common GitLab actions can look like this
- Create a TOKEN on your GitLab instance with scopes: `api`
+ For instance on gitlab.com: `https://gitlab.com/-/profile/personal_access_tokens`
- Store your token in .Renviron as `GITLAB_COM_TOKEN` with `usethis::edit_r_environ()` and restart your session
- Set a connection to GitLab instance
```{r, cache=FALSE}
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")
)
```
- Find the list of projects available to you
+ Define a limit of pages of projects to search in with `max_page`, otherwise the entire GitLab.com will be downloaded here...
+ Find all parameters available in the API for projects on this page: https://docs.gitlab.com/ee/api/projects.html
+ For instance, we can set `owned = FALSE` to retrieve all projects except ours.
```{r}
# a tibble is returned, as is always by {gitlabr} functions
gl_list_projects(max_page = 2, owned = FALSE)
```
### Work with a specific project
- Explore one of your projects. You can set the name of the project or its ID. The ID is highly recommended, in particular if your project does not appear in the first pages of projects above.
+ Let's explore [project "repo.rtask"](https://gitlab.com/statnmap/repo.rtask), with `ID = 20384533` on GitLab.com
```{r}
my_project <- 20384533 # repo.rtask",
```
- If the default branch is not named `main`, you need to specify it with `gitlabr_options_set()`
```{r}
gitlabr_options_set("gitlabr.main", "master")
```
- List files of the project using `gl_list_files()`
```{r}
gl_list_files(project = my_project)
```
- List issues with `gl_list_issues()`
```{r}
gl_list_issues(project = my_project)
```
- Create an issue
```{r, eval=FALSE}
# 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._
### Use additional requests
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>:
- The verb is `POST`
- The request is `projects`
- Required attributes are `name` or `path` (if `name` not set)
- `default_branch` is an attribute that can be set if wanted, but not required
The corresponding use of `gitlab()` is:
```{r, eval=FALSE}
gitlab(
req = "projects",
verb = httr::POST,
name = "toto",
default_branch = "main"
)
```
Implement whatever suits your needs !
### Unset connection
```{r}
unset_gitlab_connection()
```
## Using GitLab CI with {gitlabr}
{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:
```{r echo=FALSE, results='asis'}
cat(paste("-", list.files("inst/gitlab-ci/"), collapse = "\n\n"))
```
## Further information
- For an introduction see the `vignette("a-gitlabr", package = "gitlabr")`
- When writing custom extensions ("convenience functions") for {gitlabr} or when you experience any trouble, the very extensive [GitLab API documentation](https://docs.gitlab.com/ce/api/) can be helpful.
# Contributing to {gitlabr}
You're welcome to contribute to {gitlabr} by editing the source code, adding more convenience functions, filing issues, etc. [CONTRIBUTING.md](https://github.com/ThinkR-open/gitlabr/blob/main/CONTRIBUTING.md) compiles some information helpful in that process.
## Code of Conduct
Please note that the gitlabr project is released with a [Contributor Code of Conduct](https://thinkr-open.github.io/gitlabr/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
_Note that the {gitlabr} package was originally created by [Jirka Lewandowski](https://github.com/jirkalewandowski/gitlabr). The present repository is a fork to be able to continue development of this package._