GitLab API

GitlabTool

Actions1095

Projects → getApiV4ProjectsIdRepositoryFilesFilePath

AI-generated

Summary

Retrieve the content and metadata of a file in a GitLab project's repository by specifying the project ID, the URL-encoded file path, and the branch, tag, or commit reference.

Inputs

  • id (required) — The project ID or project path (e.g., 'gitlab-org/gitlab').
  • file_path (required) — The URL-encoded path to the file within the repository (e.g., 'lib%2Fclass%2Erb').
  • ref (required) — The name of the branch, tag, or commit to retrieve the file from (e.g., 'main').
  • method — The HTTP method to use, defaulting to GET; typically GET for retrieving file contents.
  • baseUrl — The base URL of the GitLab instance, defaulting to 'https://gitlab.com'.
  • skipAuthentication — Optional flag to skip authentication; defaults to false.

Output shape

a single JSON object representing the file's information and content from the repository

The response contains file metadata and content as returned by GitLab's API at endpoint /api/v4/projects/{id}/repository/files/{file_path}?ref={ref}. Authentication is required unless 'skipAuthentication' is set to true. The output format depends on GitLab's standard file endpoint response.

Examples

Example 1: Retrieve the README file from the main branch of a public project

Set 'id' to project path 'gitlab-org/gitlab', 'file_path' to 'README.md' (URL-encoded as needed), 'ref' to 'main', with default method GET and baseUrl 'https://gitlab.com'.

Links

Discussion