vcsclient

package
v0.0.0-...-a6d3b49 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2015 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package vcsclient is a generated protocol buffer package.

It is generated from these files:

vcsclient.proto

It has these top-level messages:

FileRange
GetFileOptions
TreeEntry

Index

Constants

View Source
const (
	// Route names
	RouteRepo                   = "vcs:repo"
	RouteRepoBlameFile          = "vcs:repo.blame-file"
	RouteRepoBranch             = "vcs:repo.branch"
	RouteRepoBranches           = "vcs:repo.branches"
	RouteRepoCommit             = "vcs:repo.commit"
	RouteRepoCommits            = "vcs:repo.commits"
	RouteRepoCommitters         = "vcs:repo.committers"
	RouteRepoCreateOrUpdate     = "vcs:repo.create-or-update"
	RouteRepoDiff               = "vcs:repo.diff"
	RouteRepoCrossRepoDiff      = "vcs:repo.cross-repo-diff"
	RouteRepoMergeBase          = "vcs:repo.merge-base"
	RouteRepoCrossRepoMergeBase = "vcs:repo.cross-repo-merge-base"
	RouteRepoRevision           = "vcs:repo.rev"
	RouteRepoSearch             = "vcs:repo.search"
	RouteRepoTag                = "vcs:repo.tag"
	RouteRepoTags               = "vcs:repo.tags"
	RouteRepoTreeEntry          = "vcs:repo.tree-entry"
	RouteRoot                   = "vcs:root"
)
View Source
const TotalCommitsHeader = "x-vcsstore-total-commits"

TotalCommitsHeader is the name of the HTTP header that contains the total number of commits in a call to Commits.

Variables

View Source
var ErrRepoNotExist = errors.New("repository does not exist on remote server")

Functions

func CheckResponse

func CheckResponse(r *http.Response, redirectOK bool) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range (and the 300 range if redirectOK is true). API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

func GetFile

func GetFile(o RepositoryOpener, repoPath string, at vcs.CommitID, path string) ([]byte, os.FileInfo, error)

GetFile gets a file from the repository's tree at a specific commit. If the path does not refer to a file, a non-nil error is returned.

func IsHTTPErrorCode

func IsHTTPErrorCode(err error, statusCode int) bool

func IsRepoNotExist

func IsRepoNotExist(err error) bool

Types

type Client

type Client struct {
	// Base URL for API requests, which should have a trailing slash.
	BaseURL *url.URL

	// User agent used for HTTP requests to the vcsstore API.
	UserAgent string
	// contains filtered or unexported fields
}

A Client communicates with the vcsstore API.

func New

func New(base *url.URL, httpClient *http.Client) *Client

New returns a new vcsstore API client that communicates with an HTTP server at the base URL. If httpClient is nil, http.DefaultClient is used.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) GitTransport

func (c *Client) GitTransport(repoPath string) (git.GitTransport, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) Repository

func (c *Client) Repository(repoPath string) (vcs.Repository, error)

type CloneInfo

type CloneInfo struct {
	// VCS is the type of VCS (e.g., "git")
	VCS string

	// CloneURL is the remote URL from which to clone.
	CloneURL string

	// Additional options
	vcs.RemoteOpts
}

CloneInfo is the information needed to clone a repository.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response `json:",omitempty"` // HTTP response that caused this error
	Message  string         // error message
}

An ErrorResponse reports errors caused by an API request.

func (*ErrorResponse) Description

func (r *ErrorResponse) Description() string

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

func (*ErrorResponse) HTTPStatusCode

func (r *ErrorResponse) HTTPStatusCode() int

type FileGetter

type FileGetter interface {
	GetFileWithOptions(path string, opt GetFileOptions) (*FileWithRange, error)
}

A FileGetter is a repository FileSystem that can get files with extended range options (GetFileWithOptions).

It's generally more efficient to use the client's implementation of the GetFileWithOptions method instead of calling the vcsclient.GetFileWithOptions func because the former causes only the requested range to be sent over the network, while the latter requests the whole file and narrows the range on the client side.

type FileRange

type FileRange struct {
	// start of line range
	StartLine int64 `protobuf:"varint,1,opt,name=start_line,proto3" json:"start_line,omitempty" url:",omitempty"`
	// end of line range
	EndLine int64 `protobuf:"varint,2,opt,name=end_line,proto3" json:"end_line,omitempty" url:",omitempty"`
	// start of byte range
	StartByte int64 `protobuf:"varint,3,opt,name=start_byte,proto3" json:"start_byte,omitempty" url:",omitempty"`
	// end of byte range
	EndByte int64 `protobuf:"varint,4,opt,name=end_byte,proto3" json:"end_byte,omitempty" url:",omitempty"`
}

FileRange is a line and byte range in a file.

func ComputeFileRange

func ComputeFileRange(data []byte, opt GetFileOptions) (*FileRange, *fileset.File, error)

