Skip to content
safran

Type to search. Enter opens the first result.

    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_TOKEN
    safran repos
    safran sync payments-api
    safran links refresh
    list-repos.ts
    import { 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 user x-access-token and the token as password, passed only through the environment of the git process (an http.<origin>.extraHeader setting), 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_TOKEN

    With 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/v3

    url 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

    FieldTypeDefaultRequiredMeaning
    idstringyesName of this entry; the host of its repositories.
    includestring[][]noGlob patterns on repository names. Empty means all.
    excludestring[][]noGlob patterns on repository names. Exclude wins over include.
    type"github"yesSelects this plugin.
    ownerstringyesOrganization or user that owns the repositories. No slashes.
    owner_typeauto, org or userautonoWhich listing endpoint to use. auto asks the organization endpoint first and falls back to the user endpoint on 404.
    reposstring[]noExplicit repositories instead of listing the owner: name, or other-owner/name. At least one when present.
    token_envvariable namenoVariable holding a token. Omit for public repositories.
    urlURLhttps://api.github.comnoAPI 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 through repos) is called owner/name.
    • fullName is owner/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 Link header. 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 fieldSource
    idThe pull request number
    title, descriptionTitle and full body
    mergedAt, mergeCommitmerged_at, merge_commit_sha
    sourceBranch, targetBranchHead and base branch
    linkedTicketKeysIssues named with a closing keyword in the description
    urlThe 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 descriptionKey
    Fixes #412payments-api#412 (the pull request's own repository)
    Closes acme/web-app#412web-app#412
    Resolves acme-labs/design-tokens#7acme-labs/design-tokens#7 (another owner keeps its owner)
    fixes https://github.com/acme/web-app/issues/412web-app#412
    closes https://gitlab.acme.test/x/y/issues/3nothing: 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-url.ts
    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-L58

    Rate 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

    ConstantValueMeaning
    DEFAULT_PULL_REQUEST_LIMIT / MAX_PULL_REQUEST_LIMIT50 / 500Pull requests returned per call.
    GITHUB_PULL_REQUEST_PAGE_SIZE50Closed pull requests asked from GitHub per request.
    DEFAULT_MAX_PULL_REQUEST_PAGES20Upstream pages one call reads before returning what it has, with a cursor to continue.
    GITHUB_PAGE_SIZE100Repositories and files per request.
    DEFAULT_MAX_REPO_PAGES100Pages of a repository listing (10,000 repositories).
    GITHUB_MAX_PULL_REQUEST_FILES3000Files GitHub lists for one pull request.
    GITHUB_API_VERSION2022-11-28Sent 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