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. It also reads pull requests as they are now: reviewers and votes, changed files, review threads and diffs. It reads only, unless the profile turns writes on: then it can also comment on a pull request and reply in a review thread.

    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.
    token_expiresdate (YYYY-MM-DD)noThe day this entry's token stops working, when you know it. Only used to warn two weeks ahead (safran doctor, get_server_info); never for authentication.

    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.

    Live pull requests

    With the capabilities pull-requests-live, pr-diff and pr-threads the connector reads pull requests as they are now: safran pulls, safran.pulls and the pull request tools.

    • References. {web root}/{owner}/{repo}/pull/{number} and everything the UI hangs behind it (/files, /commits, /checks, /changes, a query, #discussion_r…, #issuecomment-…), on the entry's own web host only. The owner must be the configured one, or the repository must be named with its owner in repos.
    • Votes. A person's decision is their latest APPROVED (approved) or CHANGES_REQUESTED (rejected) review; a dismissed review takes it back; a later comment does not, exactly as on GitHub. People asked who have not decided are none. GitHub has no "approved with suggestions" or "waiting" level, and no "required reviewer" flag.
    • Listing. GitHub has no listing across repositories that carries branches and draft state, so a listing without a repo reads the entry's repositories side by side (at most 25) and merges them. A pull request from a fork is not found by source branch. Filtering by reviewer costs one more request per row.
    • Thread status. With a token, review threads come from GraphQL, the only place GitHub says whether a thread is resolved: resolved, outdated or active. Without a token they are rebuilt from the REST review comments, which have no resolved flag: every thread then reads active (or outdated when its comment no longer has a place in the diff), resolved ones included, and the log says so once. General comments and review summaries cannot be resolved on GitHub and are always active.
    • Thread ids name the first comment the way the UI's links do: discussion_r<id> for a review thread, issuecomment-<id> for a general comment, pullrequestreview-<id> for a review summary.
    • Diffs are the patches GitHub computed. The context cannot be varied: GitHub always sends three lines. A file whose lines were counted but whose patch was withheld as too large comes back truncated. GitHub sends no binary flag; a file without lines and without a patch is taken as binary.

    Writes

    Off unless the profile enables them; see writes.

    • pull_request.comment (write:pr-comment): a general comment is an issue comment; a comment on a file or a line is a review comment anchored to the head commit of the pull request, which costs one read before the one write. A line outside the diff is refused by GitHub and reported as INVALID_INPUT, not turned into a general comment.
    • pull_request.reply (write:pr-reply): a reply to a review thread (discussion_r…). General comments and review summaries are threads of one comment with nothing to reply into: answering one is UNSUPPORTED rather than a new top-level comment in disguise.

    A fine-grained token most likely needs "Pull requests" (write) on the repository, a classic token the repo scope (public_repo for public repositories). A private repository the token cannot see answers 404, not 403.

    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.

    • Live pull requests: what was run and what was not. Without a token, against a public repository, one run exercised the reference matching, "Get a pull request" and the paging of "List reviews". The changed-files listing, review comments, the GraphQL query for resolved threads and both writes were not run against the live service.

    • Review states and merge states. The documentation types both as plain strings without listing their values; the connector uses the values the API has always sent.

    • outdated without a token is read from a review comment having lost its line; the documentation does not describe that state.

    • Binary files are inferred (no lines, no patch); a change of file mode alone would also be reported as binary.

    See also