IF Commons GitHub

mod

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-githost FR-004

The Git hosts behind one interface (commons 0001-githost FR-001 to FR-006): GitHub, GitLab (groups to any depth, gitlab.com or self-managed) and plain Git, shaped together as GitHostClient, with the reading of a remote URL, the table of what each kind offers and clientFor, the one place that reads a credential.

clientFor(ref, { env }) chooses the adapter by the kind of the reference and reads a token from env alone (GITHUB_TOKEN, then GH_TOKEN for GitHub; GITLAB_TOKEN, then CI_JOB_TOKEN for GitLab): the caller passes its environment, so that this code reads none itself. The token is held in the adapter's closure and nowhere else; it is never in a result, a failure, a URL or a log, and the live transport it makes sends it only to the host the client serves.

Source: commons/githost/src/mod.ts

1 of 2 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

ClientForOptionstypeno test imports it
type ClientForOptions = { /** The caller's environment: where the token is read from, and nowhere else. */ readonly … (1097 characters)
type ClientForOptions = {
  /** The caller's environment: where the token is read from, and nowhere else. */
  readonly env: Readonly<Record<string, string | undefined>>;
  /** How requests are sent; the live transport (with backoff, and a credential allowed only where a token is given) by default. */
  readonly transport?: Transport;
  /** For a plain Git remote: where it is asked from and where a clone is. */
  readonly plain?: PlainGitOptions;
  /**
   * The hosts, besides `github.com` and `gitlab.com`, that may be sent a token: those the manifest names (a self-managed GitLab, GitHub Enterprise Server). A host not here is asked with no
   * credential, so that an environment's token is never sent to a host nobody named.
   */
  readonly trustedHosts?: readonly string[];
  /** The base URL of a self-managed GitLab, where the reference's host is not `gitlab.com` and is not served over `https://<host>`. */
  readonly gitlabBaseUrl?: string;
  /** The API's base URL of a GitHub Enterprise Server host, where it is not `https://<host>/api/v3`. */
  readonly githubApiBase?: string;
};

What clientFor reads and uses.

clientForfunction
function clientFor(ref: RepoRef, options: ClientForOptions): GitHostClient

The client for a reference's kind of host, with the token the environment holds for it, if any and if the host may receive one.

Imported by 3 tests of the run (3 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.