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 AuthenticationToken
- type Change
- type ChangeBranch
- type ChangeComment
- type ChangeCommentID
- type ChangeID
- type ChangeMetadata
- type Cmd
- type Config
- type Forge
- func (f *Forge) AuthenticationFlow(ctx context.Context) (forge.AuthenticationToken, error)
- func (f *Forge) CLIPlugin() any
- func (f *Forge) ChangeTemplatePaths() []string
- func (f *Forge) ClearAuthenticationToken(stash secret.Stash) error
- func (*Forge) ID() string
- func (f *Forge) LoadAuthenticationToken(stash secret.Stash) (forge.AuthenticationToken, error)
- func (f *Forge) MarshalChangeMetadata(md forge.ChangeMetadata) (json.RawMessage, error)
- func (f *Forge) MatchURL(remoteURL string) bool
- func (f *Forge) OpenURL(ctx context.Context, token forge.AuthenticationToken, remoteURL string) (forge.Repository, error)
- func (f *Forge) SaveAuthenticationToken(stash secret.Stash, t forge.AuthenticationToken) error
- func (f *Forge) UnmarshalChangeMetadata(data json.RawMessage) (forge.ChangeMetadata, error)
- type MergeChangeRequest
- type Options
- type RejectChangeRequest
- 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) ListChangeComments() ([]*ChangeComment, error)
- 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) RegisterUser(username string) error
- func (sh *ShamHub) RejectChange(req RejectChangeRequest) 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 AuthenticationToken ¶
type AuthenticationToken struct { forge.AuthenticationToken // contains filtered or unexported fields }
AuthenticationToken defines the token returned by the ShamHub forge.
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 ChangeComment ¶
ChangeComment is a comment made on ShamHub.
type ChangeCommentID ¶
type ChangeCommentID int
ChangeCommentID uniquely identifies a comment on a change in ShamHub.
func (ChangeCommentID) String ¶
func (id ChangeCommentID) 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.
func (*ChangeMetadata) NavigationCommentID ¶ added in v0.5.0
func (m *ChangeMetadata) NavigationCommentID() forge.ChangeCommentID
NavigationCommentID reports the comment ID of the navigation comment.
func (*ChangeMetadata) SetNavigationCommentID ¶ added in v0.5.0
func (m *ChangeMetadata) SetNavigationCommentID(id forge.ChangeCommentID)
SetNavigationCommentID sets the comment ID of the navigation comment. id may be nil.
type Cmd ¶
type Cmd struct{}
Cmd implements the 'shamhub' command for test scripts.
To install it, run Cmd.Setup in your testscript.Params.Setup, and add Cmd.Run as a command in the testscript.Params.Cmds.
func (*Cmd) Run ¶
func (c *Cmd) Run(ts *testscript.TestScript, neg bool, args []string)
Run implements the 'shamhub' command for test scripts. The script MUST have called Cmd.Setup first.
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 ¶
Forge provides an implementation of forge.Forge backed by a ShamHub server.
func (*Forge) AuthenticationFlow ¶
AuthenticationFlow initiates the authentication flow for the ShamHub forge. The flow is optimized for ease of use from test scripts and is not representative of a real-world authentication flow.
To authenticate, the user must set the SHAMHUB_USERNAME environment variable before attempting to authenticate. The flow will fail if these variables are not set. The flow will also fail if the user is already authenticated.
func (*Forge) ChangeTemplatePaths ¶
ChangeTemplatePaths reports the case-insensitive paths at which it's possible to define change templates in the repository.
func (*Forge) ClearAuthenticationToken ¶
ClearAuthenticationToken removes the authentication token from the stash.
func (*Forge) LoadAuthenticationToken ¶
LoadAuthenticationToken loads the authentication token from the stash.
func (*Forge) MarshalChangeMetadata ¶
func (f *Forge) MarshalChangeMetadata(md forge.ChangeMetadata) (json.RawMessage, error)
MarshalChangeMetadata marshals the given change metadata to JSON.
func (*Forge) OpenURL ¶
func (f *Forge) OpenURL(ctx context.Context, token forge.AuthenticationToken, remoteURL string) (forge.Repository, error)
OpenURL opens a repository hosted on the forge with the given remote URL.
func (*Forge) SaveAuthenticationToken ¶
SaveAuthenticationToken saves the given authentication token to the stash.
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
// DeleteBranch indicates that the merged branch
// should be deleted after the merge.
DeleteBranch bool
}
MergeChangeRequest is a request to merge an open change proposed against this forge.
type Options ¶
type Options struct { // URL is the base URL for Git repositories // hosted on the ShamHub server. // URLs under this must implement the Git HTTP protocol. URL string `name:"shamhub-url" hidden:"" env:"SHAMHUB_URL" help:"Base URL for ShamHub requests"` // APIURL is the base URL for the ShamHub API. APIURL string `name:"shamhub-api-url" hidden:"" env:"SHAMHUB_API_URL" help:"Base URL for ShamHub API requests"` }
Options defines CLI options for the ShamHub forge.
type RejectChangeRequest ¶ added in v0.6.0
RejectChangeRequest is a request to reject a change.
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) ListChangeComments ¶
func (sh *ShamHub) ListChangeComments() ([]*ChangeComment, error)
ListChangeComments returns all comments on all changes in ShamHub.
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.
func (*ShamHub) RegisterUser ¶
RegisterUser registers a new user against the Forge with the given username and password.
func (*ShamHub) RejectChange ¶ added in v0.6.0
func (sh *ShamHub) RejectChange(req RejectChangeRequest) error
RejectChange closes a CR without merging it.