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 ¶
- type Change
- type ChangeBranch
- type ChangeID
- type ChangeMetadata
- type Config
- type Forge
- func (f *Forge) ChangeTemplatePaths() []string
- func (*Forge) ID() string
- func (f *Forge) MarshalChangeMetadata(md forge.ChangeMetadata) (json.RawMessage, error)
- func (f *Forge) MatchURL(remoteURL string) bool
- func (f *Forge) OpenURL(ctx context.Context, remoteURL string) (forge.Repository, error)
- func (f *Forge) UnmarshalChangeMetadata(data json.RawMessage) (forge.ChangeMetadata, error)
- type MergeChangeRequest
- type ShamHub
- func (sh *ShamHub) APIURL() string
- func (sh *ShamHub) Close() error
- func (sh *ShamHub) GitRoot() string
- func (sh *ShamHub) GitURL() string
- func (sh *ShamHub) ListChanges() ([]*Change, error)
- func (sh *ShamHub) MergeChange(req MergeChangeRequest) error
- func (sh *ShamHub) NewRepository(owner, repo string) (string, error)
- func (sh *ShamHub) RepoURL(owner, repo string) string
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 ¶
ChangeBranch is a branch in a change proposal.
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 ¶
ChangeTemplatePaths reports the case-insensitive paths at which it's possible to define change templates in the repository.
func (*Forge) MarshalChangeMetadata ¶
func (f *Forge) MarshalChangeMetadata(md forge.ChangeMetadata) (json.RawMessage, error)
MarshalChangeMetadata marshals the given change metadata to JSON.
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 ¶
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 ¶
APIURL returns the URL to which API requests should be sent. Configure the shamhub.Forge to use this as the API URL.
func (*ShamHub) GitURL ¶
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 ¶
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 ¶
NewRepository creates a new Git repository with the given owner and repo name and returns the URL to the repository.