Skip to contents

Downloads a file from a GitLab repository via the GET /projects/{id_project}/repository/files/{path}/raw endpoint of GitLab's v4 RESTful API and returns its content.

Usage

file_content(
  path,
  id_project = funky::config_val("id_project"),
  ref = NULL,
  base_url = funky::config_val("base_url"),
  token = funky::config_val("token"),
  max_tries = 3L
)

Arguments

path

character(1)
File path, relative to the repository root.

id_project

integer(1)
GitLab project identifier.

ref

character(1)
Git revision expression matching the desired Git tree object, e.g. a ref name (branch, tag, etc.), a commit identifier, or another symbolic reference like "HEAD~10". Omitted if NULL, otherwise set as a URL parameter in the API request. Note that the GitLab API doesn't support every type of revision expression.

base_url

character(1)
Base URL to the GitLab v4 RESTful API root.

token

character(1)
GitLab access token used for authentication. If NULL, the API request is made unauthenticated which results in HTTP 404 Not Found and other errors for non-public resources.

max_tries

integer(1)
Maximum number of request attempts in case of an HTTP error. An integerish scalar. Retries are performed using exponential backoff and jitter, see httr2::req_retry() for details.

Value

A character scalar if path refers to a text file, otherwise a raw vector.

See also

Other functions to manage files on GitLab: commit_files(), file_commit_action(), file_create(), file_delete(), file_exists(), file_full(), file_meta(), file_req(), file_update(), file_write(), files_delete()

Examples

gitlab::file_content(path = "DESCRIPTION",
                     id_project = 64767928,
                     ref = "9c2fe95c63fef013205fe5ff64dd30494579f3f2") |>
  cat()
#> Package: gitlab
#> Title: Use GitLab's v4 RESTful API
#> Version: 0.0.9000
#> Authors@R: 
#>     person("Salim", "Brüggemann", , "salim-b@pm.me", role = c("aut", "cre"),
#>            comment = c(ORCID = "0000-0002-5329-5987"))
#> Description: Allows to conveniently work with GitLab's v4 RESTful API from
#>     R. GitLab (https://gitlab.com) is an open-source DevOps software suite
#>     that i.a. includes a powerful Git forge.
#> License: AGPL (>= 3)
#> URL: https://gitlab.rpkg.dev, https://gitlab.com/rpkg.dev/gitlab
#> BugReports: https://gitlab.com/rpkg.dev/gitlab/issues
#> Depends: 
#>     R (>= 4.4)
#> Imports: 
#>     base64enc (>= 0.1.3),
#>     brio (>= 1.1.5),
#>     checkmate (>= 2.3.2),
#>     cli (>= 3.6.3),
#>     digest (>= 0.6.37),
#>     dplyr (>= 1.1.4),
#>     fs (>= 1.6.5),
#>     glue (>= 1.8.0),
#>     heck (>= 0.1.3),
#>     httr2 (>= 1.0.6),
#>     jsonlite (>= 1.8.9),
#>     magrittr (>= 2.0.3),
#>     pal (>= 0.0.9101),
#>     purrr (>= 1.0.2),
#>     rlang (>= 1.1.4),
#>     stringr (>= 1.5.1),
#>     tibble (>= 3.2.1)
#> Encoding: UTF-8
#> LazyData: true
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 7.3.2.9000