Skip to contents

Tests whether or not a file exists in a GitLab repository.

Usage

file_exists(
  path,
  id_project = funky::config_val("id_project"),
  ref = "HEAD",
  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 logical scalar.

Details

file_exists() makes a light-weight HTTP HEAD request only and properly handles HTTP 404 Not Found errors.

See also

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

Examples

gitlab::file_exists(path = "README.md",
                    id_project = 64767928)
#> [1] TRUE

gitlab::file_exists(path = "test.md",
                    id_project = 64767928)
#> [1] FALSE