FerryDocs
ReferenceAPI reference

Git connections

Git connections: the GitHub / GitLab accounts this server is authorized to read the repositories of, to pick a repository and a branch from a list and to clone private repositories. An account is authorized in the browser (a GitHub App on GitHub, an OAuth application on GitLab) or with an access token. Connections belong to the server, not to a service: a repository is cloned with the connection that serves its URL.

POST/api/v1/git/authorize

Starts connecting an account on the provider's own pages and answers with where to send the browser (status: redirect): a URL to navigate to (method: get) or to submit a form with fields to (method: post). When the provider is done it sends the browser back to redirect_uri (the dashboard's /git/callback page) with query parameters to hand to POST /api/v1/git/callback.

GitHub: the browser posts a manifest to GitHub, which registers a private GitHub App for this server (on the user's account, or in organization) and then asks the account which repositories the app may read. No token is ever typed: the app's key mints short-lived tokens.

GitLab: the account authorizes an OAuth application created for this server (scopes read_api and read_repository, redirect URI = redirect_uri). Give its client_id and client_secret the first time (400 git_application_required otherwise); they are kept for later authorizations.

With connection_id, resumes a pending connection or authorizes a connection again; the answer is status: connected when nothing is left to do (a GitHub App that is already installed).

Authorization

AuthorizationBearer <token>

An API token: one created in the dashboard or by ferry login, or the server token stored in <data-dir>/api_token. GET requests may send it as ?access_token= instead.

In: header

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

POST /api/v1/git/authorize — start, or resume, the authorization of a git provider account in the browser.

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/api/v1/git/authorize" \  -H "Authorization: Bearer $FERRY_TOKEN" \  -H "Content-Type: application/json" \  -d '{    "redirect_uri": "string"  }'
{  "connection": {    "account": "string",    "account_name": "string",    "app_slug": "string",    "app_url": "string",    "auth": "github_app",    "base_url": "string",    "client_id": "string",    "created_at": "2019-08-24T14:15:22Z",    "id": "string",    "manage_url": "string",    "provider": "github",    "repository_selection": "string",    "scopes": [      "string"    ],    "services": [      "string"    ],    "status": "connected",    "token_expires_at": "2019-08-24T14:15:22Z",    "token_hint": "string",    "updated_at": "2019-08-24T14:15:22Z"  },  "fields": {    "property1": "string",    "property2": "string"  },  "method": "get",  "status": "redirect",  "url": "string"}
POST/api/v1/git/callback

Takes the query parameters the provider sent the browser back with (to the redirect_uri given to POST /api/v1/git/authorize): state, and code and / or installation_id. Answers with the next page to send the browser to (status: redirect: after GitHub registered the app, its installation page) or with the connection (status: connected). A state works once, for an hour. Without state but with an installation_id (GitHub sends the browser back after an installation was changed on its own pages), the connection of that installation is read again.

Authorization

AuthorizationBearer <token>

An API token: one created in the dashboard or by ferry login, or the server token stored in <data-dir>/api_token. GET requests may send it as ?access_token= instead.

In: header

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

POST /api/v1/git/callback — the query parameters the provider sent the browser back with.

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/api/v1/git/callback" \  -H "Authorization: Bearer $FERRY_TOKEN" \  -H "Content-Type: application/json" \  -d '{    "state": "string"  }'
{  "connection": {    "account": "string",    "account_name": "string",    "app_slug": "string",    "app_url": "string",    "auth": "github_app",    "base_url": "string",    "client_id": "string",    "created_at": "2019-08-24T14:15:22Z",    "id": "string",    "manage_url": "string",    "provider": "github",    "repository_selection": "string",    "scopes": [      "string"    ],    "services": [      "string"    ],    "status": "connected",    "token_expires_at": "2019-08-24T14:15:22Z",    "token_hint": "string",    "updated_at": "2019-08-24T14:15:22Z"  },  "fields": {    "property1": "string",    "property2": "string"  },  "method": "get",  "status": "redirect",  "url": "string"}

List git connections

GET/api/v1/git/connections

The GitHub / GitLab accounts this server is authorized to read the repositories of, with the names of the services whose repository each one clones. A pending connection was started in the browser and not finished. Secrets are never returned.

Authorization

AuthorizationBearer <token>

An API token: one created in the dashboard or by ferry login, or the server token stored in <data-dir>/api_token. GET requests may send it as ?access_token= instead.

In: header

Response Body

application/json

application/json

application/json

curl -X GET "https://example.com/api/v1/git/connections" \  -H "Authorization: Bearer $FERRY_TOKEN"
[  {    "account": "string",    "account_name": "string",    "app_slug": "string",    "app_url": "string",    "auth": "github_app",    "base_url": "string",    "client_id": "string",    "created_at": "2019-08-24T14:15:22Z",    "id": "string",    "manage_url": "string",    "provider": "github",    "repository_selection": "string",    "scopes": [      "string"    ],    "services": [      "string"    ],    "status": "connected",    "token_expires_at": "2019-08-24T14:15:22Z",    "token_hint": "string",    "updated_at": "2019-08-24T14:15:22Z"  }]
POST/api/v1/git/connections

The alternative to authorizing in the browser (POST /api/v1/git/authorize), for scripts and for instances where no application can be registered: connects the account a personal access token belongs to. Ferry asks the provider who the token is, then stores it. On GitHub use a classic personal access token with the repo scope, or a fine-grained one with read access to Contents and Metadata; on GitLab one with the read_api and read_repository scopes. base_url selects a self-hosted instance (GitHub Enterprise Server, GitLab self-managed). An account that is already connected gets the token instead of what it had (200 instead of 201). The token is never returned by the API.

Authorization

AuthorizationBearer <token>

An API token: one created in the dashboard or by ferry login, or the server token stored in <data-dir>/api_token. GET requests may send it as ?access_token= instead.

In: header

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

POST /api/v1/git/connections — connect an account of a git provider with a personal access token (instead of authorizing it in the browser).

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/api/v1/git/connections" \  -H "Authorization: Bearer $FERRY_TOKEN" \  -H "Content-Type: application/json" \  -d '{    "provider": "github",    "token": "string"  }'
{  "account": "string",  "account_name": "string",  "app_slug": "string",  "app_url": "string",  "auth": "github_app",  "base_url": "string",  "client_id": "string",  "created_at": "2019-08-24T14:15:22Z",  "id": "string",  "manage_url": "string",  "provider": "github",  "repository_selection": "string",  "scopes": [    "string"  ],  "services": [    "string"  ],  "status": "connected",  "token_expires_at": "2019-08-24T14:15:22Z",  "token_hint": "string",  "updated_at": "2019-08-24T14:15:22Z"}

Get a git connection

GET/api/v1/git/connections/{id}

Authorization

AuthorizationBearer <token>

An API token: one created in the dashboard or by ferry login, or the server token stored in <data-dir>/api_token. GET requests may send it as ?access_token= instead.

In: header

Path Parameters

id*string

Git connection id.

Response Body

application/json

application/json

application/json

application/json

curl -X GET "https://example.com/api/v1/git/connections/string" \  -H "Authorization: Bearer $FERRY_TOKEN"
{  "account": "string",  "account_name": "string",  "app_slug": "string",  "app_url": "string",  "auth": "github_app",  "base_url": "string",  "client_id": "string",  "created_at": "2019-08-24T14:15:22Z",  "id": "string",  "manage_url": "string",  "provider": "github",  "repository_selection": "string",  "scopes": [    "string"  ],  "services": [    "string"  ],  "status": "connected",  "token_expires_at": "2019-08-24T14:15:22Z",  "token_hint": "string",  "updated_at": "2019-08-24T14:15:22Z"}

Disconnect a git account

DELETE/api/v1/git/connections/{id}

Deletes the connection and its secrets. What it authorized stays on the provider until it is removed there: the GitHub App (delete it in GitHub's settings), the OAuth grant or the token. Refused while services' repositories are cloned with it, unless force=true: those services keep their repository and are cloned without credentials from then on, which fails for private repositories.

Authorization

AuthorizationBearer <token>

An API token: one created in the dashboard or by ferry login, or the server token stored in <data-dir>/api_token. GET requests may send it as ?access_token= instead.

In: header

Path Parameters

id*string

Git connection id.

Query Parameters

force?boolean

Disconnect even though services are cloned with the connection.

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X DELETE "https://example.com/api/v1/git/connections/string" \  -H "Authorization: Bearer $FERRY_TOKEN"
Empty
GET/api/v1/git/connections/{id}/repositories

The repositories the connection can read, asked from the provider on every call, most recently updated first: for a GitHub App the repositories the account allowed it to read (see manage_url); otherwise the account's own, its organizations' / groups' and those it collaborates on. At most 1000 are listed (truncated says when there are more). Use a repository's clone_url as the repo_url of a service: it is cloned with this connection.

Authorization

AuthorizationBearer <token>

An API token: one created in the dashboard or by ferry login, or the server token stored in <data-dir>/api_token. GET requests may send it as ?access_token= instead.

In: header

Path Parameters

id*string

Git connection id.

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

curl -X GET "https://example.com/api/v1/git/connections/string/repositories" \  -H "Authorization: Bearer $FERRY_TOKEN"
{  "repositories": [    {      "archived": true,      "clone_url": "string",      "default_branch": "string",      "description": "string",      "full_name": "string",      "id": "string",      "name": "string",      "owner": "string",      "private": true,      "updated_at": "2019-08-24T14:15:22Z",      "web_url": "string"    }  ],  "truncated": true}
GET/api/v1/git/branches

The branches of a repository and its default one, asked from the repository's remote itself (git ls-remote) on every call. Works for any repository URL a service can deploy from; it is read the way a deploy would clone it: with the git connection that serves the URL when there is one (connection_id in the answer), with the credentials the URL carries, or without any.

Authorization

AuthorizationBearer <token>

An API token: one created in the dashboard or by ferry login, or the server token stored in <data-dir>/api_token. GET requests may send it as ?access_token= instead.

In: header

Query Parameters

repo_url*string

The repository: any URL a service can deploy from (https://…, git@host:owner/name.git, a path on the server).

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X GET "https://example.com/api/v1/git/branches?repo_url=string" \  -H "Authorization: Bearer $FERRY_TOKEN"
{  "branches": [    "string"  ],  "connection_id": "string",  "default_branch": "string"}