Skip to content

Update API endpoints for raw files

As apparently raw blobs fetching via API is confusing, as endpoints should probably move to repository/files instead of raw_blobs.

As this breaks the API we probably should do this for 9.0?

/cc @rymai

Proposed change

  • Modify /projects/:id/repository/files to /projects/:id/repository/files/:filepath (:filepath should be URL-encoded)
  • Move /projects/:id/repository/blobs/:sha to /projects/:id/repository/files/:filepath/raw
  • Move /projects/:id/repository/raw_blobs/:sha to /projects/:id/repository/blobs/:sha/raw
  • (optionally) Add /projects/:id/repository/blobs/:sha that returns the blob as JSON

It should bring to more consistency compared to the snippets endpoint.

Get file from repository

Allows you to receive information about file in repository like name, size, content. Note that file content is Base64 encoded. This endpoint can be accessed without authentication if the repository is publicly accessible.

GET /projects/:id/repository/files/:filepath

Parameters:

  • id (required) - The ID of a project
  • filepath (required) - Full path to new file, URL-encoded. Ex. lib%2Fclass.rb
  • ref (required) - The name of branch, tag or commit

Example response:

{
  "file_name": "key.rb",
  "file_path": "app/models/key.rb",
  "size": 1476,
  "encoding": "base64",
  "content": "IyA9PSBTY2hlbWEgSW5mb3...",
  "ref": "master",
  "blob_id": "79f7bbd25901e8334750839545a9bd021f0e4c83",
  "commit_id": "d5a3ff139356ce33e37e73add446f16869741b50",
  "last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d"
}

Raw file content

Get the raw file contents for a file by commit SHA and path. This endpoint can be accessed without authentication if the repository is publicly accessible.

GET /projects/:id/repository/files/:filepath/raw

Parameters:

  • id (required) - The ID of a project
  • filepath (required) - Full path to new file, URL-encoded. Ex. lib%2Fclass.rb
  • ref (required) - The name of branch, tag or commit

Example response:

Raw blob content

Get the raw file contents for a blob by blob SHA. This endpoint can be accessed without authentication if the repository is publicly accessible.

GET /projects/:id/repository/blobs/:sha/raw

Parameters:

  • id (required) - The ID of a project
  • sha (required) - The blob SHA

(optional) Blob content

Get the file contents for a blob by blob SHA. This endpoint can be accessed without authentication if the repository is publicly accessible.

GET /projects/:id/repository/blobs/:sha

Parameters:

  • id (required) - The ID of a project
  • sha (required) - The blob SHA

Example response:

{
  "size": 1476,
  "encoding": "base64",
  "content": "IyA9PSBTY2hlbWEgSW5mb3...",
  "sha": "79f7bbd25901e8334750839545a9bd021f0e4c83"
}