engine

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package engine provides the core concurrency and execution logic for Corral.

Index

Examples

Constants

View Source
const StateFileName = ".corral-state.json"

StateFileName is the basename of the per-clone sidecar file Corral writes next to .git/. It records the most recent push timestamp the engine has observed for the upstream so subsequent runs can skip a no-op `git pull`.

Exported so external tooling (e.g. a future `corralctl status` command, or a user's .gitignore generator) can reference the same constant.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, opts RunOptions)

Run executes the core Corral workflow, orchestrating GitHub API fetches, legacy layout migrations, concurrent Git operations, and orphaned repository detection.

Example

ExampleRun demonstrates a complete run: clone and organise every public Go and Rust repository for an owner over SSH using shallow single-branch clones, syncing existing checkouts, reporting orphaned local repositories, and emitting a machine-readable JSON summary.

package main

import (
	"context"

	"github.com/sebastienrousseau/corral/internal/engine"
	"github.com/sebastienrousseau/corral/internal/git"
	"github.com/sebastienrousseau/corral/internal/github"
)

func main() {
	ctx := context.Background()
	engine.Run(ctx, engine.RunOptions{
		Owner:       "sebastienrousseau",
		BaseDir:     "/home/me/Code",
		Concurrency: 8,
		DoSync:      true,
		Orphans:     true,
		Protocol:    "ssh",
		Output:      engine.OutputJSON,
		Fetch: github.FetchOptions{
			Limit:            500,
			Visibility:       "public",
			IncludeLanguages: []string{"go", "rust"},
			AuthMode:         github.AuthModeAuto,
		},
		Clone: git.CloneOptions{
			SingleBranch: true,
			Depth:        1,
		},
		Sync: engine.SyncOptions{
			Force: false, // set to true to bypass cache and force pull
		},
	})
}
Example (DryRun)

ExampleRun_dryRun demonstrates previewing actions without making any changes, streaming one NDJSON record per repository.

package main

import (
	"context"

	"github.com/sebastienrousseau/corral/internal/engine"
	"github.com/sebastienrousseau/corral/internal/github"
)

func main() {
	ctx := context.Background()
	engine.Run(ctx, engine.RunOptions{
		Owner:       "sebastienrousseau",
		BaseDir:     "/home/me/Code",
		Concurrency: 1,
		DryRun:      true,
		Protocol:    "https",
		Output:      engine.OutputNDJSON,
		Fetch:       github.FetchOptions{Limit: 1000},
	})
}

Types

type Job

type Job struct {
	// Repo is the GitHub repository to be processed.
	Repo github.Repo
	// Target is the destination directory for the repository under the new layout.
	Target string
	// Legacy is the directory where the repository may exist under the old layout.
	Legacy string
}

Job encapsulates a repository to be processed along with its target directories.

type OutputFormat added in v0.0.3

type OutputFormat string

OutputFormat controls how operation results are emitted.

const (
	// OutputText emits human-readable, line-oriented progress output.
	OutputText OutputFormat = "text"
	// OutputJSON emits a single aggregated JSON document at the end of the run.
	OutputJSON OutputFormat = "json"
	// OutputNDJSON emits one JSON object per result as a stream of newline-delimited records.
	OutputNDJSON OutputFormat = "ndjson"
)

type RepoResult added in v0.0.3

type RepoResult struct {
	// RepoName is the name of the processed repository.
	RepoName string `json:"repo"`
	// Action is the outcome verb, such as CLONE, SYNC, SKIP, ERROR, or DRY-RUN.
	Action string `json:"action"`
	// Message is a human-readable description of the outcome.
	Message string `json:"message"`
	// Target is the destination directory for the repository.
	Target string `json:"target"`
	// Visibility is the repository visibility (e.g. Public or Private).
	Visibility string `json:"visibility"`
	// Language is the normalized primary language directory name.
	Language string `json:"language"`
	// DryRun indicates whether the run was performed in dry-run mode.
	DryRun bool `json:"dry_run"`
	// Protocol is the clone transport used (https or ssh).
	Protocol string `json:"protocol"`
	// ClonedURL is the URL used for cloning, if a clone was attempted.
	ClonedURL string `json:"clone_url,omitempty"`
	// SyncAttempt indicates whether a sync (pull) was attempted.
	SyncAttempt bool `json:"sync_attempt"`
}

RepoResult represents the final status of processing a repository.

type RunOptions added in v0.0.3

type RunOptions struct {
	// Owner is the GitHub user or organization whose repositories are processed.
	Owner string
	// BaseDir is the root directory under which repositories are laid out.
	BaseDir string
	// Concurrency is the number of worker goroutines processing repositories; must be >= 1.
	Concurrency int
	// DryRun, when true, reports intended actions without performing clone or pull operations.
	DryRun bool
	// Orphans, when true, enables detection of local repositories no longer present upstream.
	Orphans bool
	// Protocol selects the clone transport and must be either "https" or "ssh".
	Protocol string
	// DoSync, when true, pulls updates into existing repositories.
	DoSync bool
	// Output selects the result emission format (text, json, or ndjson).
	Output OutputFormat
	// Interactive, when true, displays an interactive selector before processing.
	Interactive bool

	// Fetch holds the options passed to the GitHub repository listing call.
	Fetch github.FetchOptions
	// Clone holds the options passed to each Git clone operation.
	Clone git.CloneOptions
	// Sync controls when an already-cloned repository is actually pulled.
	Sync SyncOptions
	// Layout specifies the templated path structure for repositories.
	Layout string
	// Version is the build version of Corral.
	Version string
}

RunOptions contains all execution controls for a run.

type Summary added in v0.0.3

type Summary struct {
	// Total is the number of repositories scheduled for processing.
	Total int `json:"total"`
	// Cloned is the number of repositories successfully cloned.
	Cloned int `json:"cloned"`
	// Synced is the number of repositories successfully synced.
	Synced int `json:"synced"`
	// Skipped is the number of repositories skipped.
	Skipped int `json:"skipped"`
	// Failed is the number of repositories that failed to process.
	Failed int `json:"failed"`
}

Summary tracks aggregate run outcomes.

type SyncOptions added in v0.0.7

type SyncOptions struct {
	// Force, when true, runs `git pull` even when the cached state shows
	// the upstream pushed_at is unchanged.
	Force bool
	// IgnoreSubmoduleFailures, when true with Clone.RecurseSubmodules, allows
	// the parent repository to update even when a submodule sync fails (e.g.
	// the submodule repo was deleted upstream or its access revoked). The
	// failure is logged as a WARN but not propagated.
	IgnoreSubmoduleFailures bool
}

SyncOptions configures the engine's per-repo sync decision. Kept separate from git.CloneOptions because forcing a sync is a corral-level policy choice, not a clone-time git flag.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL