Architecture

Celerium.GitHub is a thin, generated layer over one shared request engine.

GitHub OpenAPI description (docs/api.github.com.2026-03-10.json)
        |  build/New-PublicFunctions.ps1 (+ build/Helpers)
        v
Celerium.GitHub/Public/<Category>/Verb-GitHubNoun.ps1   (~1,280 generated functions)
        |  each builds PathParameters / Query / Body from $PSBoundParameters
        v
Invoke-GitHubRequest            (Public/Core, the single request engine, also public)
        |  Private helpers: Resolve-GitHubRequestPath, ConvertTo-GitHubQueryString,
        |  Get-GitHubAuthorizationHeader, Send-GitHubHttpRequest, Update-GitHubLastResponse,
        |  Get-GitHubLinkHeader, Wait-GitHubRetry, ConvertFrom-GitHubResponse, New-GitHubErrorRecord
        v
System.Net.Http.HttpClient      (one shared client, Send-GitHubHttpRequest never throws on an HTTP status)

Layout

Path Purpose
Celerium.GitHub/Celerium.GitHub.psd1 Manifest. RootModule, version 2.0.0, PowerShell 5.1+, explicit generated FunctionsToExport and AliasesToExport, no NestedModules
Celerium.GitHub/Celerium.GitHub.psm1 Source loader: dot-sources Private then Public. Not used by the built module
Celerium.GitHub/Private Request engine helpers and module state, not exported
Celerium.GitHub/Public/Core Hand written commands: API key, base uri, settings, Get-GitHubLastResponse, Invoke-GitHubRequest
Celerium.GitHub/Public/<Category> Generated, one file per operation. Category is the PascalCase of the x-github.category of the spec
build Prerequisites, spec download and comparison, generator, module build, tests runner, documentation, publishing
docs GitHub Pages (just-the-docs), the spec, endpoints.csv, generated documentation
tests Pester 6 tests: Private, Public, Build, Live (opt-in), quality tests
examples Runnable examples that are validated by the tests

Module state lives in $Script: variables (no globals): the stored token as a SecureString, base and upload uri, API version (2026-03-10), user agent, retry and timeout settings, and the metadata of the last response.

Request flow

  1. A generated function binds its parameters. Path parameters are mandatory, required query parameters are mandatory, and every property of the JSON request body is a typed parameter. -Body carries a raw body, bound parameters override the same key
  2. The function maps only the bound parameters to the spec names with small maps ($PathMap, $QueryMap, $BodyMap) and calls Invoke-GitHubRequest -Method -Path '/repos/{owner}/{repo}' -PathParameters -Query -Body. Writes first call ShouldProcess
  3. Resolve-GitHubRequestPath substitutes the {placeholders}, escaping each path segment, and ConvertTo-GitHubQueryString builds an RFC 3986 query string (booleans as true/false, dates as UTC, arrays as repeated keys)
  4. Headers are added: Accept: application/vnd.github+json, X-GitHub-Api-Version, User-Agent, and Authorization: Bearer <token> (stored key, then GITHUB_TOKEN, then GH_TOKEN). The token is never logged; debug output redacts it
  5. Send-GitHubHttpRequest sends the request. It is the one mock seam of the unit tests
  6. The response metadata and the x-ratelimit-* headers are recorded (Get-GitHubLastResponse)
  7. Redirects are followed manually (max 5). The Authorization header is dropped when the redirect goes to another host
  8. Rate limits: a 403 or 429 with x-ratelimit-remaining: 0 waits until the reset, a Retry-After header waits that long, and a secondary limit message without headers waits 60 seconds, all capped by MaxRateLimitWaitSeconds and MaxRetryCount. 500, 502, 503, 504 and connection failures are retried with exponential backoff, GET only
  9. The body is converted: JSON becomes objects (arrays are streamed item by item), text becomes a string, everything else a byte[] (or a file with -OutFile)
  10. With -AllResults the Link: rel="next" url is followed (same host only) and items are streamed page by page
  11. A failure becomes an error record with the id GitHubApi.<status>, a matching category, and a TargetObject with StatusCode, Method, Uri, Message, DocumentationUrl, Errors, and RequestId

Naming algorithm (generator)

