node-git-server logonode-git-server

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:

MemberDescription
repothe repository name
accept()allow the operation
reject(code, message)reject with an HTTP status code and message
headersincoming request headers
methodHTTP method ("GET" / "POST")
urlrequest URL
cwdthe resolved repository directory on disk
existswhether 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()
    }
})