ComputeFileRange determines the actual file range according to the input range parameter. For example, if input has a line range set, the returned FileRange will contain the byte range that corresponds to the input line range.

func (*FileRange) ProtoMessage

func (*FileRange) ProtoMessage()

func (*FileRange) Reset

func (m *FileRange) Reset()

func (*FileRange) String

func (m *FileRange) String() string

type FileSystem

type FileSystem interface {
	vfs.FileSystem
	Get(path string) (*TreeEntry, error)
}

type FileWithRange

type FileWithRange struct {
	*TreeEntry
	FileRange // range of actual returned tree entry contents within file
}

FileWithRange is returned by GetFileWithOptions and includes the returned file's TreeEntry as well as the actual range of lines and bytes returned (based on the GetFileOptions parameters). That is, if Start/EndLine are set in GetFileOptions, this struct's Start/EndByte will be set to the actual start and end bytes of those specified lines, and so on for the other fields in GetFileOptions.

func GetFileWithOptions

func GetFileWithOptions(fs vfs.FileSystem, path string, opt GetFileOptions) (*FileWithRange, error)

GetFileWithOptions gets a file and observes the options specified in opt. If fs implements FileGetter, fs.GetFileWithOptions is called; otherwise the options are applied on the client side after fetching the whole file.

type GetFileOptions

type GetFileOptions struct {
	// line or byte range to fetch (can't set both line *and* byte range)
	FileRange `protobuf:"bytes,1,opt,name=file_range,embedded=file_range" json:"file_range"`
	// EntireFile is whether the entire file contents should be returned. If true,
	// Start/EndLine and Start/EndBytes are ignored.
	EntireFile bool `protobuf:"varint,2,opt,name=entire_file,proto3" json:"entire_file,omitempty" url:",omitempty"`
	// ExpandContextLines is how many lines of additional output context to include (if
	// Start/EndLine and Start/EndBytes are specified). For example, specifying 2 will
	// expand the range to include 2 full lines before the beginning and 2 full lines
	// after the end of the range specified by Start/EndLine and Start/EndBytes.
	ExpandContextLines int32 `protobuf:"varint,3,opt,name=expand_context_lines,proto3" json:"expand_context_lines,omitempty" url:",omitempty"`
	// FullLines is whether a range that includes partial lines should be extended to
	// the nearest line boundaries on both sides. It is only valid if StartByte and
	// EndByte are specified.
	FullLines bool `protobuf:"varint,4,opt,name=full_lines,proto3" json:"full_lines,omitempty" url:",omitempty"`
	// Recursive only applies if the returned entry is a directory. It will
	// return the full file tree of the host repository, recursing into all
	// sub-directories.
	Recursive bool `protobuf:"varint,5,opt,name=recursive,proto3" json:"recursive,omitempty" url:",omitempty"`
	// RecurseSingleSubfolder only applies if the returned entry is a directory.
	// It will recursively find and include all sub-directories with a single sub-directory.
	RecurseSingleSubfolder bool `protobuf:"varint,6,opt,name=recurse_single_subfolder,proto3" json:"recurse_single_subfolder,omitempty" url:",omitempty"`
}

GetFileOptions specifies options for GetFileWithOptions.

func (*GetFileOptions) ProtoMessage

func (*GetFileOptions) ProtoMessage()

func (*GetFileOptions) Reset

func (m *GetFileOptions) Reset()

func (*GetFileOptions) String

func (m *GetFileOptions) String() string

type MockRepositoryOpener

type MockRepositoryOpener struct{ Return vcs.Repository }

func (MockRepositoryOpener) Repository

func (m MockRepositoryOpener) Repository(repoPath string) (vcs.Repository, error)

type MockVCSStore

type MockVCSStore struct {
	Repository_   func(repoPath string) (vcs.Repository, error)
	GitTransport_ func(repoPath string) (git.GitTransport, error)
}

func (*MockVCSStore) GitTransport

func (s *MockVCSStore) GitTransport(repoPath string) (git.GitTransport, error)

func (*MockVCSStore) Repository

func (s *MockVCSStore) Repository(repoPath string) (vcs.Repository, error)

type RepoKey

type RepoKey struct {
	// URI identifies the repository, and it has the form "host/user/repo".
	// Use RepoKey.RepoKeyURI to parse URI as a RepoKeyURI.
	URI string
	VCS string
}

type RepositoryCloneUpdater

type RepositoryCloneUpdater interface {
	// CloneOrUpdate instructs the server to clone the repository so
	// it is available to the client via the API if it doesn't yet
	// exist, or update it from its default remote. The call blocks
	// until cloning finishes or fails.
	CloneOrUpdate(cloneInfo *CloneInfo) error
}

type RepositoryOpener

type RepositoryOpener interface {
	Repository(repoPath string) (vcs.Repository, error)
}

type Router

