GitHub
The github code host lists the repositories of an organization or user, supplies the credentials to clone them, and reads merged pull requests with the issues they close and the files they changed. It works with github.com and GitHub Enterprise Server, without a token for public repositories, and it is read-only.
Profile entry
- id: github
type: github
owner: acme
token_env: GITHUB_TOKENsafran repos
safran sync payments-api
safran links refreshimport { createSafran } from "@safran/core";
await using safran = await createSafran({ profile: "safran.yaml" });
const repos = await safran.repos.list();
for (const repo of repos) console.log(repo.name, repo.defaultBranch, repo.primaryLanguage, repo.archived === true ? "archived" : "");
const report = await safran.links.refresh({ repos: ["payments-api"], since: "2026-01-01" });
console.log(report.repos);Authentication
token_env is optional.
- With a token, REST requests send
Authorization: Bearer. Git gets HTTP Basic with the userx-access-tokenand the token as password, passed only through the environment of the git process (anhttp.<origin>.extraHeadersetting), never inside the clone URL. - Without
token_env, requests and clones are anonymous. That works for public repositories; GitHub then allows 60 requests per hour.
The source names no scope. The token needs read access to the repositories' contents and pull requests.
Public repositories, no token
- id: github
type: github
owner: acme
repos: [payments-api, ledger]Explicit repositories, other owners
- id: github
type: github
owner: acme
repos: [payments-api, ledger, acme-labs/design-tokens]
token_env: GITHUB_TOKENWith repos, the owner is not listed at all: each named repository is fetched by name. An entry of the form other-owner/name reaches a repository outside owner.
GitHub Enterprise Server
- id: github
type: github
owner: acme
token_env: GITHUB_TOKEN
url: https://github.acme.test/api/v3url is the API root. The web address used for links is derived from it: api.github.com becomes github.com, and a trailing /api/v3 is removed.
Configuration reference
| Field | Type | Default | Required | Meaning |
|---|---|---|---|---|
id | string | yes | Name of this entry; the host of its repositories. | |
include | string[] | [] | no | Glob patterns on repository names. Empty means all. |
exclude | string[] | [] | no | Glob patterns on repository names. Exclude wins over include. |
type | "github" | yes | Selects this plugin. | |
owner | string | yes | Organization or user that owns the repositories. No slashes. | |
owner_type | auto, org or user | auto | no | Which listing endpoint to use. auto asks the organization endpoint first and falls back to the user endpoint on 404. |
repos | string[] | no | Explicit repositories instead of listing the owner: name, or other-owner/name. At least one when present. | |
token_env | variable name | no | Variable holding a token. Omit for public repositories. | |
url | URL | https://api.github.com | no | API root. GitHub Enterprise Server: https://HOSTNAME/api/v3. |
How repositories are listed and named
- An organization is listed with all its repositories the token can see.
- A user is listed with the repositories that user owns, and this listing only returns public ones. To include a user's private repositories, name them under
repos. - A repository is called by its name:
payments-api. One under another owner (only possible throughrepos) is calledowner/name. fullNameisowner/name.- Disabled repositories are left out because they cannot be cloned. Archived ones are kept, with
archived: true: they can be cloned and still explain the code base. - Listings follow GitHub's
Linkheader. The "next" link is moved onto the configured origin before it is requested, so the token only ever goes to the host in the profile.
If the same short name exists on another code host entry, the host listed first in the profile keeps it and the later one is named <hostId>/<name>.
include and exclude are applied by Safran after the listing, to the short name and to fullName. * is any run of characters, ? exactly one; matching is case-insensitive and covers the whole name.
- id: github
type: github
owner: acme
token_env: GITHUB_TOKEN
include: ["payments-*", "ledger", "acme-ios", "acme-android"]
exclude: ["*-archive"]Pull requests and linked tickets
Closed pull requests are read newest update first, and only merged ones are returned.
PullRequest field | Source |
|---|---|
id | The pull request number |
title, description | Title and full body |
mergedAt, mergeCommit | merged_at, merge_commit_sha |
sourceBranch, targetBranch | Head and base branch |
linkedTicketKeys | Issues named with a closing keyword in the description |
url | The pull request's web URL |
What counts as a linked ticket. The host reads GitHub's closing keywords from the description: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved, followed by a space or a colon and one of:
| Written in the description | Key |
|---|---|
Fixes #412 | payments-api#412 (the pull request's own repository) |
Closes acme/web-app#412 | web-app#412 |
Resolves acme-labs/design-tokens#7 | acme-labs/design-tokens#7 (another owner keeps its owner) |
fixes https://github.com/acme/web-app/issues/412 | web-app#412 |
closes https://gitlab.acme.test/x/y/issues/3 | nothing: a URL only counts on this host's own web address |
These keys have the form the github-issues tracker uses. Keywords inside HTML comments, fenced code blocks and inline code are ignored, as they are when GitHub renders the text; pull request templates often carry example keywords in comments. #12abc is not issue 12.
Safran then adds the keys it finds in the title, the source branch and the description, for the project keys declared under trackers[].projects. With tickets in Jira, a pull request titled PAY-1423 partial refund rounding is linked to PAY-1423 without any closing keyword.
Changed files are the pull request's file list without removed files; a rename reports the new path. GitHub lists at most GITHUB_MAX_PULL_REQUEST_FILES files per pull request; beyond that the list is cut and a warning is logged.
With mergedSince, the listing stops as soon as it reaches a pull request whose last update is older than the date: nothing further can have been merged since.
File links
import { createSafran } from "@safran/core";
await using safran = await createSafran({ profile: "safran.yaml" });
const url = safran.hosts.get("github")?.fileUrl?.("payments-api", "src/refund/service.ts", "main", { start: 40, end: 58 });
console.log(url); // https://github.com/acme/payments-api/blob/main/src/refund/service.ts#L40-L58Rate limits
GitHub answers an exhausted rate limit with 403, which would otherwise read as "access denied". The connector recognises it from the rate-limit headers, a retry-after header or the message, and reports RATE_LIMITED with the time requests are allowed again in the hint and in details.resetAt. An exhausted primary limit is not retried, because it resets in minutes, not seconds. Without a token the hint also says that token_env raises the limit.
Limits
| Constant | Value | Meaning |
|---|---|---|
DEFAULT_PULL_REQUEST_LIMIT / MAX_PULL_REQUEST_LIMIT | 50 / 500 | Pull requests returned per call. |
GITHUB_PULL_REQUEST_PAGE_SIZE | 50 | Closed pull requests asked from GitHub per request. |
DEFAULT_MAX_PULL_REQUEST_PAGES | 20 | Upstream pages one call reads before returning what it has, with a cursor to continue. |
GITHUB_PAGE_SIZE | 100 | Repositories and files per request. |
DEFAULT_MAX_REPO_PAGES | 100 | Pages of a repository listing (10,000 repositories). |
GITHUB_MAX_PULL_REQUEST_FILES | 3000 | Files GitHub lists for one pull request. |
GITHUB_API_VERSION | 2022-11-28 | Sent as X-GitHub-Api-Version. |
Known caveats
This is the one built-in code host that has been run against the live service, with public repositories on github.com. Private repositories, organization-wide listing with a token and GitHub Enterprise Server are covered by fixture tests only. See verification status. The source marks nothing in this connector UNVERIFIED; these are its documented limits:
- A user's private repositories are not listed; name them under
repos. - A pull request with more than 3000 changed files has an incomplete file list.
- Linked tickets are read from the description only, not from issues linked through the sidebar of the pull request.
See also
- GitHub Issues, the tracker for the same owner.
- Repos in the SDK and links.
- Connectors overview for the rules shared by all connectors.