contents
Creates, updates, deletes, gets or lists a contents resource.
Overview
| Name | contents |
| Type | Resource |
| Id | github.repos.contents |
Fields
The following fields are returned by SELECT queries:
- get_readme_in_directory
- get_readme
Response
| Name | Datatype | Description |
|---|---|---|
name | string | |
_links | object | |
content | string | |
download_url | string (uri) | |
encoding | string | |
git_url | string (uri) | |
html_url | string (uri) | |
path | string | |
sha | string | |
size | integer | |
submodule_git_url | string | (example: "git://example.com/defunkt/dotjs.git") |
target | string | (example: "actual/actual.md") |
type | string | (file) |
url | string (uri) |
Response
| Name | Datatype | Description |
|---|---|---|
name | string | |
_links | object | |
content | string | |
download_url | string (uri) | |
encoding | string | |
git_url | string (uri) | |
html_url | string (uri) | |
path | string | |
sha | string | |
size | integer | |
submodule_git_url | string | (example: "git://example.com/defunkt/dotjs.git") |
target | string | (example: "actual/actual.md") |
type | string | (file) |
url | string (uri) |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
get_readme_in_directory | select | owner, repo, dir | ref | 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. |
get_readme | select | owner, repo | ref | Gets 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_contents | insert | owner, repo, path, message, content | 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. | |
delete_file | delete | owner, repo, path | 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. |
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.
| Name | Datatype | Description |
|---|---|---|
dir | string | The alternate path to look for a README file |
owner | string | The account owner of the repository. The name is not case sensitive. |
path | string | path parameter |
repo | string | The name of the repository without the .git extension. The name is not case sensitive. |
ref | string | The name of the commit/branch/tag. Default: the repository’s default branch. |
SELECT examples
- get_readme_in_directory
- get_readme
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 }}'
;
Gets 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.
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 ref = '{{ ref }}'
;
INSERT examples
- create_or_update_file_contents
- Manifest
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
;
# Description fields are for documentation purposes
- name: contents
props:
- name: owner
value: "{{ owner }}"
description: Required parameter for the contents resource.
- name: repo
value: "{{ repo }}"
description: Required parameter for the contents resource.
- name: path
value: "{{ path }}"
description: Required parameter for the contents resource.
- name: message
value: "{{ message }}"
description: |
The commit message.
- name: content
value: "{{ content }}"
description: |
The new file content, using Base64 encoding.
- name: sha
value: "{{ sha }}"
description: |
**Required if you are updating a file**. The blob SHA of the file being replaced.
- name: branch
value: "{{ branch }}"
description: |
The branch name. Default: the repository’s default branch.
- name: committer
description: |
The person that committed the file. Default: the authenticated user.
value:
name: "{{ name }}"
email: "{{ email }}"
date: "{{ date }}"
- name: author
description: |
The author of the file. Default: The `committer` or the authenticated user if you omit `committer`.
value:
name: "{{ name }}"
email: "{{ email }}"
date: "{{ date }}"
DELETE examples
- delete_file
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
;