GitForge
GitForge.jl is a unified interface for interacting with Git "forges".
GitForge.Forge — TypeA forge is an online platform for Git repositories. The most common example is GitHub.
Forge subtypes can access their respective web APIs.
Supported Forges
GitHub
GitForge.GitHub.GitHubAPI — TypeGitHubAPI(;
token::AbstractToken=NoToken(),
url::AbstractString="https://api.github.com",
has_rate_limits::Bool=true,
on_rate_limit::OnRateLimit=ORL_THROW,
)Create a GitHub API client.
Keywords
token::AbstractToken=NoToken(): Authorization token (or lack thereof).url::AbstractString="https://api.github.com": Base URL of the target GitHub instance.has_rate_limits::Bool=true: Whether or not the GitHub server has rate limits.on_rate_limit::OnRateLimit=ORL_THROW: Behaviour on exceeded rate limits.
GitForge.GitHub.NoToken — TypeNoToken()Represents no authentication. Only public data will be available.
GitForge.GitHub.Token — TypeToken(token::AbstractString)An OAuth2 token, or a personal access token.
GitForge.GitHub.JWT — TypeJWT(token::AbstractString)A JWT signed by a private key for GitHub Apps.
GitLab
GitForge.GitLab.GitLabAPI — TypeGitLabAPI(;
token::AbstractToken=NoToken(),
url::AbstractString="https://gitlab.com/api/v4",
has_rate_limits::Bool=true,
on_rate_limit::OnRateLimit=ORL_THROW,
)Create a GitLab API client.
Keywords
token::AbstractToken=NoToken(): Authorization token (or lack thereof).url::AbstractString"https://gitlab.com/api/v4": Base URL of the target GitLab instance.has_rate_limits::Bool=true: Whether or not the GitLab server has rate limits.on_rate_limit::OnRateLimit=ORL_THROW: Behaviour on exceeded rate limits.
GitForge.GitLab.NoToken — TypeNoToken()Represents no authentication. Only public data will be available.
GitForge.GitLab.OAuth2Token — TypeOAuth2Token(token::AbstractString)GitForge.GitLab.PersonalAccessToken — TypePersonalAccessToken(token::AbstractString)API
Each API function (get_user, get_repo, etc.) returns a Tuple{T, HTTP.Response}. The value of T depends on what function you've called. For example, get_user will generally return some User type for your forge.
When things go wrong, exceptions are thrown. They will always be one of the following types:
GitForge.ForgeError — TypeThe supertype of all other exceptions raised by API functions.
GitForge.HTTPError — TypeAn error encountered during the HTTP request.
Fields
response::Union{HTTP.Response, Nothing}: Set for status exceptions.exception::Exceptionstacktrace::StackTrace
GitForge.PostProcessorError — TypeAn error encountered during response postprocessing.
Fields
response::HTTP.Responseexception::Exceptionstacktrace::StackTrace
GitForge.RateLimitedError — TypeA signal that a rate limit has been exceeded.
Fields
period::Union{Period, Nothing}Amount of time until rate limit expiry, if known.
Pagination
GitForge.@paginate — Macro@paginate fun(args...; kwargs...) page=1 per_page=100 -> PaginatorCreate an iterator that paginates the results of repeatedly calling fun(args...; kwargs...). The first argument of fun must be a Forge and it must return a Tuple{Vector{T}, HTTP.Response}.
Keywords
page::Int=1: Starting page.per_page::Int=100: Number of entries per page.
Endpoints
These functions all allow any number of trailing keywords. For more information on these keywords, see request.
GitForge.get_user — Functionget_user(::Forge[, name_or_id::Union{AbstractString, Integer, UUID}])Get the currently authenticated user, or a user by name or ID.
GitForge.get_users — Functionget_users(::Forge)Get all users.
GitForge.update_user — Functionupdate_user(::Forge[, id::Union{Integer, UUID}]; kwargs...)Update the currently authenticated user, or a user by ID.
GitForge.create_user — Functioncreate_user(::Forge; kwargs...)Create a new user.
GitForge.delete_user — Functiondelete_user(::Forge, id::Union{Integer, UUID})Delete a user by ID.
GitForge.get_user_repos — Functionget_user_repos(::Forge[, name_or_id::Union{AbstractString, Integer, UUID}])Get the currently authenticated user's repositories, or those of a user by name or ID.
GitForge.get_repo — Functionget_repo(::Forge, owner_repo::AbstractString)
get_repo(::Forge, owner::AbstractString, repo::AbstractString)
get_repo(::Forge, id::Integer)
get_repo(::Forge, id::UUID)
get_repo(::Forge, owner::AbstractString, subgroup::AbstractString, repo::AbstractString)Get a repository by owner and name or ID.
GitForge.get_branch — Functionget_branch(::Forge, owner::AbstractString, repo::AbstractString, branch::AbstractString)Get a branch from a repository.
GitForge.get_file_contents — Functionget_file_contents(
::Forge,
owner::AbstractString,
repo::AbstractString,
path::AbstractString,
)
get_file_contents(f::Forge, id::Integer, path::AbstractString)Get a file from a repository.
GitForge.get_pull_request — Functionget_pull_request(::Forge, owner::AbstractString, repo::AbstractString, number::Integer)
get_pull_request(::Forge, project::Integer, number::Integer)Get a specific pull request.
GitForge.get_pull_requests — Functionget_pull_requests(::Forge, owner::AbstractString, repo::AbstractString)
get_pull_requests(::Forge, project::Integer)List a repository's pull requests.
GitForge.create_pull_request — Functioncreate_pull_request(::Forge, owner::AbstractString, repo::AbstractString; kwargs...)
create_pull_request(::Forge, project::Integer; kwargs...)Create a pull request.
GitForge.update_pull_request — Functionupdate_pull_request(::Forge, owner::AbstractString, repo::AbstractString, number::Integer; kwargs...)
update_pull_request(::Forge, project::Integer, number::Integer; kwargs...)Update a pull request.
GitForge.get_commit — Functionget_commit(::Forge, owner::AbstractString, repo::AbstractString, ref::AbstractString)
get_commit(::Forge, project::Integer, ref::AbstractString)Get a commit from a repository.
GitForge.get_tags — Functionget_tags(::Forge, owner::AbstractString, repo::AbstractString)
get_tags(::Forge, project::Integer)Get a list of tags from a repository.
GitForge.is_collaborator — Functionis_collaborator(
::Forge,
owner::AbstractString,
repo::AbstractString,
name_or_id::Union{AbstractString, Integer, UUID},
)Check whether or not a user is a collaborator on a repository.
GitForge.is_member — Functionis_member(::Forge, org::AbstractString, name_or_id::Union{AbstractString, Integer, UUID})Check whether or not a user is a member of an organization.
Internals
The following resources are useful for implementing new forges, or customizing behaviour.
Many functions take a Function argument, which can be used to limit the affected API functions. To make a method specific to a single function, use ::typeof(fun).
URLs
These functions set request URLs. To determine the full URL for a given request, they are concatenated together.
GitForge.base_url — Functionbase_url(::Forge) -> StringReturns the base URL of all API endpoints.
GitForge.endpoint — Functionendpoint(::Forge, ::Function, args...) -> EndpointReturns an Endpoint for a given function. Trailing arguments are usually important for routing. For example, get_user can take some ID parameter which becomes part of the URL.
GitForge.Endpoint — TypeEndpoint(
method::Symbol,
url::AbstractString;
headers::Vector{<:Pair}=HTTP.Header[],
query::Dict=Dict(),
allow_404::Bool=false,
) -> EndpointContains information on how to call an endpoint.
Arguments
method::Symbol: HTTP request method to use.url::AbstractString: Endpoint URL, relative to the base URL.
Keywords
headers::Vector{<:Pair}=HTTP.Header[]: Request headers to add.query::Dict=Dict(): Query string parameters to add.allow_404::Bool=false: Sends responses with 404 statuses to the postprocessor.
Request Options
These functions set parts of HTTP requests.
GitForge.request_headers — Functionrequest_headers(::Forge, ::Function) -> Vector{Pair}Returns the headers that should be added to each request.
GitForge.request_query — Functionrequest_query(::Forge, ::Function) -> DictReturns the query string parameters that should be added to each request.
GitForge.request_kwargs — Functionrequest_kwargs(::Forge, ::Function) -> Dict{Symbol}Returns the extra keyword arguments that should be passed to HTTP.request.
Requests
This function makes the actual HTTP requests.
GitForge.request — Functionrequest(
f::Forge, fun::Function, ep::Endpoint;
headers::Vector{<:Pair}=HTTP.Header[],
query::AbstractDict=Dict(),
request_opts=Dict(),
kwargs...,
) -> T, HTTP.ResponseMake an HTTP request and return T and the response, where T is determined by into.
Arguments
f::ForgeAForgesubtype.fun::Function: The API function being called.ep::Endpoint: The endpoint information.
Keywords
query::AbstractDict=Dict(): Query string parameters to add to the request.headers::Vector{<:Pair}=HTTP.Header[]: Headers to add to the request.request_opts=Dict(): Keywords passed intoHTTP.request.
Trailing keywords are sent as a JSON body for PATCH, POST, and PUT requests. For other request types, the keywords are sent as query string parameters.
Every API function passes its keyword arguments into this function. Therefore, to customize behaviour for a single request, pass the above keywords to the API function.
Rate Limiting
These functions and types handle certain generic rate limiters.
GitForge.RateLimiter — TypeA generic rate limiter using the [X-]RateLimit-Remaining and [X-]RateLimit-Reset response headers. The reset header is assumed to be a Unix timestamp in seconds.
GitForge.OnRateLimit — TypeDetermines how to react to an exceeded rate limit.
ORL_THROW: Throw aRateLimitedError.ORL_WAIT: Block and wait for the rate limit to expire.
GitForge.has_rate_limits — Functionhas_rate_limits(::Forge, ::Function) -> BoolReturns whether or not the forge server uses rate limiting.
GitForge.rate_limit_check — Functionrate_limit_check(::Forge, ::Function) -> BoolReturns whether or not there is an active rate limit. If one is found, on_rate_limit is called to determine how to react.
GitForge.on_rate_limit — Functionon_rate_limit(::Forge, ::Function) -> OnRateLimitReturns an OnRateLimit that determines how to react to an exceeded rate limit.
GitForge.rate_limit_wait — Functionrate_limit_wait(::Forge, ::Function)Wait for a rate limit to expire.
GitForge.rate_limit_period — Functionrate_limit_period(::Forge, ::Function) -> PeriodCompute the amount of time until a rate limit expires.
GitForge.rate_limit_update! — Functionrate_limit_update!(::Forge, ::Function, ::HTTP.Response)Update the rate limiter with a new response.
Post Processing
These functions and types process HTTP responses.
GitForge.postprocessor — Functionpostprocessor(::Forge, ::Function) -> PostProcessorReturns the PostProcessor to be used.
GitForge.into — Functioninto(::Forge, ::Function) -> TypeReturns the type that the PostProcessor should create from the response.
GitForge.PostProcessor — TypeDetermines the behaviour of postprocess.
GitForge.postprocess — Functionpostprocess(::PostProcessor, ::HTTP.Response, ::Type{T})Computes a value to be returned from an HTTP response.
GitForge.DoNothing — TypeDoes nothing and always returns nothing.
GitForge.DoSomething — TypeDoSomething(::Function) -> DoSomethingRuns a user-defined postprocessor.
GitForge.JSON — TypeJSON(f::Function=identity) -> JSONParses a JSON response into a given type and runs f on that object.
GitForge.@json — Macro@json struct T ... end
@json FORGETYPE struct T ... endCreate a type that can be parsed from JSON.
Optionally accept a forge type for struct names that do not follow the ModuleAPI convention