Skip to main content

contents

Creates, updates, deletes, gets or lists a contents resource.

Overview

Namecontents
TypeResource
Idgithub.repos.contents

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
namestring
_linksobject
contentstring
download_urlstring (uri)
encodingstring
git_urlstring (uri)
html_urlstring (uri)
pathstring
shastring
sizeinteger
submodule_git_urlstring (example: "git://example.com/defunkt/dotjs.git")
targetstring (example: "actual/actual.md")
typestring (file)
urlstring (uri)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_readme_in_directoryselectowner, repo, dirrefGets the README from a repository directory.

This endpoint supports the following custom media types. For more information, see "Media types."

- application/vnd.github.raw+json: Returns the raw file contents. This is the default if you do not specify a media type.
- application/vnd.github.html+json: Returns the README in HTML. Markup languages are rendered to HTML using GitHub's open-source Markup library.
get_readmeselectowner, reporefGets the preferred README for a repository.

This endpoint supports the following custom media types. For more information, see "Media types."

- application/vnd.github.raw+json: Returns the raw file contents. This is the default if you do not specify a media type.
- application/vnd.github.html+json: Returns the README in HTML. Markup languages are rendered to HTML using GitHub's open-source Markup library.
create_or_update_file_contentsinsertowner, repo, path, message, contentCreates a new file or replaces an existing file in a repository.

> [!NOTE]
> If you use this endpoint and the "Delete a file" endpoint in parallel, the concurrent requests will conflict and you will receive errors. You must use these endpoints serially instead.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint. The workflow scope is also required in order to modify files in the .github/workflows directory.
delete_filedeleteowner, repo, pathDeletes a file in a repository.

You can provide an additional committer parameter, which is an object containing information about the committer. Or, you can provide an author parameter, which is an object containing information about the author.

The author section is optional and is filled in with the committer information if omitted. If the committer information is omitted, the authenticated user's information is used.

You must provide values for both name and email, whether you choose to use author or committer. Otherwise, you'll receive a 422 status code.

> [!NOTE]
> If you use this endpoint and the "Create or update file contents" endpoint in parallel, the concurrent requests will conflict and you will receive errors. You must use these endpoints serially instead.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
dirstringThe alternate path to look for a README file
ownerstringThe account owner of the repository. The name is not case sensitive.
pathstringpath parameter
repostringThe name of the repository without the .git extension. The name is not case sensitive.
refstringThe name of the commit/branch/tag. Default: the repository’s default branch.

SELECT examples

Gets the README from a repository directory.

This endpoint supports the following custom media types. For more information, see "Media types."

- application/vnd.github.raw+json: Returns the raw file contents. This is the default if you do not specify a media type.
- application/vnd.github.html+json: Returns the README in HTML. Markup languages are rendered to HTML using GitHub's open-source Markup library.

SELECT
name,
_links,
content,
download_url,
encoding,
git_url,
html_url,
path,
sha,
size,
submodule_git_url,
target,
type,
url
FROM github.repos.contents
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND dir = '{{ dir }}' -- required
AND ref = '{{ ref }}'
;

INSERT examples

Creates a new file or replaces an existing file in a repository.

> [!NOTE]
> If you use this endpoint and the "Delete a file" endpoint in parallel, the concurrent requests will conflict and you will receive errors. You must use these endpoints serially instead.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint. The workflow scope is also required in order to modify files in the .github/workflows directory.

INSERT INTO github.repos.contents (
message,
content,
sha,
branch,
committer,
author,
owner,
repo,
path
)
SELECT
'{{ message }}' /* required */,
'{{ content }}' /* required */,
'{{ sha }}',
'{{ branch }}',
'{{ committer }}',
'{{ author }}',
'{{ owner }}',
'{{ repo }}',
'{{ path }}'
RETURNING
commit,
content
;

DELETE examples

Deletes a file in a repository.

You can provide an additional committer parameter, which is an object containing information about the committer. Or, you can provide an author parameter, which is an object containing information about the author.

The author section is optional and is filled in with the committer information if omitted. If the committer information is omitted, the authenticated user's information is used.

You must provide values for both name and email, whether you choose to use author or committer. Otherwise, you'll receive a 422 status code.

> [!NOTE]
> If you use this endpoint and the "Create or update file contents" endpoint in parallel, the concurrent requests will conflict and you will receive errors. You must use these endpoints serially instead.

DELETE FROM github.repos.contents
WHERE owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND path = '{{ path }}' --required
;