shamhub

package
v0.1.0-beta5 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package shamhub implements a fake GitHub-like Forge.

It stores Git repositories in a temporary directory, and provides a REST-like API for interacting with them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	Number int    `json:"number"`
	URL    string `json:"html_url"`

	Draft  bool   `json:"draft,omitempty"`
	State  string `json:"state"`
	Merged bool   `json:"merged,omitempty"`

	Subject string `json:"title"`
	Body    string `json:"body"`

	Base *ChangeBranch `json:"base"`
	Head *ChangeBranch `json:"head"`
}

Change is a change proposal against a repository.

type ChangeBranch

type ChangeBranch struct {
	Name string `json:"ref"`
	Hash string `json:"sha"`
}

ChangeBranch is a branch in a change proposal.

type ChangeID

type ChangeID int

ChangeID is a unique identifier for a change on a ShamHub server.

func (ChangeID) String

func (id ChangeID) String() string

type ChangeMetadata

type ChangeMetadata struct {
	Number int `json:"number"`
}

ChangeMetadata records the metadata for a change on a ShamHub server.

func (*ChangeMetadata) ChangeID

func (m *ChangeMetadata) ChangeID() forge.ChangeID

ChangeID reports the change ID of the change.

func (*ChangeMetadata) ForgeID

func (*ChangeMetadata) ForgeID() string

ForgeID reports the forge ID that owns this metadata.

type Config

type Config struct {
	// Git is the path to the git binary.
	// If not set, we'll look for it in the PATH.
	Git string

	Log *log.Logger
}

Config configures a ShamHub server.

type Forge

type Forge struct {
	// BaseURL is the base URL for Git repositories
	// hosted on the ShamHub server.
	// URLs under this must implement the Git HTTP protocol.
	URL string

	// APIURL is the base URL for the ShamHub API.
	APIURL string

	// Log is the logger to use for logging.
	Log *log.Logger
}

Forge provides an implementation of forge.Forge backed by a ShamHub server.

func (*Forge) ChangeTemplatePaths

func (f *Forge) ChangeTemplatePaths() []string

ChangeTemplatePaths reports the case-insensitive paths at which it's possible to define change templates in the repository.

func (*Forge) ID

func (*Forge) ID() string

ID reports a unique identifier for this forge.

func (*Forge) MarshalChangeMetadata

func (f *Forge) MarshalChangeMetadata(md forge.ChangeMetadata) (json.RawMessage, error)

MarshalChangeMetadata marshals the given change metadata to JSON.

func (*Forge) MatchURL

func (f *Forge) MatchURL(remoteURL string) bool

MatchURL reports whether the given URL is a ShamHub URL.

func (*Forge) OpenURL

func (f *Forge) OpenURL(ctx context.Context, remoteURL string) (forge.Repository, error)

OpenURL opens a repository hosted on the forge with the given remote URL.

func (*Forge) UnmarshalChangeMetadata

func (f *Forge) UnmarshalChangeMetadata(data json.RawMessage) (forge.ChangeMetadata, error)

UnmarshalChangeMetadata unmarshals the given JSON data to change metadata.

type MergeChangeRequest

type MergeChangeRequest struct {
	Owner, Repo string
	Number      int

	// Optional fields:
	Time                          time.Time
	CommitterName, CommitterEmail string
}

MergeChangeRequest is a request to merge an open change proposed against this forge.

type ShamHub

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

ShamHub is a fake GitHub-like Forge. The ShamHub type provides control of the forge, with direct access to Git repositories and change proposals.

It provides two HTTP endpoints: one for the API server implementing the Forge API, and one for the Git server implementing the Git HTTP protocol. Note that the HTTP API provided by ShamHub is not the same as the GitHub API.

func New

func New(cfg Config) (*ShamHub, error)

New creates a new ShamHub server and returns an ShamHub to control it. The server should be closed with the Close method when done.

func (*ShamHub) APIURL

func (sh *ShamHub) APIURL() string

APIURL returns the URL to which API requests should be sent. Configure the shamhub.Forge to use this as the API URL.

func (*ShamHub) Close

func (sh *ShamHub) Close() error

Close closes the ShamHub server.

func (*ShamHub) GitRoot

func (sh *ShamHub) GitRoot() string

GitRoot returns the path to the root directory of the Git repositories.

func (*ShamHub) GitURL

func (sh *ShamHub) GitURL() string

GitURL returns the URL for the Git HTTP server. Append <owner>/<repo>.git to these to get the Git remote. Configure the shamhub.Forge to use this as the Base URL.

func (*ShamHub) ListChanges

func (sh *ShamHub) ListChanges() ([]*Change, error)

ListChanges reports all changes known to the forge.

func (*ShamHub) MergeChange

func (sh *ShamHub) MergeChange(req MergeChangeRequest) error

MergeChange merges an open change against this forge.

func (*ShamHub) NewRepository

func (sh *ShamHub) NewRepository(owner, repo string) (string, error)

NewRepository creates a new Git repository with the given owner and repo name and returns the URL to the repository.

func (*ShamHub) RepoURL

func (sh *ShamHub) RepoURL(owner, repo string) string

RepoURL returns the URL for the Git repository with the given owner and repo name.

Jump to

Keyboard shortcuts

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