The name is built from the spec operationId (prefix/action):

  1. PrefixWord is the singular PascalCase of the prefix with overrides (repos is Repository, pulls is PullRequest, orgs is Organization, codes-of-conduct is CodeOfConduct, rate-limit is RateLimit). A list of prefixes stays as it is (actions, billing, copilot, git, markdown, meta, search, activity, …)
  2. One leading verb is removed from the action by HTTP method: GET get/list, POST create, PUT create-or-update/set/update, PATCH update/set, DELETE delete/remove. Other verbs stay in the noun
  3. Repeat collapse: when the first word(s) of the remaining action equal the PrefixWord (case-insensitive, the last word compared as singular so actions/action and classroom/classrooms match) the repeat is dropped (actions/get-actions-cache-usage gives ActionsCacheUsage, not ActionsActionsCacheUsage; oidc/create-oidc-custom-... gives OidcCustom...). If the collapsed name collides with another name, the operation keeps its un-collapsed name and the generator warns
  4. Verb-GitHub<PrefixWord><PascalCase(rest)> where the verb is Get (GET), New (POST), Set (PATCH, PUT), or Remove (DELETE)
  5. Collisions: a get/list pair gets a List suffix on the list operation (Get-GitHubIssueList), others are resolved by an explicit override table. The generator fails when a name or alias is duplicated or collides with a Core command
  6. The alias is Get-GH + the verb when it is not Get + the noun without GitHub (Get-GHRepository, Get-GHNewRepository, Get-GHSetRepository, Get-GHRemoveRepository)

Examples: repos/get is Get-GitHubRepository, repos/update is Set-GitHubRepository, repos/delete is Remove-GitHubRepository, repos/create-for-authenticated-user is New-GitHubRepositoryForAuthenticatedUser, issues/create is New-GitHubIssue, rate-limit/get is Get-GitHubRateLimit.

The complete mapping is the Tracking CSV (docs/endpoints.csv): category, endpoint, method, function, alias, operation id, deprecated flag, notes, and whether the endpoint was seen in the public documentation.

How to regenerate

./build/Get-GitHubSpec.ps1                  # only to move to another spec file / refresh the pinned one
./build/New-PublicFunctions.ps1             # rewrites Public/<Category>, FunctionsToExport/AliasesToExport, docs/endpoints.csv
./build/Test-EndpointCoverage.ps1           # CSV and manifest agree with the spec
./build/Invoke-HelpContent.ps1              # docs/site, docs/index.md, docs/TrackingCSV.md

The generator is idempotent (a second run changes nothing), writes UTF-8 without BOM and LF, and moves files of removed operations to build/Archive (never deletes). CI regenerates and runs git diff --exit-code so hand edits and stale output are caught.

Documentation pipeline

build/Invoke-HelpContent.ps1 loads the source module and runs Microsoft.PowerShell.PlatyPS 1.0.3 for every exported command (about 30 ms each, about a minute for all commands). It writes docs/site/<Category>/<Command>.md with just-the-docs front matter, one index.md per category, docs/site/index.md, the home page (a copy of the README), and docs/TrackingCSV.md. Output has no dates, so unchanged code gives a clean git diff. Command pages are nav_excluded (a 1,300 entry sidebar would be rendered into every page); they are reached through the category pages, breadcrumbs, and the search.

The Documentation workflow regenerates the docs on every merge to main, commits changes, builds the site with Jekyll and deploys it to GitHub Pages. Use Settings, Pages, Source: GitHub Actions.

build/Compare-GitHubSpec.ps1 crawls docs.github.com (/api/pagelist and /api/article/body) politely and sequentially, caches pages in build/Cache, and writes docs/DocumentationEndpoints.csv and EndpointDiscrepancies. The spec is the source of truth; the crawl only tells us when the spec and the documentation disagree. The weekly Spec check workflow runs it; the normal CI never needs the network for validation.

Build and release

build/Invoke-ModuleBuild.ps1 builds build/Celerium.GitHub/<Version> with ModuleBuilder: one psm1 (Private files first, then Public) and the manifest. The 14 MB OpenAPI spec is not shipped, the module never reads it at runtime. Tags vX.Y.Z trigger the Release workflow: the tag must match the manifest version, the built module is tested, a GitHub release is created, and the module is published to the PowerShell Gallery (secret PSGALLERY_API_KEY).

Tests

Unit tests mock Send-GitHubHttpRequest, so no network and no token are needed. Large suites over the ~1,300 commands are aggregated (one test per rule that lists the offenders) so Windows PowerShell 5.1 finishes in reasonable time. Tags: Live (opt-in), Build, Quality.