---
title: "Analysing GitLab"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Analysing GitLab}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(woodendesc)
```

GitLab is a site providing, among other services, code repositories with Git version control system. This allows for accessing a wide set of metadata.

## Packages

A user or a group may be (and in most cases is) an owner of several repositories. Not all repositories are R packages, thus the repository character is approximated by the presence of a `DESCRIPTION` file, one of very few required files for R packages, in the root folder.

```{r gitlab_packages, cache=TRUE}
wood_gitlab_packages("r-packages")
```

By default, forks of other repositories are not listed, but this setting can be changed using `include_forks` parameter:

```{r gitlab_forks, cache=TRUE}
wood_gitlab_packages("r-packages", include_forks = TRUE)
```

## Available tags

GitLab allows referencing to certain commits through specifying tags associated with them. To list all tags available for a given repository the user should use `wood_gitlab_tags()`. Note that some repositories may not have any tags defined, in which case an empty character vector would be returned.

```{r gitlab_tags, cache=TRUE}
wood_gitlab_tags("rock", "r-packages")
```

## Available package versions

Repository tags do not have to follow the specific guidelines of version codes. To extract package version codes associated with each GitLab tag the user should use `wood_gitlab_versions()`. This extracts the data from the `DESCRIPTION` file corresponding to each tagged commit.

```{r gitlab_versions, cache=TRUE}
wood_gitlab_versions("rock", "r-packages")
```

## Latest package version

To query the latest package version, i.e. the one that'd be installed by calling `remotes::install_gitlab()`, the user should use `wood_gitlab_latest()`. This function queries GitLab for the version code associated with the latest commit to the default branch of the specified repository. Note that this commit may be untagged, in which case the returned version code may not be among the ones listed by `wood_gitlab_versions()`.

```{r gitlab_latest, cache=TRUE}
wood_gitlab_latest("rock", "r-packages")
```

## Package dependencies

To list package dependencies the user should use `wood_gitlab_dependencies()`. This function extracts dependencies from the `DESCRIPTION` file. By default the latest commit is queried (the same behaviour can be obtained using `tag = "latest"` parameter) but it is possible to list dependencies for any tagged version.

```{r gitlab_deps, cache=TRUE}
wood_gitlab_dependencies("limonaid", "r-packages")
wood_gitlab_dependencies("rock", "r-packages", tag = "0.6.3")
```
