http.github
Classes & types
Functions
http.github.apiRequest | Makes a request to the Github API and parses the JSON response. |
http.github.compare | Compares two refs. |
http.github.createIssue | Creates an issue, requires a token. |
http.github.fetchBlob | Fetches the raw bytes of a blob, without the base64 overhead. |
http.github.fetchFile | Fetches the raw content of a file. |
http.github.fetchRaw | Downloads a response body as is (archives, raw files), anything but 200 is a failure. |
http.github.fetchReleaseAsset | Downloads a release asset. |
http.github.fetchTar | Fetches the repository contents as a gzipped TAR archive. |
http.github.fetchZip | Fetches the repository contents as a ZIP archive. |
http.github.getBlob | Fetches the content of a blob (a blob = file contents) in a repository, using its SHA-1. |
http.github.getBranch | Fetches a single branch of a repository. |
http.github.getBranches | Fetches the branches of a repository. |
http.github.getCommit | Fetches a single commit, a branch or tag name resolves to its latest commit. |
http.github.getCommits | Fetches the commits of a repository. |
http.github.getContents | Fetches the metadata of a file or the listing of a directory. |
http.github.getContributors | Fetches a list of repository contributors. |
http.github.getEmojis | Fetches a list of all github emojis. |
http.github.getGist | Fetches a gist. |
http.github.getIssues | Fetches the issues of a repository (pull requests are included by Github). |
http.github.getLanguages | Fetches a list of repository languages. |
http.github.getLatestRelease | Fetches the latest published release of a repository. |
http.github.getLicenses | Fetches a list of all github licenses. |
http.github.getPullRequests | Fetches the pull requests of a repository. |
http.github.getRateLimit | Fetches the current rate limit state of the token (does not count against the limit). |
http.github.getReadme | Fetches the readme of a repository, the content is decoded. |
http.github.getReleaseByTag | Fetches the release of a tag. |
http.github.getReleases | Fetches the releases of a repository. |
http.github.getRepositories | Fetches a list of all repositories owned by an organization. |
http.github.getRepository | Fetches a detailed information about a specific repository. |
http.github.getRepositoryTags | Fetches the tags (versions) of a repository. |
http.github.getTopics | Fetches the topics of a repository. |
http.github.getTree | Fetches a single Git tree — that is, a snapshot of the repository's file structure at a specific commit or tree. |
http.github.getUser | Fetches the user profile. |
http.github.getUserRepositories | Fetches a list of all public repositories owned by a user. |
http.github.paginate | Fetches every page of a list endpoint and joins them into one list. |
http.github.renderMarkdown | Renders Markdown to HTML. |
http.github.request | Sends a request to the Github API. |
http.github.searchCode | Searches code, requires a token. |
http.github.searchRepositories | Searches repositories. |
http.github.template | Replaces all occurrences of {name} in pathname with the percent-encoded replaces[name]. |
http.github.templateRequest | Replaces all placeholders in pathname (see template) and makes a request to the Github API. |
http.github.tryApiRequest | Same as apiRequest, but a 404 is not a failure: it returns true and nil. |
async function http.github.apiRequest(method: http.RequestMethod, pathname: string, headers?: table, body?: string, do_cache?: boolean, extra?: http.github.RequestOptions): boolean, table | string
Makes a request to the Github API and parses the JSON response.
Works like pcall: returns true and the data, or false and the error message. Empty responses (204) give an empty table.
Parameters
| Name | Type | Description |
|---|
method | http.RequestMethod | The request method. |
pathname | string | The path to send the request to. |
headersoptional | table | The headers to send with the request. |
bodyoptional | string | The body to send with the request. |
do_cacheoptional | boolean | Whether to cache the response. |
extraoptional | http.github.RequestOptions | The JSON body and query parameters. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | data | The data returned from the API, or the error message. |
async function http.github.compare(owner: string, repo: string, base: string, head: string): boolean, table | string
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
base | string | The base ref. |
head | string | The head ref. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | comparison | The comparison (status, ahead_by, behind_by, commits, files), or the error message if ok is false. |
async function http.github.createIssue(owner: string, repo: string, title: string, issue_body?: string, labels?: string[]): boolean, table | string
Creates an issue, requires a token.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
title | string | The issue title. |
issue_bodyoptional | string | The issue text. |
labelsoptional | string[] | The labels. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | issue | The created issue, or the error message if ok is false. |
async function http.github.fetchBlob(owner: string, repo: string, file_sha: string): boolean, string | string
Fetches the raw bytes of a blob, without the base64 overhead.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
file_sha | string | The SHA1 value of the blob. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
string | string | content | The blob content, or the error message if ok is false. |
async function http.github.fetchFile(owner: string, repo: string, path: string, ref?: string): boolean, string | string
Fetches the raw content of a file.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
path | string | The path of the file. |
refoptional | string | The branch, tag or commit, the default branch if omitted. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
string | string | content | The file content, or the error message if ok is false. |
async function http.github.fetchRaw(pathname: string, headers?: table): boolean, string
Downloads a response body as is (archives, raw files), anything but 200 is a failure.
Parameters
| Name | Type | Description |
|---|
pathname | string | |
headersoptional | table | |
Returns
| Type | Name | Description |
|---|
boolean | ok | |
string | body_or_message | |
#http.github.fetchReleaseAsset
async function http.github.fetchReleaseAsset(owner: string, repo: string, asset_id: integer): boolean, string | string
Downloads a release asset.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
asset_id | integer | The asset id (Release.assets[n].id). |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
string | string | content | The asset content, or the error message if ok is false. |
async function http.github.fetchTar(owner: string, repo: string, ref?: string): boolean, string | string
Fetches the repository contents as a gzipped TAR archive.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
refoptional | string | The branch name, tag name, or commit sha-1, the default branch if omitted. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
string | string | content | The body of the tarball, or the error message if ok is false. |
async function http.github.fetchZip(owner: string, repo: string, ref?: string): boolean, string | string
Fetches the repository contents as a ZIP archive.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
refoptional | string | The branch name, tag name, or commit sha-1, the default branch if omitted. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
string | string | content | The body of the zipball, or the error message if ok is false. |
async function http.github.getBlob(owner: string, repo: string, file_sha: string): boolean, http.github.Blob | string
Fetches the content of a blob (a blob = file contents) in a repository, using its SHA-1.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
file_sha | string | The SHA1 value of the blob. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Blob | string | blob | The blob, or the error message if ok is false. |
async function http.github.getBranch(owner: string, repo: string, branch: string): boolean, table | string
Fetches a single branch of a repository.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
branch | string | The branch name. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | branch | The branch, or the error message if ok is false. |
async function http.github.getBranches(owner: string, repo: string): boolean, table[] | string
Fetches the branches of a repository.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table[] | string | branches | The list of branches, or the error message if ok is false. |
async function http.github.getCommit(owner: string, repo: string, ref: string): boolean, http.github.Commit | string
Fetches a single commit, a branch or tag name resolves to its latest commit.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
ref | string | The branch name, tag name, or commit sha-1. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Commit | string | commit | The commit, or the error message if ok is false. |
async function http.github.getCommits(owner: string, repo: string, parameters?: table<string, any>, max_pages?: integer): boolean, http.github.Commit[] | string
Fetches the commits of a repository.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
parametersoptional | table<string, any> | Filters: sha (branch/tag/commit), path, author, since, until. |
max_pagesoptional | integer | The maximum number of pages, 1 by default. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Commit[] | string | commits | The list of commits, or the error message if ok is false. |
async function http.github.getContents(owner: string, repo: string, path?: string, ref?: string): boolean, table | string
Fetches the metadata of a file or the listing of a directory.
The content of a file is decoded.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
pathoptional | string | The path in the repository, empty is the root. |
refoptional | string | The branch, tag or commit, the default branch if omitted. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | content | The file object or the list of directory entries, or the error message if ok is false. |
#http.github.getContributors
async function http.github.getContributors(owner: string, repo: string): boolean, http.github.Contributor[] | string
Fetches a list of repository contributors.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Contributor[] | string | contributors | The list of contributors, or the error message if ok is false. |
async function http.github.getEmojis(): boolean, table<string, string> | string
Fetches a list of all github emojis.
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table<string, string> | string | data | The list of emojis, or the error message if ok is false. |
async function http.github.getGist(gist_id: string): boolean, table | string
Parameters
| Name | Type | Description |
|---|
gist_id | string | The gist id. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | gist | The gist, files holds the content, or the error message if ok is false. |
async function http.github.getIssues(owner: string, repo: string, parameters?: table<string, any>, max_pages?: integer): boolean, table[] | string
Fetches the issues of a repository (pull requests are included by Github).
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
parametersoptional | table<string, any> | Filters: state, labels, assignee, since. |
max_pagesoptional | integer | The maximum number of pages, 1 by default. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table[] | string | issues | The list of issues, or the error message if ok is false. |
#http.github.getLanguages
async function http.github.getLanguages(owner: string, repo: string): boolean, table<string, integer> | string
Fetches a list of repository languages.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table<string, integer> | string | languages | The languages, or the error message if ok is false. |
#http.github.getLatestRelease
async function http.github.getLatestRelease(owner: string, repo: string): boolean, http.github.Release | string | nil
Fetches the latest published release of a repository.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Release | string | nil | release | The release, nil if there are none, or the error message if ok is false. |
async function http.github.getLicenses(): boolean, http.github.License[] | string
Fetches a list of all github licenses.
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.License[] | string | list | The list, or the error message if ok is false. |
#http.github.getPullRequests
async function http.github.getPullRequests(owner: string, repo: string, parameters?: table<string, any>, max_pages?: integer): boolean, table[] | string
Fetches the pull requests of a repository.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
parametersoptional | table<string, any> | Filters: state, head, base, sort. |
max_pagesoptional | integer | The maximum number of pages, 1 by default. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table[] | string | pulls | The list of pull requests, or the error message if ok is false. |
#http.github.getRateLimit
async function http.github.getRateLimit(): boolean, table | string
Fetches the current rate limit state of the token (does not count against the limit).
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | limits | The resources and rate tables sent by Github, or the error message if ok is false. |
async function http.github.getReadme(owner: string, repo: string, ref?: string): boolean, table | string
Fetches the readme of a repository, the content is decoded.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
refoptional | string | The branch, tag or commit, the default branch if omitted. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | readme | The readme file object, or the error message if ok is false. |
#http.github.getReleaseByTag
async function http.github.getReleaseByTag(owner: string, repo: string, tag: string): boolean, http.github.Release | string | nil
Fetches the release of a tag.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
tag | string | The tag name. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Release | string | nil | release | The release, nil if not found, or the error message if ok is false. |
async function http.github.getReleases(owner: string, repo: string, max_pages?: integer): boolean, http.github.Release[] | string
Fetches the releases of a repository.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
max_pagesoptional | integer | The maximum number of pages, 50 by default. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Release[] | string | releases | The list of releases, or the error message if ok is false. |
#http.github.getRepositories
async function http.github.getRepositories(organization: string): boolean, http.github.Repository[] | string
Fetches a list of all repositories owned by an organization.
Parameters
| Name | Type | Description |
|---|
organization | string | The name of the organization. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Repository[] | string | repos | The list of repositories, or the error message if ok is false. |
#http.github.getRepository
async function http.github.getRepository(owner: string, repo: string): boolean, http.github.Repository | string
Fetches a detailed information about a specific repository.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Repository | string | repo | The repository, or the error message if ok is false. |
async function http.github.getTopics(owner: string, repo: string): boolean, string[] | string
Fetches the topics of a repository.
Parameters
| Name | Type | Description |
|---|
owner | string | The owner of the repository. |
repo | string | The name of the repository. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
string[] | string | topics | The list of topics, or the error message if ok is false. |
async function http.github.getTree(owner: string, repo: string, tree_sha: string, recursive?: boolean, allow_truncated?: boolean): boolean, http.github.Tree | string
Fetches a single Git tree — that is, a snapshot of the repository's file structure at a specific commit or tree.
Recursive trees are limited by Github to 100,000 entries / 7 MB, a truncated tree throws unless allow_truncated is set.
Parameters
| Name | Type | Description |
|---|
owner | string | The account owner of the repository. The name is not case sensitive. |
repo | string | The name of the repository without the .git extension. The name is not case sensitive. |
tree_sha | string | The SHA1 value or ref (branch or tag) name of the tree. |
recursiveoptional | boolean | Returns the objects or subtrees referenced by the tree specified in :tree_sha. |
allow_truncatedoptional | boolean | Return a truncated tree instead of throwing. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Tree | string | tree | The tree, or the error message if ok is false. |
async function http.github.getUser(login: string): boolean, http.github.User | string
Fetches the user profile.
Parameters
| Name | Type | Description |
|---|
login | string | The username. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.User | string | user | The user, or the error message if ok is false. |
#http.github.getUserRepositories
async function http.github.getUserRepositories(login: string): boolean, http.github.Repository[] | string
Fetches a list of all public repositories owned by a user.
Parameters
| Name | Type | Description |
|---|
login | string | The username. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
http.github.Repository[] | string | repos | The list of repositories, or the error message if ok is false. |
async function http.github.paginate(pathname: string, parameters?: table<string, any>, max_pages?: integer, start_page?: integer): boolean, table[] | string
Fetches every page of a list endpoint and joins them into one list.
Pages are 100 items, the loop stops when there is no next link (or the page is not full if the link is unknown).
Parameters
| Name | Type | Description |
|---|
pathname | string | The path to send the requests to. |
parametersoptional | table<string, any> | The query parameters. |
max_pagesoptional | integer | The maximum number of pages to fetch, 50 by default. |
start_pageoptional | integer | The first page, 1 by default. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether every page was fetched. |
table[] | string | items | The joined list, or the error message. |
#http.github.renderMarkdown
async function http.github.renderMarkdown(text: string, repository?: string): boolean, string | string
Renders Markdown to HTML.
Parameters
| Name | Type | Description |
|---|
text | string | The Markdown text. |
repositoryoptional | string | The owner/repo used to link issues and mentions, switches to the gfm mode. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
string | string | html | The rendered HTML, or the error message if ok is false. |
async function http.github.request(method: http.RequestMethod, pathname: string, headers?: table, body?: string, do_cache?: boolean, extra?: http.github.RequestOptions): http.Response | nil, string | nil
Sends a request to the Github API.
Returns nil and a message when the rate limit is exhausted for too long, other statuses are returned as is.
Parameters
| Name | Type | Description |
|---|
method | http.RequestMethod | The request method. |
pathname | string | The path to send the request to. |
headersoptional | table | The headers to send with the request. |
bodyoptional | string | The body to send with the request. |
do_cacheoptional | boolean | Whether to cache the response, only applies to GET requests, true by default. |
extraoptional | http.github.RequestOptions | The JSON body and query parameters. |
Returns
| Type | Name | Description |
|---|
http.Response | nil | response | The response, nil if the rate limit is exceeded. |
string | nil | message | The reason if there is no response. |
async function http.github.searchCode(query: string, page?: integer): boolean, table | string
Searches code, requires a token.
Parameters
| Name | Type | Description |
|---|
query | string | The search query (https://docs.github.com/en/search-github/searching-on-github/searching-code). |
pageoptional | integer | The page number, 1 by default. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | result | total_count and items (up to 100 matches), or the error message if ok is false. |
#http.github.searchRepositories
async function http.github.searchRepositories(query: string, page?: integer): boolean, table | string
Parameters
| Name | Type | Description |
|---|
query | string | The search query (https://docs.github.com/en/search-github/searching-on-github/searching-for-repositories). |
pageoptional | integer | The page number, 1 by default. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | result | total_count and items (up to 100 repositories), or the error message if ok is false. |
function http.github.template(pathname: string, replaces: table<string, any>): string
Replaces all occurrences of {name} in pathname with the percent-encoded replaces[name].
{+name} keeps / unencoded (for refs and file paths), . and .. segments are rejected, a missing value throws.
Parameters
| Name | Type | Description |
|---|
pathname | string | The path to replace placeholders in. |
replaces | table<string, any> | The table to replace placeholders with. |
Returns
| Type | Name | Description |
|---|
string | pathname | The path with placeholders replaced. |
#http.github.templateRequest
async function http.github.templateRequest(method: http.RequestMethod, pathname: string, replaces: table<string, any>, headers?: table, body?: string, do_cache?: boolean, extra?: http.github.RequestOptions): boolean, table | string
Replaces all placeholders in pathname (see template) and makes a request to the Github API.
Parameters
| Name | Type | Description |
|---|
method | http.RequestMethod | The request method. |
pathname | string | The path to send the request to. |
replaces | table<string, any> | The table to replace placeholders with. |
headersoptional | table | The headers to send with the request. |
bodyoptional | string | The body to send with the request. |
do_cacheoptional | boolean | Whether to cache the response. |
extraoptional | http.github.RequestOptions | The JSON body and query parameters. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded. |
table | string | data | The data returned from the API, or the error message. |
#http.github.tryApiRequest
async function http.github.tryApiRequest(method: http.RequestMethod, pathname: string, headers?: table, body?: string, do_cache?: boolean, extra?: http.github.RequestOptions): boolean, table | string | nil
Same as apiRequest, but a 404 is not a failure: it returns true and nil.
Parameters
| Name | Type | Description |
|---|
method | http.RequestMethod | The request method. |
pathname | string | The path to send the request to. |
headersoptional | table | The headers to send with the request. |
bodyoptional | string | The body to send with the request. |
do_cacheoptional | boolean | Whether to cache the response. |
extraoptional | http.github.RequestOptions | The JSON body and query parameters. |
Returns
| Type | Name | Description |
|---|
boolean | ok | Whether the request succeeded (true for a 404). |
table | string | nil | data | The data returned from the API, nil if not found, or the error message. |