Documentation
¶
Overview ¶
Package client holds the plugin configuration and (later) the GitHub client.
Index ¶
- Constants
- Variables
- func Discover(ctx context.Context, logger zerolog.Logger, clients *Clients, spec Spec) (map[string][]*github.Repository, error)
- func Drain[T any](ctx context.Context, seq iter.Seq2[T, error], res chan<- any) error
- func GenerateSchema() ([]byte, error)
- func IsNoAccess(err error) (status int, ok bool)
- func OrgMultiplex(meta schema.ClientMeta) []schema.ClientMeta
- func OrgRepositoryMultiplex(meta schema.ClientMeta) []schema.ClientMeta
- func RegisterTablePermission(table, permission string)
- func SkipOnNoAccess(table, permission string, notFoundIsNoAccess bool, r schema.TableResolver) schema.TableResolver
- func TablePermission(table string) (string, bool)
- func TransformWithStruct(t any, opts ...transformers.StructTransformerOption) schema.Transform
- type AppAuthSpec
- type Client
- type Clients
- type EnterpriseSettings
- type Spec
- type StateStore
- type TableOptions
- type WorkflowRunsOptions
Constants ¶
const DefaultMaxLookback = 35 * 24 * time.Hour
DefaultMaxLookback is the default max_lookback: 35 days, GitHub's maximum workflow run duration.
Variables ¶
var JSONSchema string
JSONSchema is the published JSON schema of Spec, generated by `make gen`.
var OrgColumn = schema.Column{ Name: "org", Type: arrow.BinaryTypes.String, Resolver: func(_ context.Context, meta schema.ClientMeta, r *schema.Resource, col schema.Column) error { return r.Set(col.Name, meta.(*Client).Org) }, PrimaryKey: true, }
OrgColumn is the shared "org" primary key column.
var RepositoryIDColumn = schema.Column{ Name: "repository_id", Type: arrow.PrimitiveTypes.Int64, Resolver: func(_ context.Context, meta schema.ClientMeta, r *schema.Resource, col schema.Column) error { return r.Set(col.Name, meta.(*Client).Repository.GetID()) }, PrimaryKey: true, }
RepositoryIDColumn is the shared "repository_id" primary key column.
Functions ¶
func Discover ¶
func Discover(ctx context.Context, logger zerolog.Logger, clients *Clients, spec Spec) (map[string][]*github.Repository, error)
Discover returns repositories keyed by org login as first written in the config (orgs before repos, compared case-insensitively). Every org in spec.Orgs is present in the result, with an empty non-nil slice when it has no repositories. Repositories within an org are sorted by full name, and a repository found more than once (for example under an old name or owner that GitHub redirects) is kept only once.
func Drain ¶
Drain sends every item of an iterator to the result channel and returns the first error the iterator yields, unchanged. If ctx ends while an item is being sent, it returns ctx.Err().
func GenerateSchema ¶
GenerateSchema renders the JSON schema for Spec, with a trailing newline.
func IsNoAccess ¶
IsNoAccess reports whether err means the credentials cannot read the resource, by the rule of SkipOnNoAccess with notFoundIsNoAccess true (a 403 that is not a rate limit, or a 404), and returns the HTTP status.
func OrgMultiplex ¶
func OrgMultiplex(meta schema.ClientMeta) []schema.ClientMeta
OrgMultiplex returns one client per configured organization.
func OrgRepositoryMultiplex ¶
func OrgRepositoryMultiplex(meta schema.ClientMeta) []schema.ClientMeta
OrgRepositoryMultiplex returns one client per discovered repository, ordered by org and then by full name.
func RegisterTablePermission ¶
func RegisterTablePermission(table, permission string)
RegisterTablePermission records the permission a table needs, so that documentation can be checked against the code. SkipOnNoAccess calls it when a resolver is built; a table that builds its SkipOnNoAccess wrapper only at sync time registers its permission explicitly. Registering the same table twice with the same permission is a no-op; a different permission is a programming error and panics. It does not affect syncing.
func SkipOnNoAccess ¶
func SkipOnNoAccess(table, permission string, notFoundIsNoAccess bool, r schema.TableResolver) schema.TableResolver
SkipOnNoAccess wraps r. If r fails with a GitHub 403 that is not a rate limit, or (when notFoundIsNoAccess) a 404, it returns nil and records the skip. The first skip of each (org, table, HTTP status) is logged as a warning naming the table, the permission, the status, GitHub's message (which tells a missing permission apart from, say, SAML enforcement or an IP allow list) and, for a repository table, the repository; later skips of the same (org, table, status) are logged at debug level. LogSkipSummary reports the counts. Any other error is returned unchanged.
func TablePermission ¶
TablePermission returns the permission registered for table.
func TransformWithStruct ¶
func TransformWithStruct(t any, opts ...transformers.StructTransformerOption) schema.Transform
TransformWithStruct is transformers.TransformWithStruct with this plugin's defaults: embedded structs are unwrapped and github.Timestamp fields become UTC microsecond timestamps. Caller options are applied after the defaults.
Types ¶
type AppAuthSpec ¶
type AppAuthSpec struct {
Org string `json:"org"`
AppID string `json:"app_id"`
InstallationID string `json:"installation_id"`
// Exactly one of PrivateKey and PrivateKeyPath must be set.
PrivateKey string `json:"private_key,omitempty"`
PrivateKeyPath string `json:"private_key_path,omitempty"`
}
AppAuthSpec holds the credentials of one GitHub App installation.
func (AppAuthSpec) JSONSchemaExtend ¶
func (AppAuthSpec) JSONSchemaExtend(s *jsonschema.Schema)
JSONSchemaExtend requires exactly one of the two private key forms.
type Client ¶
type Client struct {
// Org is the organization (or owner) this copy is scoped to.
Org string
// Repository is set by OrgRepositoryMultiplex.
Repository *github.Repository
// GitHub is the API client for Org.
GitHub *github.Client
// Spec is the configuration with duplicates removed and without the
// access token or private keys.
Spec Spec
// State is the incremental sync state, shared by all copies. It is never
// nil after New; State.Enabled() is false when no backend is configured.
State *StateStore
// contains filtered or unexported fields
}
Client is the object the SDK scheduler hands to every table resolver. OrgMultiplex and OrgRepositoryMultiplex return copies with Org (and Repository) set. All copies share the same underlying state.
func New ¶
New builds the clients for spec and discovers the repositories to sync. Duplicate orgs and repos are dropped first, and the Spec kept on the returned Client carries no access token or private key.
func (*Client) LogSkipSummary ¶
func (c *Client) LogSkipSummary()
LogSkipSummary logs, for each (org, table) that SkipOnNoAccess skipped more than once, one info line with the number of skips (one per repository, or per parent row for a child table), in org and table order; then, for each (org, table) with child listings dropped by ParentGone, one info line with the count.
func (*Client) ParentGone ¶
ParentGone records that one child listing of table was dropped because its parent answered 404 (the parent was deleted during the sync): no rows, no error, no warning. It logs a debug line naming the parent by parentField (such as "team_id") and parentID; LogSkipSummary reports the count per (org, table). It is safe for concurrent use.
func (*Client) WithState ¶
func (c *Client) WithState(s *StateStore) *Client
WithState replaces c's state store with s and returns c. Call it before the sync starts, so every multiplexed copy shares s.
type Clients ¶
type Clients struct {
// contains filtered or unexported fields
}
Clients holds one go-github client per organisation with its own App installation, plus the default client used for every other organisation.
func NewClients ¶
NewClients builds the clients described by spec. It makes no network calls; App installation tokens are fetched on first use. Errors never contain tokens or private keys.
type EnterpriseSettings ¶
type EnterpriseSettings struct {
BaseURL string `json:"base_url"`
UploadURL string `json:"upload_url"`
}
EnterpriseSettings points the plugin at a GitHub Enterprise Server.
func (EnterpriseSettings) JSONSchemaExtend ¶
func (EnterpriseSettings) JSONSchemaExtend(s *jsonschema.Schema)
JSONSchemaExtend requires both URLs.
type Spec ¶
type Spec struct {
// Personal access token (or other token) used to authenticate.
AccessToken string `json:"access_token,omitempty"`
// Organizations to sync.
Orgs []string `json:"orgs,omitempty"`
// Individual repositories to sync, as "owner/repo".
Repos []string `json:"repos,omitempty" jsonschema:"pattern=^[^/\\s]+/[^/\\s]+$"`
// GitHub App credentials, one entry per organization.
AppAuth []AppAuthSpec `json:"app_auth,omitempty"`
// Settings for GitHub Enterprise Server.
Enterprise *EnterpriseSettings `json:"enterprise,omitempty"`
// Number of requests the scheduler may run concurrently.
Concurrency int `json:"concurrency,omitempty" jsonschema:"minimum=1,default=1500"`
// Number of concurrent requests used while discovering repositories.
DiscoveryConcurrency int `json:"discovery_concurrency,omitempty" jsonschema:"default=1"`
// Also sync archived repositories.
IncludeArchivedRepos bool `json:"include_archived_repos,omitempty"`
// Directory used to cache HTTP responses between syncs.
LocalCachePath string `json:"local_cache_path,omitempty"`
// Per-table options.
TableOptions TableOptions `json:"table_options,omitempty"`
}
Spec is the plugin configuration. It accepts the same keys as the configuration of the GitHub plugin it replaces.
func (Spec) JSONSchemaExtend ¶
func (Spec) JSONSchemaExtend(s *jsonschema.Schema)
JSONSchemaExtend adds the cross-field constraints that struct tags cannot express. Token and app auth (and orgs and repos) are alternatives that may also be combined, matching the previous plugin's run-time behaviour.
func (*Spec) SetDefaults ¶
func (s *Spec) SetDefaults()
SetDefaults fills in the default concurrency settings.
type StateStore ¶
type StateStore struct {
// contains filtered or unexported fields
}
StateStore keeps incremental sync state for the duration of one sync. Keys are read from the backend on first use and then kept in memory; changes stay in memory until Save writes them. It is safe for concurrent use, and a nil *StateStore behaves as a disabled store that keeps nothing.
func NewStateStore ¶
func NewStateStore(backend state.Client, enabled bool) *StateStore
NewStateStore returns a store over backend. When enabled is false or backend is nil the store works in memory only and Save writes nothing.
func (*StateStore) Enabled ¶
func (s *StateStore) Enabled() bool
Enabled reports whether the store is backed by a state backend. It is false for a nil store and when no backend was configured.
func (*StateStore) Get ¶
Get returns the current value of key ("" if absent), loading it from the backend on first use.
func (*StateStore) Mutate ¶
func (s *StateStore) Mutate(ctx context.Context, key string, fn func(current string) (string, error)) error
Mutate loads key (from the backend on first use, then from memory), calls fn with the current value ("" if absent) and stores fn's result in memory, atomically per store. If fn returns an error nothing changes and the error is returned.
The store's lock is held while fn runs: fn must be quick and must not call back into the store. On a nil store fn is called with "" and its result is discarded.
type TableOptions ¶
type TableOptions struct {
WorkflowRuns WorkflowRunsOptions `json:"github_workflow_runs,omitempty"`
}
type WorkflowRunsOptions ¶
type WorkflowRunsOptions struct {
// Only sync runs created after this time: RFC3339, a date, or a relative
// value such as "14 days ago".
CreatedSince string `json:"created_since,omitempty"`
// CreatedSinceTime is set by Validate; zero when CreatedSince is empty.
CreatedSinceTime time.Time `json:"-"`
// With a state backend: unfinished runs created longer ago than this stop
// being refetched, as "<N> days" or "<N> hours".
MaxLookback string `json:"max_lookback,omitempty" jsonschema:"default=35 days"`
// MaxLookbackDuration is set by Validate: DefaultMaxLookback when
// MaxLookback is empty.
MaxLookbackDuration time.Duration `json:"-"`
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package clienttest fakes the GitHub API for tests.
|
Package clienttest fakes the GitHub API for tests. |
|
internal
|
|
|
retrywait
Package retrywait holds the test override of the waits before the retries of a transient GitHub failure.
|
Package retrywait holds the test override of the waits before the retries of a transient GitHub failure. |
|
spec
|
|
|
gen
command
Command gen writes client/schema.json from the Spec type.
|
Command gen writes client/schema.json from the Spec type. |