Help us shape the future of Go! Take the 2026 Go Developer Survey

browse

package
v0.1.62 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 14 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 IsGitType

func IsGitType(kind string) bool

Types

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 Options

type Options struct {
	Catalog  func(context.Context) ([]models.Connection, error)
	Resolve  func(context.Context, string) (models.Connection, error)
	CacheDir string
}

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 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) 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) 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) Repositories

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

Jump to

Keyboard shortcuts

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