type Router muxpkg.Router

func NewRouter

func NewRouter(parent *muxpkg.Router) *Router

NewRouter creates a new router that matches and generates URLs that the HTTP handler recognizes.

func (*Router) URLTo

func (r *Router) URLTo(route string, vars ...string) *url.URL

func (*Router) URLToRepo

func (r *Router) URLToRepo(repoPath string) *url.URL

func (*Router) URLToRepoBlameFile

func (r *Router) URLToRepoBlameFile(repoPath string, path string, opt *vcs.BlameOptions) *url.URL

func (*Router) URLToRepoBranch

func (r *Router) URLToRepoBranch(repoPath string, branch string) *url.URL

func (*Router) URLToRepoBranches

func (r *Router) URLToRepoBranches(repoPath string, opt vcs.BranchesOptions) *url.URL

func (*Router) URLToRepoCommit

func (r *Router) URLToRepoCommit(repoPath string, commitID vcs.CommitID) *url.URL

func (*Router) URLToRepoCommits

func (r *Router) URLToRepoCommits(repoPath string, opt vcs.CommitsOptions) *url.URL

func (*Router) URLToRepoCommitters

func (r *Router) URLToRepoCommitters(repoPath string, opt vcs.CommittersOptions) *url.URL

func (*Router) URLToRepoCrossRepoDiff

func (r *Router) URLToRepoCrossRepoDiff(baseRepoPath string, base vcs.CommitID, headRepoPath string, head vcs.CommitID, opt *vcs.DiffOptions) *url.URL

func (*Router) URLToRepoCrossRepoMergeBase

func (r *Router) URLToRepoCrossRepoMergeBase(repoPath string, a vcs.CommitID, bRepoPath string, b vcs.CommitID) *url.URL

func (*Router) URLToRepoDiff

func (r *Router) URLToRepoDiff(repoPath string, base, head vcs.CommitID, opt *vcs.DiffOptions) *url.URL

func (*Router) URLToRepoMergeBase

func (r *Router) URLToRepoMergeBase(repoPath string, a, b vcs.CommitID) *url.URL

func (*Router) URLToRepoRevision

func (r *Router) URLToRepoRevision(repoPath string, revSpec string) *url.URL

func (*Router) URLToRepoSearch

func (r *Router) URLToRepoSearch(repoPath string, at vcs.CommitID, opt vcs.SearchOptions) *url.URL

func (*Router) URLToRepoTag

func (r *Router) URLToRepoTag(repoPath string, tag string) *url.URL

func (*Router) URLToRepoTags

func (r *Router) URLToRepoTags(repoPath string) *url.URL

func (*Router) URLToRepoTreeEntry

func (r *Router) URLToRepoTreeEntry(repoPath string, commitID vcs.CommitID, path string) *url.URL

type TreeEntriesByTypeByName

type TreeEntriesByTypeByName []*TreeEntry

func (TreeEntriesByTypeByName) Len

func (v TreeEntriesByTypeByName) Len() int

func (TreeEntriesByTypeByName) Less

func (v TreeEntriesByTypeByName) Less(i, j int) bool

func (TreeEntriesByTypeByName) Swap

func (v TreeEntriesByTypeByName) Swap(i, j int)

type TreeEntry

type TreeEntry struct {
	Name     string            `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Type     TreeEntryType     `protobuf:"varint,2,opt,name=type,proto3,enum=vcsclient.TreeEntryType" json:"type,omitempty"`
	Size     int64             `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"`
	ModTime  pbtypes.Timestamp `protobuf:"bytes,4,opt,name=mod_time" json:"mod_time"`
	Contents []byte            `protobuf:"bytes,5,opt,name=contents,proto3" json:"contents,omitempty"`
	Entries  []*TreeEntry      `protobuf:"bytes,6,rep,name=entries" json:"entries,omitempty"`
}

func (*TreeEntry) GetEntries

func (m *TreeEntry) GetEntries() []*TreeEntry

func (*TreeEntry) GetModTime

func (m *TreeEntry) GetModTime() pbtypes.Timestamp

func (*TreeEntry) ProtoMessage

func (*TreeEntry) ProtoMessage()

func (*TreeEntry) Reset

func (m *TreeEntry) Reset()

func (*TreeEntry) Stat

func (e *TreeEntry) Stat() (os.FileInfo, error)

Stat returns the FileInfo structure describing the tree entry.

func (*TreeEntry) String

func (m *TreeEntry) String() string

type TreeEntryType

type TreeEntryType int32
const (
	FileEntry    TreeEntryType = 0
	DirEntry     TreeEntryType = 1
	SymlinkEntry TreeEntryType = 2
)

func (TreeEntryType) String

func (x TreeEntryType) String() string

type VCSStore

type VCSStore interface {
	RepositoryOpener
	git.GitTransporter
}

Jump to

Keyboard shortcuts

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