browse

package
v0.1.72 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

README

Git browsing

browse.Service resolves configured connections and repositories for read-only UI discovery. It lists redacted connections, repositories, refs, commit pages, files, pipelines and executions. ReadFile requires a full commit SHA and a repository-relative regular-file path; file discovery returns that SHA alongside the paths. Credentials stay in the server-side resolver.

Construct a service with browse.Options: Catalog lists configured connection models, Resolve hydrates the selected connection's credential references, and CacheDir stores shared bare Git mirrors. Provider connections accept only repositories returned by that provider's catalog. A plain Git connection pins its repository and rejects a separate repo parameter.

Mount httpapi.API.Handler(operation) under your application's prefix. httpapi.New requires Authorize and Service callbacks; authorization runs before input parsing or credential resolution. Supported operations are exposed by httpapi.Operations. Call httpapi.AddOpenAPI(spec, prefix) to document the same contract.

api, err := httpapi.New(httpapi.Options{
    Authorize: authorizeGitRead,
    Service: resolveGitBrowser,
})
if err != nil {
    return err
}
for _, operation := range httpapi.Operations {
    mux.HandleFunc("GET /api/git/"+operation, api.Handler(operation))
}

connection names a configured connection. repo identifies the selected provider repository. ref selects a branch, tag or full SHA. extension may repeat to restrict file discovery, for example .xlsx. Commit, pipeline and execution endpoints accept limit (1–100) and opaque cursor values returned as nextCursor. Execution requests additionally require pipeline, with optional branch. Commit cursors pin the first page's SHA so later pages remain stable if a branch moves.

Azure DevOps build definitions/builds and GitHub Actions workflows/runs implement git.PipelineProvider, an optional capability obtained through git.PipelineAPI. Other providers return git.ErrPipelinesUnsupported. Execution metadata retains provider status/result, source branch, full SHA, author, timestamp and stable run ID. Browsing never starts a pipeline or modifies repository state.

Run the focused provider, service and HTTP contracts with go test ./git/....

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid           = errors.New("invalid git source")
	ErrUnknownConnection = errors.New("unknown git connection")
)

Functions

func FindRepository added in v0.1.72

func FindRepository(options RepositoryLookup) (git.RepositoryInfo, error)

func IsGitType

func IsGitType(kind string) bool

Types

type CacheAction added in v0.1.72

type CacheAction struct {
	Owner      string `json:"owner,omitempty"`
	Connection string `json:"connection,omitempty"`
	Repo       string `json:"repo,omitempty"`
}

CacheAction names what a cache action applies to: Owner (a cache key) for prune and evict; Connection and Repo, plus an optional Owner, for rebind.

type CacheInventory added in v0.1.72

type CacheInventory struct {
	Entries          []CacheRepository `json:"entries"`
	ConnectionErrors map[string]string `json:"connectionErrors,omitempty"`
}

CacheInventory is every git cache entry. ConnectionErrors names the catalog connections whose repositories could not be listed, so entries they serve show no connection.

type CacheRepository added in v0.1.72

type CacheRepository struct {
	git.CacheEntry
	Connection string `json:"connection,omitempty"`
	Repo       string `json:"repo,omitempty"`
}

CacheRepository is a git cache entry with the catalog connection and repository it caches. Connection is empty when no catalog connection serves the entry; Repo is empty for a connection pinned to one repository.

type Commit

type Commit struct {
	SHA     string `json:"sha"`
	Subject string `json:"subject"`
	Author  string `json:"author"`
	Date    string `json:"date"`
}

type Connection

type Connection struct {
	Name string `json:"name"`
	Type string `json:"type"`
	URL  string `json:"url,omitempty"`
}

type Files

type Files struct {
	SHA   string   `json:"sha"`
	Paths []string `json:"paths"`
}

type Opened added in v0.1.72

type Opened struct {
	Client     *git.Client
	Repository *git.Repository
	Name       string
	Info       git.RepositoryInfo
}

type Options

type Options struct {
	Catalog     func(context.Context) ([]models.Connection, error)
	Resolve     func(context.Context, string) (models.Connection, error)
	CacheDir    string
	PinTTL      time.Duration
	Client      func(context.Context, string) (*git.Client, models.Connection, error)
	ClientScope func(context.Context) (string, error)
}

