Request Objects
Each event hands your listener a request object. They share a common base (an HTTP duplex wrapping the request and response) and add event-specific fields.
Common members
Every request object exposes:
| Member | Description |
|---|---|
repo | the repository name |
accept() | allow the operation |
reject(code, message) | reject with an HTTP status code and message |
headers | incoming request headers |
method | HTTP method ("GET" / "POST") |
url | request URL |
cwd | the resolved repository directory on disk |
exists | whether the repository already existed |
Because the object wraps the underlying response, res and the usual stream helpers
(write, end, setHeader, …) are available too.
push
interface PushData {
repo: string
commit: string // sha being pushed
branch: string // branch name
log(...args): void // send a `remote:` line to the client
}tag
interface TagData {
repo: string
commit: string
version: string // the tag name
}fetch
interface FetchData {
repo: string
commit: string
}info and head
interface InfoData {
repo: string
}
interface HeadData {
repo: string
}Accept / reject
For every event, exactly one listener must call accept() or reject(). If no
listeners are attached for an event, it is accepted automatically.
repos.on("push", (push) => {
if (isProtected(push.branch)) {
push.reject(403, "branch is protected")
} else {
push.accept()
}
})