Options configures New. PinTTL is how long a commit pin survives without a read when CachePrune prunes a mirror (prune is refused without one).

type Ref

type Ref struct {
	Name string `json:"name"`
	SHA  string `json:"sha"`
}

type Refs

type Refs struct {
	Branches []Ref `json:"branches"`
	Tags     []Ref `json:"tags"`
	Head     *Ref  `json:"head"`
}

type Repository

type Repository struct {
	Name          string `json:"name"`
	FullName      string `json:"fullName"`
	Namespace     string `json:"namespace,omitempty"`
	CloneURL      string `json:"cloneUrl,omitempty"`
	WebURL        string `json:"webUrl,omitempty"`
	DefaultBranch string `json:"defaultBranch,omitempty"`
	Private       bool   `json:"private,omitempty"`
	Archived      bool   `json:"archived,omitempty"`
}

type RepositoryLookup added in v0.1.72

type RepositoryLookup struct {
	Name         string
	Connection   string
	Repositories []git.RepositoryInfo
}

type Request

type Request struct {
	Connection string   `json:"connection"`
	Repo       string   `json:"repo,omitempty"`
	Ref        string   `json:"ref,omitempty"`
	Path       string   `json:"path,omitempty"`
	Pipeline   string   `json:"pipeline,omitempty"`
	Branch     string   `json:"branch,omitempty"`
	Cursor     string   `json:"cursor,omitempty"`
	Limit      int      `json:"limit,omitempty"`
	Extensions []string `json:"extensions,omitempty"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(options Options) (*Service, error)

func (*Service) Cache added in v0.1.72

func (s *Service) Cache(ctx context.Context) (CacheInventory, error)

Cache describes the git cache, joined to the catalog's repositories.

func (*Service) CacheEvict added in v0.1.72

func (s *Service) CacheEvict(ctx context.Context, action CacheAction) (git.EvictResult, error)

CacheEvict deletes the owner mirror; it and its dependents clone again on their next read.

func (*Service) CacheOwners added in v0.1.72

func (s *Service) CacheOwners(ctx context.Context, request Request) ([]git.SharedOwner, error)

CacheOwners ranks the mirrors the request's repository could bind to.

func (*Service) CachePrune added in v0.1.72

func (s *Service) CachePrune(ctx context.Context, action CacheAction) (git.CacheEntry, error)

CachePrune expires the owner mirror's unused pins and garbage-collects it, returning its refreshed entry.

func (*Service) CacheRebind added in v0.1.72

func (s *Service) CacheRebind(ctx context.Context, action CacheAction) (git.RebindResult, error)

CacheRebind binds the action's repository to action.Owner, or to the best shared owner when Owner is empty.

func (*Service) Commits

func (s *Service) Commits(ctx context.Context, request Request) (git.Page[Commit], error)

func (*Service) Connections

func (s *Service) Connections(ctx context.Context) ([]Connection, error)

func (*Service) Executions

func (s *Service) Executions(ctx context.Context, request Request) (git.Page[git.PipelineExecution], error)

func (*Service) Files

func (s *Service) Files(ctx context.Context, request Request) (Files, error)

func (*Service) Open added in v0.1.72

func (s *Service) Open(ctx context.Context, request Request) (*Opened, error)

func (*Service) Pipelines

func (s *Service) Pipelines(ctx context.Context, request Request) (git.Page[git.Pipeline], error)

func (*Service) ReadFile

func (s *Service) ReadFile(ctx context.Context, request Request) ([]byte, error)

func (*Service) Refs

func (s *Service) Refs(ctx context.Context, request Request) (Refs, error)

func (*Service) RemoteRefs added in v0.1.72

func (s *Service) RemoteRefs(ctx context.Context, repo *git.Repository) (git.RemoteRefs, error)

func (*Service) Repositories

func (s *Service) Repositories(ctx context.Context, request Request) ([]Repository, error)

func (*Service) ResolveRef added in v0.1.72

func (s *Service) ResolveRef(ctx context.Context, repo *git.Repository, name string) (git.Ref, error)

Jump to

Keyboard shortcuts

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