sourcegraph

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 6, 2015 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PersonStatAuthors            = "authors"
	PersonStatClients            = "clients"
	PersonStatOwnedRepos         = "owned-repos"
	PersonStatContributedToRepos = "contributed-to-repos"
	PersonStatDependencies       = "dependencies"
	PersonStatDependents         = "dependents"
	PersonStatDefs               = "defs"
	PersonStatExportedDefs       = "exported-defs"
)
View Source
const (
	Git = "git"
	Hg  = "hg"
)
View Source
const (
	// StatXRefs is the number of external references to any def defined in a
	// repository (i.e., references from other repositories). It is only
	// computed per-repository (and not per-repository-commit) because it is
	// not easy to determine which specific commit a ref references.
	RepoStatXRefs = "xrefs"

	// StatAuthors is the number of resolved people who contributed code to any
	// def defined in a repository (i.e., references from other
	// repositories). It is only computed per-repository-commit.
	RepoStatAuthors = "authors"

	// StatClients is the number of resolved people who have committed refs that
	// reference a def defined in the repository. It is only computed
	// per-repository (and not per-repository-commit) because it is not easy to
	// determine which specific commit a ref references.
	RepoStatClients = "clients"

	// StatDependencies is the number of repositories that the repository
	// depends on. It is only computed per-repository-commit.
	RepoStatDependencies = "dependencies"

	// StatDependents is the number of repositories containing refs to a def
	// defined in the repository. It is only computed per-repository (and not
	// per-repository-commit) because it is not easy to determine which specific
	// commit a ref references.
	RepoStatDependents = "dependents"

	// StatDefs is the number of defs defined in a repository commit. It
	// is only computed per-repository-commit (or else it would count 1 def
	// for each revision of the repository that we have processed).
	RepoStatDefs = "defs"

	// StatExportedDefs is the number of exported defs defined in a
	// repository commit. It is only computed per-repository-commit (or else it
	// would count 1 def for each revision of the repository that we have
	// processed).
	RepoStatExportedDefs = "exported-defs"
)
View Source
const DefaultPerPage = 10
View Source
const (
	ImportTaskOp = "import"
)

Build task ops.

Variables

View Source
var ErrBuildNotFound = errors.New("build not found")
View Source
var ErrForbidden = errors.New("repository is unavailable")

ErrForbidden is an error indicating that the repository can no longer be accessed due to server's refusal to serve it (possibly DMCA takedowns on github etc)

View Source
var ErrNoRepoBuild = errors.New("no suitable repo build found for revspec")

ErrNoRepoBuild indicates that no build could be found for a repo revspec.

View Source
var ErrNoScheme = errors.New("clone URL has no scheme")

ErrNoScheme is an error indicating that a clone URL contained no scheme component (e.g., "http://").

View Source
var ErrNonStandardURI = errors.New("cannot infer repository clone URL because repository host is not standard; try adding it explicitly")

ErrNotPersisted is an error indicating that repository cannot be created without an explicit clone URL, because it has a non-standard URI. It implies ErrNotPersisted.

View Source
var ErrNotExist = errors.New("repository does not exist on external host")

ErrNotExist is an error definitively indicating that no such repository exists.

View Source
var ErrNotPersisted = errors.New("repository is not persisted locally, but it might exist remotely (explicitly add it to check)")

ErrNotPersisted is an error indicating that no such repository is persisted locally. The repository might exist on a remote host, but it must be explicitly added (it will not be implicitly added via a Get call).

View Source
var ErrUserNotExist = errors.New("user does not exist")

ErrUserNotExist is an error indicating that no such user exists.

View Source
var ExternalHostTimeout = time.Second * 7

ExternalHostTimeout is the timeout for HTTP requests to external repository hosts.

View Source
var RepoStatTypes = map[RepoStatType]struct{}{RepoStatXRefs: struct{}{}, RepoStatAuthors: struct{}{}, RepoStatClients: struct{}{}, RepoStatDependencies: struct{}{}, RepoStatDependents: struct{}{}, RepoStatDefs: struct{}{}, RepoStatExportedDefs: struct{}{}}

Router is used to generate URLs for the Sourcegraph API.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) 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. 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 GetBuildDataFile

func GetBuildDataFile(s BuildDataService, file BuildDataFileSpec) (io.ReadCloser, os.FileInfo, error)

GetBuildDataFile is a helper function that calls Stat and Open on the FileSystem returned for file's RepoRevSpec. Callers are responsible for closing the file (unless an error is returned).

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func IsDefError

func IsDefError(err error) bool

func IsForbidden

func IsForbidden(err error) bool

func IsGitHubRepoURI

func IsGitHubRepoURI(repoURI string) bool

IsGitHubRepoURI returns true iff this repository is hosted on GitHub.

func IsGoogleCodeRepoURI

func IsGoogleCodeRepoURI(repoURI string) bool

IsGoogleCodeRepoURI returns true iff this repository is hosted on Google Code (code.google.com).

func IsHTTPErrorCode

func IsHTTPErrorCode(err error, statusCode int) bool

func IsNotPresent

func IsNotPresent(err error) bool

IsNotPresent returns whether err is one of ErrNotExist, ErrNotPersisted, or ErrRedirected.

func MapByURI

func MapByURI(repos []*Repo) map[string]*Repo

func ParseRepoAndCommitID

func ParseRepoAndCommitID(repoAndCommitID string) (uri, commitID string)

ParseRepoAndCommitID parses strings like "example.com/repo" and "example.com/repo@myrev".

func ResetRouter

func ResetRouter()

ResetRouter clears and reconstructs the preinitialized API router. It should be called after setting an router.ExtraConfig func but only during init time.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func TokenType

func TokenType(tok Token) string

func URL

func URL(route string, routeVars map[string]string, opt interface{}) (*url.URL, error)

URL generates a URL for the given route, route variables, and querystring options. Unless you explicitly set a Host, Scheme, and/or Port on Router, the returned URL will contain only path and querystring components (and will not be an absolute URL).

Types

type AnyToken

type AnyToken string

An AnyToken is a token that has not yet been resolved into another token type. It resolves to Term if it can't be resolved to another token type.

func (AnyToken) String

func (u AnyToken) String() string

type AugmentedDefAuthor

type AugmentedDefAuthor struct {
	Person *Person
	*DefAuthor
}

type AugmentedDefClient

type AugmentedDefClient struct {
	Person *Person
	*DefClient
}

type AugmentedDefDependent

type AugmentedDefDependent struct {
	Repo *Repo
	*DefDependent
}

type AugmentedPersonUsageByClient

type AugmentedPersonUsageByClient struct {
	Author *Person
	*PersonUsageByClient
}

type AugmentedPersonUsageOfAuthor

type AugmentedPersonUsageOfAuthor struct {
	Client *Person
	*PersonUsageOfAuthor
}

type AugmentedRepoAuthor

type AugmentedRepoAuthor struct {
	Person *Person
	*RepoAuthor
}

AugmentedRepoAuthor is a RepoAuthor with the full Person and graph.Def structs embedded.

type AugmentedRepoClient

type AugmentedRepoClient struct {
	Person *Person
	*RepoClient
}

AugmentedRepoClient is a RepoClient with the full Person and graph.Def structs embedded.

type AugmentedRepoContribution

type AugmentedRepoContribution struct {
	Repo *Repo
	*RepoContribution
}

type AugmentedRepoDependency

type AugmentedRepoDependency struct {
	Repo *Repo
	*RepoDependency
}

type AugmentedRepoDependent

type AugmentedRepoDependent struct {
	Repo *Repo
	*RepoDependent
}

type AugmentedRepoUsageByClient

type AugmentedRepoUsageByClient struct {
	DefRepo            *Repo
	*RepoUsageByClient `json:"RepoUsageByClient"`
}

AugmentedRepoUsageByClient is a RepoUsageByClient with the full Repo struct embedded.

type AugmentedRepoUsageOfAuthor

type AugmentedRepoUsageOfAuthor struct {
	Repo               *Repo
	*RepoUsageOfAuthor `json:"RepoUsageOfAuthor"`
}

AugmentedRepoUsageOfAuthor is a RepoUsageOfAuthor with the full Repo struct embedded.

type AuthorStats

type AuthorStats struct {
	AuthorshipInfo

	// DefCount is the number of defs that this author contributed (where
	// "contributed" means "committed any hunk of code to source code files").
	DefCount int `db:"def_count"`

	DefsProportion float64 `db:"defs_proportion"`

	// ExportedDefCount is the number of exported defs that this author
	// contributed (where "contributed to" means "committed any hunk of code to
	// source code files").
	ExportedDefCount int `db:"exported_def_count"`

	ExportedDefsProportion float64 `db:"exported_defs_proportion"`
}

type AuthorshipInfo

type AuthorshipInfo struct {
	AuthorEmail    string    `db:"author_email"`
	LastCommitDate time.Time `db:"last_commit_date"`

	// LastCommitID is the commit ID of the last commit that this author made to
	// the thing that this info describes.
	LastCommitID string `db:"last_commit_id"`
}

type Badge

type Badge struct {
	Name              string
	Description       string
	ImageURL          string
	UncountedImageURL string
	Markdown          string
}

func (*Badge) HTML

func (b *Badge) HTML() string

type Build

type Build struct {
	BID  int64 `json:",omitempty"`
	Repo int

	// CommitID is the full resolved commit ID to build.
	CommitID string `db:"commit_id"`

	CreatedAt   time.Time          `db:"created_at"`
	StartedAt   db_common.NullTime `db:"started_at"`
	EndedAt     db_common.NullTime `db:"ended_at"`
	HeartbeatAt db_common.NullTime `db:"heartbeat_at"`
	Success     bool               `json:",omitempty"`
	Failure     bool               `json:",omitempty"`

	// Killed is true if this build's worker didn't exit on its own
	// accord. It is generally set when no heartbeat has been received
	// within a certain interval. If Killed is true, then Failure must
	// also always be set to true. Unqueued builds are never killed
	// for lack of a heartbeat.
	Killed bool `json:",omitempty"`

	// Host is the hostname of the machine that is working on this build.
	Host string `json:",omitempty"`

	Purged bool // whether the build's data (defs/refs/etc.) has been purged

	BuildConfig

	BuildMeta

	// RepoURI is populated (as a convenience) in results by Get and List but
	// should not be set when creating builds (it will be ignored).
	RepoURI *string `db:"repo_uri" json:",omitempty"`
}

A Build represents a scheduled, completed, or failed repository analysis and import job.

A build is composed of many tasks. The worker that is responsible for a build or task determines whether a task failure causes the whole build to fail. (Keep reading to see how we determine who is responsible for a build or task.) There is no single kind of worker; currently there are 3 things that could be considered workers because they build builds or perform tasks: the builders on Sourcegraph.com, the task workers that run import tasks, and anyone who runs `src push` locally.

Each task has logs associated with it, and each task can be associated with a single source unit (or not).

Both builds and tasks have a Queue bool field. If a process creates a build or task that has Queue=true, that means that it relinquishes responsibility for it; some other queue workers (on the server, for example) will dequeue and complete it. If Queue=false, then the process that created it is responsible for completing it. The only exception to this is that after a certain timeout (on the order of 45 minutes), started but unfinished builds are marked as failed.

A build and its tasks may be queued (or not queued) independently. A build may have Queue=true and its tasks may all have Queue=false; this occurs when a build is enqueued by a user and subsequently dequeued by a builder, which creates and performs the tasks as a single process. Or a build may have Queue=false and it may have a task with Queue=true; this occurs when someone builds a project locally but wants the server to import the data (which only the server, having direct DB access, can do).

It probably wouldn't make sense to create a queued build and immediately create a queued task, since then those would be run independently (and potentially out of order) by two workers. But it could make sense to create a queued build, and then for the builder to do some work (such as analyzing a project) and then create a queued task in the same build to import the build data it produced.

Builds and tasks are simple "build"ing blocks (no pun intended) with simple behavior. As we encounter new requirements for the build system, they may evolve.

func (*Build) Spec

func (b *Build) Spec() BuildSpec

type BuildConfig

type BuildConfig struct {
	// Import is whether to import the build data into the database when the
	// build is complete. The data must be imported for Sourcegraph's web app or
	// API to use it, except that unimported build data is available through the
	// BuildData service. (TODO(sqs): BuildData isn't yet implemented.)
	Import bool

	// Queue is whether this build should be enqueued. If enqueued, any worker
	// may begin running this build. If not enqueued, it is up to the client to
	// run the build and update it accordingly.
	Queue bool

	// UseCache is whether to use cached build data files. If false, the
	// .sourcegraph-data directory will be wiped out before the build begins.
	//
	// Regardless of the value of UseCache, the build data files will be
	// uploaded to the central cache after the build ends.
	UseCache bool `db:"use_cache"`

	// Priority of the build in the queue (higher numbers mean the build is
	// dequeued sooner).
	Priority int
}

BuildConfig configures a repository build.

type BuildCreateOptions

type BuildCreateOptions struct {
	BuildConfig
	BuildMeta

	// Force creation of build. If false, the build will not be
	// created if a build for the same repository and with the same
	// BuildConfig exists. In all cases, the BuildMeta information is
	// merged with the data that is already persisted.
	//
	// TODO(bliu): test this
	Force bool
}

type BuildDataFileSpec

type BuildDataFileSpec struct {
	RepoRev RepoRevSpec
	Path    string
}

BuildDataFileSpec specifies a new or existing build data file in a repository.

func (*BuildDataFileSpec) RouteVars

func (s *BuildDataFileSpec) RouteVars() map[string]string

RouteVars returns route variables used to construct URLs to a build data file.

type BuildDataService

type BuildDataService interface {
	// FileSystem returns a virtual filesystem interface to the build
	// data for a repo at a specific commit.
	FileSystem(repo RepoRevSpec) (rwvfs.FileSystem, error)
}

BuildDataService communicates with the build data-related endpoints in the Sourcegraph API.

type BuildGetLogOptions

type BuildGetLogOptions struct {
	// MinID indicates that only log entries whose monotonically increasing ID
	// is greater than MinID should be returned.
	//
	// To "tail -f" or watch a log for updates, set each subsequent request's
	// MinID to the MaxID of the previous request.
	MinID string
}

BuildGetLogOptions specifies options for build log API methods.

type BuildGetOptions

type BuildGetOptions struct{}

type BuildListOptions

type BuildListOptions struct {
	Queued    bool `url:",omitempty"`
	Active    bool `url:",omitempty"`
	Ended     bool `url:",omitempty"`
	Succeeded bool `url:",omitempty"`
	Failed    bool `url:",omitempty"`

	Purged bool `url:",omitempty"`

	Repo     string `url:",omitempty"`
	CommitID string `url:",omitempty"`

	Sort      string `url:",omitempty"`
	Direction string `url:",omitempty"`

	ListOptions
}

type BuildMeta

type BuildMeta struct {
	// PullRepo is the RID of the repo associated with the pull
	// request that caused this build to be created. If this build was
	// not created due to a pull request, it is 0. If this build is
	// for the head commit of a PR against a different base repo,
	// PullRepo is the RID of that base repo (and PullRepo != the
	// build's Repo).
	//
	// If PullRepo is set, PullNumber must also be set.
	//
	// TODO(sqs): This assumes that a given commit is only the head
	// commit for a single PR, which is not true in general.
	PullRepo int `db:"pull_repo" json:",omitempty"`

	// PullNumber is the pull number (e.g., #123) of the pull request
	// (on PullRepo) that caused this build to be created. If this
	// build was not created due to a pull request, it is 0.
	//
	// If PullNumber is set, PullRepo must also be set.
	//
	// TODO(sqs): This assumes that a given commit is only the head
	// commit for a single PR, which is not true in general.
	PullNumber int `db:"pull_number" json:",omitempty"`
}

BuildMeta holds additional metadata about the build that is not considered by BuildCreateOptions.Force when deciding whether an existing equivalent build exists.

type BuildSpec

type BuildSpec struct {
	BID int64
}

func (BuildSpec) IDString

func (b BuildSpec) IDString() string

IDString returns a succinct string that uniquely identifies this build.

func (*BuildSpec) RouteVars

func (s *BuildSpec) RouteVars() map[string]string

type BuildTask

type BuildTask struct {
	// TaskID is the unique ID of this task. It is unique over all
	// tasks, not just tasks in the same build.
	TaskID int64 `json:",omitempty"`

	// BID is the build that this task is a part of.
	BID int64

	// UnitType is the srclib source unit type of the source unit that
	// this task is associated with.
	UnitType string `db:"unit_type" json:",omitempty"`

	// Unit is the srclib source unit name of the source unit that
	// this task is associated with.
	Unit string `json:",omitempty"`

	// Op is the srclib toolchain operation (graph, depresolve, etc.) that this
	// task performs.
	Op string `json:",omitempty"`

	// Order is the order in which this task is performed, relative to other
	// tasks in the same build. Lower-number-ordered tasks are built first.
	// Multiple tasks may have the same order.
	Order int `json:",omitempty"`

	// CreatedAt is when this task was initially created.
	CreatedAt db_common.NullTime `db:"created_at"`

	// StartedAt is when this task's execution began.
	StartedAt db_common.NullTime `db:"started_at" json:",omitempty"`

	// EndedAt is when this task's execution ended (whether because it
	// succeeded or failed).
	EndedAt db_common.NullTime `db:"ended_at" json:",omitempty"`

	// Queue is whether this task should be performed by queue task
	// remote workers on the central server. If true, then it will be
	// performed remotely. If false, it should be performed locally by
	// the process that created this task.
	//
	// For example, import tasks are queued because they are performed
	// by the remote server, not the local "src" process running on
	// the builders.
	//
	// See the documentation for Build for more discussion about
	// queued builds and tasks (and how they relate).
	Queue bool

	// Success is whether this task's execution succeeded.
	Success bool `json:",omitempty"`

	// Failure is whether this task's execution failed.
	Failure bool `json:",omitempty"`
}

A BuildTask represents an individual step of a build.

See the documentation for Build for more information about how builds and tasks relate to each other.

func (*BuildTask) Spec

func (t *BuildTask) Spec() TaskSpec

type BuildTaskListOptions

type BuildTaskListOptions struct{ ListOptions }

type BuildUpdate

type BuildUpdate struct {
	StartedAt   *time.Time
	EndedAt     *time.Time
	HeartbeatAt *time.Time
	Host        *string
	Success     *bool
	Purged      *bool
	Failure     *bool
	Killed      *bool
	Priority    *int
}

A BuildUpdate contains updated information to update on an existing build.

type BuildsService

type BuildsService interface {
	// Get fetches a build.
	Get(build BuildSpec, opt *BuildGetOptions) (*Build, Response, error)

	// List builds.
	List(opt *BuildListOptions) ([]*Build, Response, error)

	// Create a new build. The build will run asynchronously (Create does not
	// wait for it to return. To monitor the build's status, use Get.)
	Create(repoRev RepoRevSpec, opt *BuildCreateOptions) (*Build, Response, error)

	// Update updates information about a build and returns the build
	// after the update has been applied.
	Update(build BuildSpec, info BuildUpdate) (*Build, Response, error)

	// ListBuildTasks lists the tasks associated with a build.
	ListBuildTasks(build BuildSpec, opt *BuildTaskListOptions) ([]*BuildTask, Response, error)

	// CreateTasks creates tasks associated with a build and returns
	// them with their TID fields set.
	CreateTasks(build BuildSpec, tasks []*BuildTask) ([]*BuildTask, Response, error)

	// UpdateTask updates a task associated with a build.
	UpdateTask(task TaskSpec, info TaskUpdate) (*BuildTask, Response, error)

	// GetLog gets log entries associated with a build.
	GetLog(build BuildSpec, opt *BuildGetLogOptions) (*LogEntries, Response, error)

	// GetTaskLog gets log entries associated with a task.
	GetTaskLog(task TaskSpec, opt *BuildGetLogOptions) (*LogEntries, Response, error)

	// DequeueNext returns the next queued build and marks it as
	// having started (atomically). It is not considered an error if
	// there are no builds in the queue; in that case, a nil build and
	// error are returned.
	//
	// The HTTP response may contain tickets that grant the necessary
	// permissions to build and upload build data for the build's
	// repository. Call auth.SignedTicketStrings on the response's
	// HTTP response field to obtain the tickets.
	DequeueNext() (*Build, Response, error)
}

BuildsService communicates with the build-related endpoints in the Sourcegraph API.

type Checklist

type Checklist struct {
	Todo int // number of tasks to be done (unchecked)
	Done int // number of tasks that are done (checked)
}

type Client

type Client struct {
	// Services used to communicate with different parts of the Sourcegraph API.
	BuildData    BuildDataService
	Builds       BuildsService
	Deltas       DeltasService
	Issues       IssuesService
	Orgs         OrgsService
	People       PeopleService
	PullRequests PullRequestsService
	Repos        ReposService
	RepoTree     RepoTreeService
	Search       SearchService
	Units        UnitsService
	Users        UsersService
	Defs         DefsService
	Markdown     MarkdownService

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

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

A Client communicates with the Sourcegraph API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Sourcegraph API client. If httpClient is nil, http.DefaultClient is used.

func NewMockClient

func NewMockClient() *Client

NewMockClient returns a mockable Client for use in tests.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (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. If v is preserveBody, then the HTTP response body is not closed by Do; the caller is responsible for closing it.

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

func (c *Client) URL(route string, routeVars map[string]string, opt interface{}) (*url.URL, error)

URL generates the absolute URL to the named Sourcegraph API endpoint, using the specified route variables and query options.

type ClientStats

type ClientStats struct {
	AuthorshipInfo

	// DefRepo is the URI of the repository that defines defs that
	// this client referred to.
	DefRepo string `db:"def_repo"`

	// DefUnitType and DefUnit are the unit in DefRepo that defines
	// defs that this client referred to. If DefUnitType == "" and
	// DefUnit == "", then this ClientStats is an aggregate of this client's
	// refs to all units in DefRepo.
	DefUnitType nnz.String `db:"def_unit_type"`
	DefUnit     nnz.String `db:"def_unit"`

	// RefCount is the number of references this client made in this repository
	// to DefRepo.
	RefCount int `db:"ref_count"`
}

type CombinedStatus

type CombinedStatus struct {
	github.CombinedStatus
}

type Commit

type Commit struct {
	*vcs.Commit
}

type Completions

type Completions struct {
	// TokenCompletions are suggested completions for the token at the
	// raw query's InsertionPoint.
	TokenCompletions Tokens

	// ResolvedTokens is the resolution of the original query's tokens
	// used to produce the completions. It is useful for debugging.
	ResolvedTokens Tokens

	ResolveErrors   []TokenError `json:",omitempty"`
	ResolutionFatal bool         `json:",omitempty"`
}

Completions holds search query completions.

type Counter

type Counter struct {
	Name              string
	Description       string
	ImageURL          string
	UncountedImageURL string
	Markdown          string
}

func (*Counter) HTML

func (c *Counter) HTML() string

type Def

type Def struct {
	graph.Def

	Stat graph.Stats `json:",omitempty"`

	DocHTML string `json:",omitempty"`

	FmtStrings *DefFormatStrings `json:",omitempty"`
}

Def is a code def returned by the Sourcegraph API.

func (*Def) DefSpec

func (s *Def) DefSpec() DefSpec

DefSpec returns the DefSpec that specifies s.

func (*Def) RRefs

func (s *Def) RRefs() int

func (*Def) TotalExamples

func (s *Def) TotalExamples() int

func (*Def) TotalRefs

func (s *Def) TotalRefs() int

TotalRefs is the number of unique references of all kinds to s. It is computed as (xrefs + rrefs), omitting urefs to avoid double-counting references in the same repository.

The number of examples for s is usually TotalRefs() - 1, since the definition of a def counts as a ref but not an example.

func (*Def) URefs

func (s *Def) URefs() int

func (*Def) XRefs

func (s *Def) XRefs() int

type DefAuthor

type DefAuthor struct {
	UID   nnz.Int
	Email nnz.String
	DefAuthorship
}

type DefAuthorsByBytes

type DefAuthorsByBytes []*DefAuthor

func (DefAuthorsByBytes) Len

func (v DefAuthorsByBytes) Len() int

func (DefAuthorsByBytes) Less

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

func (DefAuthorsByBytes) Swap

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

type DefAuthorship

type DefAuthorship struct {
	AuthorshipInfo

	// Exported is whether the def is exported.
	Exported bool

	Bytes           int
	BytesProportion float64
}

type DefClient

type DefClient struct {
	UID   nnz.Int
	Email nnz.String

	AuthorshipInfo

	// UseCount is the number of times this person referred to the def.
	UseCount int `db:"use_count"`
}

type DefDelta

type DefDelta struct {
	Base *Def // the def in the base commit (if nil, this def was added in the head)
	Head *Def // the def in the head commit (if nil, this def was deleted in the head)
}

A DefDelta represents a single definition that was changed. It has fields for the before (Base) and after (Head) versions. If both Base and Head are non-nil, then the def was changed from base to head. Otherwise, one of the fields being nil means that the def did not exist in that revision (e.g., it was added or deleted from base to head).

func (DefDelta) Added

func (dd DefDelta) Added() bool

Added is whether this represents an added def (not present in base, present in head).

func (DefDelta) Changed

func (dd DefDelta) Changed() bool

Changed is whether this represents a changed def (present in base, present in head).

func (DefDelta) Deleted

func (dd DefDelta) Deleted() bool

Deleted is whether this represents a deleted def (present in base, not present in head).

type DefDependent

type DefDependent struct {
	FromRepo string `db:"from_repo"`
	Count    int
}

type DefFormatStrings

type DefFormatStrings struct {
	Name                 QualFormatStrings
	Type                 QualFormatStrings
	NameAndTypeSeparator string
	Language             string `json:",omitempty"`
	DefKeyword           string `json:",omitempty"`
	Kind                 string `json:",omitempty"`
}

DefFormatStrings contains the various def format strings from the srclib def formatter.

type DefGetOptions

type DefGetOptions struct {
	Doc bool `url:",omitempty"`

	// Stats is whether the Def response object should include statistics.
	Stats bool `url:",omitempty"`
}

DefGetOptions specifies options for DefsService.Get.

type DefListAuthorsOptions

type DefListAuthorsOptions struct {
	ListOptions
}

DefListAuthorsOptions specifies options for DefsService.ListAuthors.

type DefListClientsOptions

type DefListClientsOptions struct {
	ListOptions
}

DefListClientsOptions specifies options for DefsService.ListClients.

type DefListDependentsOptions

type DefListDependentsOptions struct {
	ListOptions
}

DefListDependentsOptions specifies options for DefsService.ListDependents.

type DefListExamplesOptions

type DefListExamplesOptions struct {
	Formatted bool `url:",omitempty"`

	// Filter by a specific Repo URI
	Repo string `url:",omitempty"`

	// TokenizedSource requests that the source code be returned as a tokenized data
	// structure rather than an (annotated) string.
	//
	// This is useful when the client wants to take full control of rendering and manipulating
	// the contents.
	TokenizedSource bool `url:",omitempty"`

	ListOptions
}

DefListExamplesOptions specifies options for DefsService.ListExamples.

type DefListOptions

type DefListOptions struct {
	Name string `url:",omitempty" json:",omitempty"`

	// Specifies a search query for defs. If specified, then the Sort and Direction options are ignored
	Query string `url:",omitempty" json:",omitempty"`

	// ByteStart and ByteEnd will restrict the results to only definitions that overlap with the specified
	// start and end byte offsets. This filter is only applied if both values are set.
	ByteStart, ByteEnd uint32

	// DefKeys, if set, will return the definitions that match the given DefKey
	DefKeys []*graph.DefKey

	// RepoRevs constrains the results to a set of repository
	// revisions (given by their URIs plus an optional "@" and a
	// revision specifier). For example, "repo.com/foo@revspec".
	RepoRevs []string `url:",omitempty,comma" json:",omitempty"`

	UnitType string `url:",omitempty" json:",omitempty"`
	Unit     string `url:",omitempty" json:",omitempty"`

	Path string `url:",omitempty" json:",omitempty"`

	// File, if specified, will restrict the results to only defs defined in
	// the specified file.
	File string `url:",omitempty" json:",omitempty"`

	// FilePathPrefix, if specified, will restrict the results to only defs defined in
	// files whose path is underneath the specified prefix.
	FilePathPrefix string `url:",omitempty" json:",omitempty"`

	Kinds    []string `url:",omitempty,comma" json:",omitempty"`
	Exported bool     `url:",omitempty" json:",omitempty"`
	Nonlocal bool     `url:",omitempty" json:",omitempty"`

	// IncludeTest is whether the results should include definitions in test
	// files.
	IncludeTest bool `url:",omitempty" json:",omitempty"`

	// Enhancements
	Doc   bool `url:",omitempty" json:",omitempty"`
	Stats bool `url:",omitempty" json:",omitempty"`
	Fuzzy bool `url:",omitempty" json:",omitempty"`

	// Sorting
	Sort      string `url:",omitempty" json:",omitempty"`
	Direction string `url:",omitempty" json:",omitempty"`

	// Paging
	ListOptions
}

DefListOptions specifies options for DefsService.List.

func (*DefListOptions) DefFilters

func (o *DefListOptions) DefFilters() []store.DefFilter

type DefListRefsOptions

type DefListRefsOptions struct {
	Authorship bool   `url:",omitempty"` // whether to fetch authorship info about the refs
	Repo       string `url:",omitempty"` // only fetch refs from this repository URI
	ListOptions
}

type DefListVersionsOptions

type DefListVersionsOptions struct {
	ListOptions
}

type DefSpec

type DefSpec struct {
	Repo     string
	CommitID string
	UnitType string
	Unit     string
	Path     string
}

DefSpec specifies a def.

func NewDefSpecFromDefKey

func NewDefSpecFromDefKey(key graph.DefKey) DefSpec

NewDefSpecFromDefKey returns a DefSpec that specifies the same def as the given key.

func (*DefSpec) DefKey

func (s *DefSpec) DefKey() graph.DefKey

DefKey returns the def key specified by s, using the Repo, UnitType, Unit, and Path fields of s.

func (*DefSpec) RouteVars

func (s *DefSpec) RouteVars() map[string]string

type DefsService

type DefsService interface {
	// Get fetches a def.
	Get(def DefSpec, opt *DefGetOptions) (*Def, Response, error)

	// List defs.
	List(opt *DefListOptions) ([]*Def, Response, error)

	// ListRefs lists references to def.
	ListRefs(def DefSpec, opt *DefListRefsOptions) ([]*Ref, Response, error)

	// ListExamples lists examples for def.
	ListExamples(def DefSpec, opt *DefListExamplesOptions) ([]*Example, Response, error)

	// ListExamples lists people who committed parts of def's definition.
	ListAuthors(def DefSpec, opt *DefListAuthorsOptions) ([]*AugmentedDefAuthor, Response, error)

	// ListClients lists people who use def in their code.
	ListClients(def DefSpec, opt *DefListClientsOptions) ([]*AugmentedDefClient, Response, error)

	// ListDependents lists repositories that use def in their code.
	ListDependents(def DefSpec, opt *DefListDependentsOptions) ([]*AugmentedDefDependent, Response, error)

	// ListVersions lists all available versions of a definition in
	// the various repository commits in which it has appeared.
	//
	// TODO(sqs): how to deal with renames, etc.?
	ListVersions(def DefSpec, opt *DefListVersionsOptions) ([]*Def, Response, error)
}

DefsService communicates with the def- and graph-related endpoints in the Sourcegraph API.

type Delta

type Delta struct {
	Base, Head             RepoRevSpec // base/head repo and revspec
	BaseCommit, HeadCommit *Commit     // base/head commits
	BaseRepo, HeadRepo     *Repo       // base/head repositories
	BaseBuild, HeadBuild   *Build      // base/head builds (or nil)
}

Delta represents the difference between two commits (possibly in 2 separate repositories).

func (*Delta) BaseAndHeadBuildsSuccessful

func (d *Delta) BaseAndHeadBuildsSuccessful() bool

BaseAndHeadBuildsSuccessful returns true iff both the base and head builds are present and ended successfully.

func (*Delta) DeltaSpec

func (d *Delta) DeltaSpec() DeltaSpec

type DeltaAffectedPerson

type DeltaAffectedPerson struct {
	Person // the affected person

	Defs []*Def // the defs they authored or use (the reason why they're affected)
}

DeltaAffectedPerson describes a person (registered user or committer email address) that is affected by a delta. It includes fields for the person affected as well as the defs that are the reason why we consider them to be affected.

The person's relationship to the Defs depends on what method returned this DeltaAffectedPerson. If it was returned by a method that lists authors, then the Defs are definitions that the Person committed. If it was returned by a method that lists clients (a.k.a users), then the Defs are definitions that the Person uses.

type DeltaAffectedRepo

type DeltaAffectedRepo struct {
	Repo // the affected repository

	DefRefs []*DeltaDefRefs // refs to defs that were changed/deleted
}

DeltaAffectedRepo describes a repository that is affected by a delta.

type DeltaDefRefs

type DeltaDefRefs struct {
	Def  *Def       // the changed/deleted def
	Refs []*Example // all of the parent DeltaAffectedRepo.Repo's refs to Def
}

DeltaDefRefs is used in DeltaAffectedRepo to store a single changed/deleted def and all of the repository's refs to that def.

type DeltaDefs

type DeltaDefs struct {
	Defs []*DefDelta // added/changed/deleted defs

	DiffStat diff.Stat // overall diffstat (not subject to pagination)
}

DeltaDefs describes definitions added/changed/deleted in a delta.

func (DeltaDefs) Len

func (v DeltaDefs) Len() int

func (DeltaDefs) Less

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

func (DeltaDefs) Swap

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

type DeltaDependencies

type DeltaDependencies struct {
}

DeltaDependencies describes dependencies added/changed/deleted in a delta.

type DeltaFiles

type DeltaFiles struct {
	FileDiffs []*FileDiff
	Delta     *Delta
	Stats     diff.Stat
}

DeltaFiles describes files added/changed/deleted in a delta.

func (*DeltaFiles) DiffStat

func (d *DeltaFiles) DiffStat() diff.Stat

DiffStat returns a diffstat that is the sum of all of the files' diffstats.

type DeltaFilter

type DeltaFilter struct {
	Unit     string `url:",omitempty"`
	UnitType string `url:",omitempty"`
}

DeltaFilter specifies criteria by which to filter results from DeltaListXxx methods.

func (DeltaFilter) DefFilters

func (f DeltaFilter) DefFilters() []store.DefFilter

type DeltaGetOptions

type DeltaGetOptions struct{}

DeltaGetOptions specifies options for getting a delta.

type DeltaListAffectedAuthorsOptions

type DeltaListAffectedAuthorsOptions struct {
	DeltaFilter
	ListOptions
}

DeltaListAffectedAuthorsOptions specifies options for ListAffectedAuthors.

type DeltaListAffectedClientsOptions

type DeltaListAffectedClientsOptions struct {
	DeltaFilter
	ListOptions
}

DeltaListAffectedClientsOptions specifies options for ListAffectedClients.

type DeltaListAffectedDependentsOptions

type DeltaListAffectedDependentsOptions struct {
	NotFormatted bool `url:",omitempty"`

	DeltaFilter
	ListOptions
}

DeltaListAffectedDependentsOptions specifies options for ListAffectedDependents.

type DeltaListDefsOptions

type DeltaListDefsOptions struct {
	DeltaFilter
	ListOptions
}

DeltaListDefsOptions specifies options for ListDefs.

type DeltaListDependenciesOptions

type DeltaListDependenciesOptions struct {
	DeltaFilter
	ListOptions
}

DeltaListDependenciesOptions specifies options for ListDependencies.

type DeltaListFilesOptions

type DeltaListFilesOptions struct {
	// Formatted is whether the files should have their contents
	// code-formatted (syntax-highlighted and reference-linked) if
	// they contain code.
	Formatted bool `url:",omitempty"`

	// Filter filters the list of returned files to those whose name matches Filter.
	Filter string `url:",omitempty"`

	// Tokenized, when set, will tokenize the whole source code contained in the diff,
	// returning 3 versions for each hunk: Head revision, Base revision and Hunk body.
	// For more information, see sourcegraph.Hunk.
	Tokenized bool `url:",omitempty"`

	DeltaFilter
}

DeltaListFilesOptions specifies options for ListFiles.

type DeltaListIncomingOptions

type DeltaListIncomingOptions struct {
	DeltaFilter
	ListOptions
}

DeltaListIncomingOptions specifies options for ListIncoming.

type DeltaListReviewersOptions

type DeltaListReviewersOptions struct {
	DeltaFilter
	ListOptions
}

type DeltaListUnitsOptions

type DeltaListUnitsOptions struct{}

DeltaListUnitsOptions specifies options for ListUnits.

type DeltaReviewer

type DeltaReviewer struct {
	Person

	Suggested       bool   `json:",omitempty"` // whether this reviewer is just suggested as a possible reviewer (and not actually assigned)
	ReasonSuggested string `json:",omitempty"` // if Suggested, this is why (e.g., because the person wrote code this delta touches)

	Defs []*Def `json:",omitempty"` // defs that this reviewer committed to and that were changed in or affected by the delta
}

A DeltaReviewer is a person who is reviewing, or is suggested as a reviewer for, a delta.

type DeltaSpec

type DeltaSpec struct {
	Base RepoRevSpec
	Head RepoRevSpec
}

A DeltaSpec specifies a delta.

func UnmarshalDeltaSpec

func UnmarshalDeltaSpec(routeVars map[string]string) (DeltaSpec, error)

UnmarshalDeltaSpec marshals a map containing route variables generated by (*DeltaSpec).RouteVars() and returns the equivalent DeltaSpec struct.

func (DeltaSpec) RouteVars

func (s DeltaSpec) RouteVars() map[string]string

RouteVars returns the route variables for generating URLs to the delta specified by this DeltaSpec.

type DeltasService

type DeltasService interface {
	// Get fetches a summary of a delta.
	Get(ds DeltaSpec, opt *DeltaGetOptions) (*Delta, Response, error)

	// ListUnits lists units added/changed/deleted in a delta.
	ListUnits(ds DeltaSpec, opt *DeltaListUnitsOptions) ([]*UnitDelta, Response, error)

	// ListDefs lists definitions added/changed/deleted in a delta.
	ListDefs(ds DeltaSpec, opt *DeltaListDefsOptions) (*DeltaDefs, Response, error)

	// ListDependencies lists dependencies added/changed/deleted in a
	// delta.
	ListDependencies(ds DeltaSpec, opt *DeltaListDependenciesOptions) (*DeltaDependencies, Response, error)

	// ListFiles fetches the file diff for a delta.
	ListFiles(ds DeltaSpec, opt *DeltaListFilesOptions) (*DeltaFiles, Response, error)

	// ListAffectedAuthors lists authors whose code is added/deleted/changed
	// in a delta.
	ListAffectedAuthors(ds DeltaSpec, opt *DeltaListAffectedAuthorsOptions) ([]*DeltaAffectedPerson, Response, error)

	// ListAffectedClients lists clients whose code is affected by a delta.
	ListAffectedClients(ds DeltaSpec, opt *DeltaListAffectedClientsOptions) ([]*DeltaAffectedPerson, Response, error)

	// ListAffectedDependents lists dependent repositories that are affected
	// by a delta.
	ListAffectedDependents(ds DeltaSpec, opt *DeltaListAffectedDependentsOptions) ([]*DeltaAffectedRepo, Response, error)

	// ListReviewers lists people who are reviewing or are suggested
	// reviewers for this delta.
	ListReviewers(ds DeltaSpec, opt *DeltaListReviewersOptions) ([]*DeltaReviewer, Response, error)

	// ListIncoming lists deltas that affect the given repo.
	ListIncoming(rr RepoRevSpec, opt *DeltaListIncomingOptions) ([]*Delta, Response, error)
}

DeltasService interacts with the delta-related endpoints of the Sourcegraph API. A delta is all of the changes between two commits, possibly from two different repositories. It includes the usual file diffs as well as definition-level diffs, affected author/repo impact information, etc.

type EmailAddr

type EmailAddr struct {
	Email string // the email address (case-insensitively compared in the DB and API)

	Verified bool // whether this email address has been verified

	Primary bool // indicates this is the user's primary email (only 1 email can be primary per user)

	Guessed bool // whether Sourcegraph inferred via public data that this is an email for the user

	Blacklisted bool // indicates that this email should not be associated with the user (even if guessed in the future)
}

EmailAddr is an email address associated with a user.

type ErrRedirect

type ErrRedirect struct {
	RedirectURI string
}

func ErrRedirectFromString

func ErrRedirectFromString(msg string) *ErrRedirect

func (ErrRedirect) Error

func (e ErrRedirect) Error() string

type ErrRenamed

type ErrRenamed struct {
	// OldURI is the previous repository URI.
	OldURI string

	// NewURI is the new URI that the repository was renamed to.
	NewURI string
}

ErrRenamed is an error type that indicates that a repository was renamed from OldURI to NewURI.

func (ErrRenamed) Error

func (e ErrRenamed) Error() string

type ErrUserRenamed

type ErrUserRenamed struct {
	// OldLogin is the previous login name.
	OldLogin string

	// NewLogin is what the old login was renamed to.
	NewLogin string
}

ErrUserRenamed is an error type that indicates that a user account was renamed from OldLogin to NewLogin.

func (ErrUserRenamed) Error

func (e ErrUserRenamed) Error() string

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

func (r *ErrorResponse) Error() string

func (*ErrorResponse) HTTPStatusCode

func (r *ErrorResponse) HTTPStatusCode() int

type Example

type Example struct {
	graph.Ref

	// SrcHTML is the formatted HTML source code of the example, with links to
	// definitions.
	SrcHTML template.HTML `json:",omitempty"`

	// SourceCode contains the parsed source for this example, if requested via
	// DefListExamplesOptions.
	SourceCode *SourceCode `json:",omitempty"`

	// The line that the given example starts on
	StartLine int

	// The line that the given example ends on
	EndLine int

	// Error is whether an error occurred while fetching this example.
	Error bool
}

Example is a usage example of a def.

type Examples

type Examples []*Example

func (Examples) Len

func (vs Examples) Len() int

func (Examples) Less

func (vs Examples) Less(i, j int) bool

func (Examples) Swap

func (vs Examples) Swap(i, j int)

type FileData

type FileData struct {
	// Repo is the repository that contains this file data.
	RepoRev RepoRevSpec

	// File is the file (relative to the repository root directory) that this
	// file data is from.
	File string

	// Start and End is the range of the data in the file.
	Range *Range `json:",omitempty"`

	// EntireFile is true if the data spans the entire file contents.
	EntireFile bool `json:",omitempty"`

	// Annotated (i.e., HTML-marked up) content.
	Annotated template.HTML

	// Raw data.
	Raw []byte
}

FileData represents a range of (possibly annotated) data in a file.

type FileDiff

type FileDiff struct {
	*diff.FileDiff
	Hunks []*Hunk
	Stats diff.Stat
}

FileDiff holds data about a diff, and additionally stores extended information about its hunks.

type FileToken

type FileToken struct {
	Path string

	Entry *vcsclient.TreeEntry
}

func (FileToken) String

func (t FileToken) String() string

type FormatResult

type FormatResult struct {
	// TooManyRefs indicates that the file being formatted exceeded the maximum
	// number of refs that are linked. Only the first NumRefs refs are linked.
	TooManyRefs bool `json:",omitempty"`

	// NumRefs is the number of refs that were linked in this file. If the total
	// number of refs in the file exceeds the (server-defined) limit, NumRefs is
	// capped at the limit.
	NumRefs int

	// LineStartByteOffsets is the byte offset of each line's first
	// byte.
	LineStartByteOffsets []int
}

FormatResult contains information about and warnings from the formatting operation (if Formatted is true in the options).

type GitHubUserSpec

type GitHubUserSpec struct {
	Login string
	ID    int
}

GitHubUserSpec specifies a GitHub user, either by GitHub login or GitHub user ID.

func (GitHubUserSpec) RouteVars

func (s GitHubUserSpec) RouteVars() map[string]string

type HTTPResponse

type HTTPResponse struct {
	*http.Response
}

HTTPResponse is a wrapped HTTP response from the Sourcegraph API with additional Sourcegraph-specific response information parsed out. It implements Response.

func (*HTTPResponse) TotalCount

func (r *HTTPResponse) TotalCount() int

TotalCount implements Response.

type Hunk

type Hunk struct {
	*diff.Hunk

	// LinePrefixes holds a string where each character's index corresponds
	// to a line in the BodySource, and it's value reflects whether the line
	// is an addition, deletion, or change ('+', '-', ' ')
	LinePrefixes string `json:",omitempty"`

	// BaseSource holds the source code for the original hunk, having all
	// lines starting from the original line down to the end of the hunk.
	BaseSource *SourceCode `json:",omitempty"`

	// HeadSource contains the source code for the new hunk, holding
	// all consecutive lines from the start to the end.
	HeadSource *SourceCode `json:",omitempty"`

	// BodySource contains the source code for the Hunk body and is a mix
	// of both additions and deletions.
	BodySource *SourceCode `json:",omitempty"`
}

Hunk holds data about a hunk in a diff.

type Issue

type Issue struct {
	github.Issue
}

Issue is a issue returned by the Sourcegraph API.

func (*Issue) Spec

func (r *Issue) Spec() IssueSpec

Spec returns the IssueSpec that specifies r.

type IssueComment

type IssueComment struct {
	RenderedBody string // the body rendered to HTML (from raw markdown)
	Checklist    *Checklist
	github.IssueComment
}

type IssueCommentSpec

type IssueCommentSpec struct {
	Issue   IssueSpec
	Comment int
}

func (IssueCommentSpec) RouteVars

func (s IssueCommentSpec) RouteVars() map[string]string

type IssueGetOptions

type IssueGetOptions struct{}

type IssueListCommentsOptions

type IssueListCommentsOptions struct {
	ListOptions
}

type IssueListOptions

type IssueListOptions struct {
	State string `url:",omitempty"` // "open", "closed", or "all"
	ListOptions
}

type IssueSpec

type IssueSpec struct {
	Repo RepoSpec

	Number int // Sequence number of the issue
}

IssueSpec specifies a issue.

func UnmarshalIssueSpec

func UnmarshalIssueSpec(routeVars map[string]string) (IssueSpec, error)

func (IssueSpec) RouteVars

func (s IssueSpec) RouteVars() map[string]string

type IssuesService

type IssuesService interface {
	// Get fetches a issue.
	Get(issue IssueSpec, opt *IssueGetOptions) (*Issue, Response, error)

	// List issues for a repository.
	ListByRepo(repo RepoSpec, opt *IssueListOptions) ([]*Issue, Response, error)

	// ListComments lists comments on a issue.
	ListComments(issue IssueSpec, opt *IssueListCommentsOptions) ([]*IssueComment, Response, error)

	// CreateComment creates a comment on an issue.
	CreateComment(issue IssueSpec, comment *IssueComment) (*IssueComment, Response, error)

	// EditComment updates a comment on an issue.
	EditComment(issue IssueSpec, comment *IssueComment) (*IssueComment, Response, error)

	// DeleteComment deletes a comment on an issue.
	DeleteComment(issue IssueSpec, commentID int) (Response, error)
}

IssuesService communicates with the issue-related endpoints in the Sourcegraph API.

type ListOptions

type ListOptions struct {
	PerPage int `url:",omitempty" json:",omitempty"`
	Page    int `url:",omitempty" json:",omitempty"`
}

ListOptions specifies general pagination options for fetching a list of results.

func (ListOptions) Limit

func (o ListOptions) Limit() int

Limit returns the number of items to fetch.

func (ListOptions) Offset

func (o ListOptions) Offset() int

Offset returns the 0-indexed offset of the first item that appears on this page, based on the PerPage and Page values (which are given default values if they are zero).

func (ListOptions) PageOrDefault

func (o ListOptions) PageOrDefault() int

func (ListOptions) PerPageOrDefault

func (o ListOptions) PerPageOrDefault() int

type LogEntries

type LogEntries struct {
	MaxID   string
	Entries []string
}

type MarkdownData

type MarkdownData struct {
	Rendered  []byte
	Checklist *Checklist
}

type MarkdownOpt

type MarkdownOpt struct {
	EnableCheckboxes bool
}

type MarkdownRequestBody

type MarkdownRequestBody struct {
	Markdown []byte
	MarkdownOpt
}

type MarkdownService

type MarkdownService interface {
	Render(markdown []byte, opt MarkdownOpt) (*MarkdownData, Response, error)
}

type MockBuildDataService

type MockBuildDataService struct {
	FileSystem_ func(repo RepoRevSpec) (rwvfs.FileSystem, error)
}

func (MockBuildDataService) FileSystem

func (s MockBuildDataService) FileSystem(repo RepoRevSpec) (rwvfs.FileSystem, error)

type MockBuildsService

type MockBuildsService struct {
	Get_            func(build BuildSpec, opt *BuildGetOptions) (*Build, Response, error)
	List_           func(opt *BuildListOptions) ([]*Build, Response, error)
	Create_         func(repoRev RepoRevSpec, opt *BuildCreateOptions) (*Build, Response, error)
	Update_         func(build BuildSpec, info BuildUpdate) (*Build, Response, error)
	ListBuildTasks_ func(build BuildSpec, opt *BuildTaskListOptions) ([]*BuildTask, Response, error)
	CreateTasks_    func(build BuildSpec, tasks []*BuildTask) ([]*BuildTask, Response, error)
	UpdateTask_     func(task TaskSpec, info TaskUpdate) (*BuildTask, Response, error)
	GetLog_         func(build BuildSpec, opt *BuildGetLogOptions) (*LogEntries, Response, error)
	GetTaskLog_     func(task TaskSpec, opt *BuildGetLogOptions) (*LogEntries, Response, error)
	DequeueNext_    func() (*Build, Response, error)
}

func (MockBuildsService) Create

func (s MockBuildsService) Create(repoRev RepoRevSpec, opt *BuildCreateOptions) (*Build, Response, error)

func (MockBuildsService) CreateTasks

func (s MockBuildsService) CreateTasks(build BuildSpec, tasks []*BuildTask) ([]*BuildTask, Response, error)

func (MockBuildsService) DequeueNext

func (s MockBuildsService) DequeueNext() (*Build, Response, error)

func (MockBuildsService) Get

func (MockBuildsService) GetLog

func (MockBuildsService) GetTaskLog

func (s MockBuildsService) GetTaskLog(task TaskSpec, opt *BuildGetLogOptions) (*LogEntries, Response, error)

func (MockBuildsService) List

func (MockBuildsService) ListBuildTasks

func (s MockBuildsService) ListBuildTasks(build BuildSpec, opt *BuildTaskListOptions) ([]*BuildTask, Response, error)

func (MockBuildsService) Update

func (s MockBuildsService) Update(build BuildSpec, info BuildUpdate) (*Build, Response, error)

func (MockBuildsService) UpdateTask

func (s MockBuildsService) UpdateTask(task TaskSpec, info TaskUpdate) (*BuildTask, Response, error)

type MockDefsService

type MockDefsService struct {
	Get_            func(def DefSpec, opt *DefGetOptions) (*Def, Response, error)
	List_           func(opt *DefListOptions) ([]*Def, Response, error)
	ListRefs_       func(def DefSpec, opt *DefListRefsOptions) ([]*Ref, Response, error)
	ListExamples_   func(def DefSpec, opt *DefListExamplesOptions) ([]*Example, Response, error)
	ListAuthors_    func(def DefSpec, opt *DefListAuthorsOptions) ([]*AugmentedDefAuthor, Response, error)
	ListClients_    func(def DefSpec, opt *DefListClientsOptions) ([]*AugmentedDefClient, Response, error)
	ListDependents_ func(def DefSpec, opt *DefListDependentsOptions) ([]*AugmentedDefDependent, Response, error)
	ListVersions_   func(def DefSpec, opt *DefListVersionsOptions) ([]*Def, Response, error)
}

func (MockDefsService) Get

func (s MockDefsService) Get(def DefSpec, opt *DefGetOptions) (*Def, Response, error)

func (MockDefsService) List

func (s MockDefsService) List(opt *DefListOptions) ([]*Def, Response, error)

func (MockDefsService) ListAuthors

func (MockDefsService) ListClients

func (MockDefsService) ListDependents

func (MockDefsService) ListExamples

func (s MockDefsService) ListExamples(def DefSpec, opt *DefListExamplesOptions) ([]*Example, Response, error)

func (MockDefsService) ListRefs

func (s MockDefsService) ListRefs(def DefSpec, opt *DefListRefsOptions) ([]*Ref, Response, error)

func (MockDefsService) ListVersions

func (s MockDefsService) ListVersions(def DefSpec, opt *DefListVersionsOptions) ([]*Def, Response, error)

type MockDeltasService

type MockDeltasService struct {
	Get_                    func(ds DeltaSpec, opt *DeltaGetOptions) (*Delta, Response, error)
	ListUnits_              func(ds DeltaSpec, opt *DeltaListUnitsOptions) ([]*UnitDelta, Response, error)
	ListDefs_               func(ds DeltaSpec, opt *DeltaListDefsOptions) (*DeltaDefs, Response, error)
	ListDependencies_       func(ds DeltaSpec, opt *DeltaListDependenciesOptions) (*DeltaDependencies, Response, error)
	ListFiles_              func(ds DeltaSpec, opt *DeltaListFilesOptions) (*DeltaFiles, Response, error)
	ListAffectedAuthors_    func(ds DeltaSpec, opt *DeltaListAffectedAuthorsOptions) ([]*DeltaAffectedPerson, Response, error)
	ListAffectedClients_    func(ds DeltaSpec, opt *DeltaListAffectedClientsOptions) ([]*DeltaAffectedPerson, Response, error)
	ListAffectedDependents_ func(ds DeltaSpec, opt *DeltaListAffectedDependentsOptions) ([]*DeltaAffectedRepo, Response, error)
	ListReviewers_          func(ds DeltaSpec, opt *DeltaListReviewersOptions) ([]*DeltaReviewer, Response, error)
	ListIncoming_           func(rr RepoRevSpec, opt *DeltaListIncomingOptions) ([]*Delta, Response, error)
}

func (MockDeltasService) Get

func (MockDeltasService) ListAffectedAuthors

func (MockDeltasService) ListAffectedClients

func (MockDeltasService) ListAffectedDependents

func (MockDeltasService) ListDefs

func (MockDeltasService) ListDependencies

func (MockDeltasService) ListFiles

func (MockDeltasService) ListIncoming

func (MockDeltasService) ListReviewers

func (MockDeltasService) ListUnits

type MockIssuesService

type MockIssuesService struct {
	Get_           func(issue IssueSpec, opt *IssueGetOptions) (*Issue, Response, error)
	ListByRepo_    func(repo RepoSpec, opt *IssueListOptions) ([]*Issue, Response, error)
	ListComments_  func(issue IssueSpec, opt *IssueListCommentsOptions) ([]*IssueComment, Response, error)
	CreateComment_ func(issue IssueSpec, comment *IssueComment) (*IssueComment, Response, error)
	EditComment_   func(issue IssueSpec, comment *IssueComment) (*IssueComment, Response, error)
	DeleteComment_ func(issue IssueSpec, commentID int) (Response, error)
}

func (MockIssuesService) CreateComment

func (s MockIssuesService) CreateComment(issue IssueSpec, comment *IssueComment) (*IssueComment, Response, error)

func (MockIssuesService) DeleteComment

func (s MockIssuesService) DeleteComment(issue IssueSpec, commentID int) (Response, error)

func (MockIssuesService) EditComment

func (s MockIssuesService) EditComment(issue IssueSpec, comment *IssueComment) (*IssueComment, Response, error)

func (MockIssuesService) Get

func (MockIssuesService) ListByRepo

func (s MockIssuesService) ListByRepo(repo RepoSpec, opt *IssueListOptions) ([]*Issue, Response, error)

func (MockIssuesService) ListComments

type MockMarkdownService

type MockMarkdownService struct {
	Render_ func(markdown []byte, opt MarkdownOpt) (*MarkdownData, Response, error)
}

func (MockMarkdownService) Render

func (s MockMarkdownService) Render(markdown []byte, opt MarkdownOpt) (*MarkdownData, Response, error)

type MockOrgsService

type MockOrgsService struct {
	Get_            func(org OrgSpec) (*Org, Response, error)
	ListMembers_    func(org OrgSpec, opt *OrgListMembersOptions) ([]*User, Response, error)
	GetSettings_    func(org OrgSpec) (*OrgSettings, Response, error)
	UpdateSettings_ func(org OrgSpec, settings OrgSettings) (Response, error)
}

func (MockOrgsService) Get

func (s MockOrgsService) Get(org OrgSpec) (*Org, Response, error)

func (MockOrgsService) GetSettings

func (s MockOrgsService) GetSettings(org OrgSpec) (*OrgSettings, Response, error)

func (MockOrgsService) ListMembers

func (s MockOrgsService) ListMembers(org OrgSpec, opt *OrgListMembersOptions) ([]*User, Response, error)

func (MockOrgsService) UpdateSettings

func (s MockOrgsService) UpdateSettings(org OrgSpec, settings OrgSettings) (Response, error)

type MockPeopleService

type MockPeopleService struct {
	Get_ func(person PersonSpec) (*Person, Response, error)
}

func (MockPeopleService) Get

func (s MockPeopleService) Get(person PersonSpec) (*Person, Response, error)

type MockPullRequestsService

type MockPullRequestsService struct {
	Get_           func(pull PullRequestSpec, opt *PullRequestGetOptions) (*PullRequest, Response, error)
	ListByRepo_    func(repo RepoSpec, opt *PullRequestListOptions) ([]*PullRequest, Response, error)
	ListComments_  func(pull PullRequestSpec, opt *PullRequestListCommentsOptions) ([]*PullRequestComment, Response, error)
	CreateComment_ func(pull PullRequestSpec, comment *PullRequestComment) (*PullRequestComment, Response, error)
	EditComment_   func(pull PullRequestSpec, comment *PullRequestComment) (*PullRequestComment, Response, error)
	DeleteComment_ func(pull PullRequestSpec, commentID int) (Response, error)
	Merge_         func(pull PullRequestSpec, mergeRequest *PullRequestMergeRequest) (*PullRequestMergeResult, Response, error)
}

func (MockPullRequestsService) CreateComment

func (MockPullRequestsService) DeleteComment

func (s MockPullRequestsService) DeleteComment(pull PullRequestSpec, commentID int) (Response, error)

func (MockPullRequestsService) EditComment

func (MockPullRequestsService) Get

func (MockPullRequestsService) ListByRepo

func (MockPullRequestsService) ListComments

func (MockPullRequestsService) Merge

type MockRepoTreeService

type MockRepoTreeService struct {
	Get_    func(entry TreeEntrySpec, opt *RepoTreeGetOptions) (*TreeEntry, Response, error)
	Search_ func(RepoRevSpec, *RepoTreeSearchOptions) ([]*vcs.SearchResult, Response, error)
}

func (MockRepoTreeService) Get

func (MockRepoTreeService) Search

type MockReposService

type MockReposService struct {
	Get_               func(repo RepoSpec, opt *RepoGetOptions) (*Repo, Response, error)
	GetStats_          func(repo RepoRevSpec) (RepoStats, Response, error)
	GetCombinedStatus_ func(spec RepoRevSpec) (*CombinedStatus, Response, error)
	CreateStatus_      func(spec RepoRevSpec, st RepoStatus) (*RepoStatus, Response, error)
	GetOrCreate_       func(repo RepoSpec, opt *RepoGetOptions) (*Repo, Response, error)
	GetSettings_       func(repo RepoSpec) (*RepoSettings, Response, error)
	UpdateSettings_    func(repo RepoSpec, settings RepoSettings) (Response, error)
	RefreshProfile_    func(repo RepoSpec) (Response, error)
	RefreshVCSData_    func(repo RepoSpec) (Response, error)
	ComputeStats_      func(repo RepoRevSpec) (Response, error)
	GetBuild_          func(repo RepoRevSpec, opt *RepoGetBuildOptions) (*RepoBuildInfo, Response, error)
	Create_            func(newRepoSpec NewRepoSpec) (*Repo, Response, error)
	GetReadme_         func(repo RepoRevSpec) (*vcsclient.TreeEntry, Response, error)
	List_              func(opt *RepoListOptions) ([]*Repo, Response, error)
	ListCommits_       func(repo RepoSpec, opt *RepoListCommitsOptions) ([]*Commit, Response, error)
	GetCommit_         func(rev RepoRevSpec, opt *RepoGetCommitOptions) (*Commit, Response, error)
	ListBranches_      func(repo RepoSpec, opt *RepoListBranchesOptions) ([]*vcs.Branch, Response, error)
	ListTags_          func(repo RepoSpec, opt *RepoListTagsOptions) ([]*vcs.Tag, Response, error)
	ListBadges_        func(repo RepoSpec) ([]*Badge, Response, error)
	ListCounters_      func(repo RepoSpec) ([]*Counter, Response, error)
	ListAuthors_       func(repo RepoRevSpec, opt *RepoListAuthorsOptions) ([]*AugmentedRepoAuthor, Response, error)
	ListClients_       func(repo RepoSpec, opt *RepoListClientsOptions) ([]*AugmentedRepoClient, Response, error)
	ListDependencies_  func(repo RepoRevSpec, opt *RepoListDependenciesOptions) ([]*AugmentedRepoDependency, Response, error)
	ListDependents_    func(repo RepoSpec, opt *RepoListDependentsOptions) ([]*AugmentedRepoDependent, Response, error)
	ListByContributor_ func(user UserSpec, opt *RepoListByContributorOptions) ([]*AugmentedRepoContribution, Response, error)
	ListByClient_      func(user UserSpec, opt *RepoListByClientOptions) ([]*AugmentedRepoUsageByClient, Response, error)
	ListByRefdAuthor_  func(user UserSpec, opt *RepoListByRefdAuthorOptions) ([]*AugmentedRepoUsageOfAuthor, Response, error)
}

func (MockReposService) ComputeStats

func (s MockReposService) ComputeStats(repo RepoRevSpec) (Response, error)

func (MockReposService) Create

func (s MockReposService) Create(newRepoSpec NewRepoSpec) (*Repo, Response, error)

func (MockReposService) CreateStatus

func (s MockReposService) CreateStatus(spec RepoRevSpec, st RepoStatus) (*RepoStatus, Response, error)

func (MockReposService) Get

func (s MockReposService) Get(repo RepoSpec, opt *RepoGetOptions) (*Repo, Response, error)

func (MockReposService) GetBuild

func (MockReposService) GetCombinedStatus

func (s MockReposService) GetCombinedStatus(spec RepoRevSpec) (*CombinedStatus, Response, error)

func (MockReposService) GetCommit

func (MockReposService) GetOrCreate

func (s MockReposService) GetOrCreate(repo RepoSpec, opt *RepoGetOptions) (*Repo, Response, error)

func (MockReposService) GetReadme

func (MockReposService) GetSettings

func (s MockReposService) GetSettings(repo RepoSpec) (*RepoSettings, Response, error)

func (MockReposService) GetStats

func (s MockReposService) GetStats(repo RepoRevSpec) (RepoStats, Response, error)

func (MockReposService) List

func (s MockReposService) List(opt *RepoListOptions) ([]*Repo, Response, error)

func (MockReposService) ListAuthors

func (MockReposService) ListBadges

func (s MockReposService) ListBadges(repo RepoSpec) ([]*Badge, Response, error)

func (MockReposService) ListBranches

func (s MockReposService) ListBranches(repo RepoSpec, opt *RepoListBranchesOptions) ([]*vcs.Branch, Response, error)

func (MockReposService) ListByClient

func (MockReposService) ListByContributor

func (MockReposService) ListByRefdAuthor

func (MockReposService) ListClients

func (MockReposService) ListCommits

func (s MockReposService) ListCommits(repo RepoSpec, opt *RepoListCommitsOptions) ([]*Commit, Response, error)

func (MockReposService) ListCounters

func (s MockReposService) ListCounters(repo RepoSpec) ([]*Counter, Response, error)

func (MockReposService) ListDependencies

func (MockReposService) ListDependents

func (MockReposService) ListTags

func (s MockReposService) ListTags(repo RepoSpec, opt *RepoListTagsOptions) ([]*vcs.Tag, Response, error)

func (MockReposService) RefreshProfile

func (s MockReposService) RefreshProfile(repo RepoSpec) (Response, error)

func (MockReposService) RefreshVCSData

func (s MockReposService) RefreshVCSData(repo RepoSpec) (Response, error)

func (MockReposService) UpdateSettings

func (s MockReposService) UpdateSettings(repo RepoSpec, settings RepoSettings) (Response, error)

type MockResponse

type MockResponse struct{}

type MockSearchService

type MockSearchService struct {
	Search_   func(opt *SearchOptions) (*SearchResults, Response, error)
	Complete_ func(q RawQuery) (*Completions, Response, error)
	Suggest_  func(q RawQuery) ([]*Suggestion, Response, error)
}

func (MockSearchService) Complete

func (MockSearchService) Search

func (MockSearchService) Suggest

func (s MockSearchService) Suggest(q RawQuery) ([]*Suggestion, Response, error)

type MockUnitsService

type MockUnitsService struct {
	Get_  func(spec UnitSpec) (*unit.RepoSourceUnit, Response, error)
	List_ func(opt *UnitListOptions) ([]*unit.RepoSourceUnit, Response, error)
}

func (MockUnitsService) Get

func (MockUnitsService) List

type MockUsersService

type MockUsersService struct {
	Get_                   func(user UserSpec, opt *UserGetOptions) (*User, Response, error)
	GetSettings_           func(user UserSpec) (*UserSettings, Response, error)
	UpdateSettings_        func(user UserSpec, settings UserSettings) (Response, error)
	ListEmails_            func(user UserSpec) ([]*EmailAddr, Response, error)
	GetOrCreateFromGitHub_ func(user GitHubUserSpec, opt *UserGetOptions) (*User, Response, error)
	RefreshProfile_        func(userSpec UserSpec) (Response, error)
	ComputeStats_          func(userSpec UserSpec) (Response, error)
	List_                  func(opt *UsersListOptions) ([]*User, Response, error)
	ListAuthors_           func(user UserSpec, opt *UsersListAuthorsOptions) ([]*AugmentedPersonUsageByClient, Response, error)
	ListClients_           func(user UserSpec, opt *UsersListClientsOptions) ([]*AugmentedPersonUsageOfAuthor, Response, error)
	ListOrgs_              func(member UserSpec, opt *UsersListOrgsOptions) ([]*Org, Response, error)
}

func (MockUsersService) ComputeStats

func (s MockUsersService) ComputeStats(userSpec UserSpec) (Response, error)

func (MockUsersService) Get

func (s MockUsersService) Get(user UserSpec, opt *UserGetOptions) (*User, Response, error)

func (MockUsersService) GetOrCreateFromGitHub

func (s MockUsersService) GetOrCreateFromGitHub(user GitHubUserSpec, opt *UserGetOptions) (*User, Response, error)

func (MockUsersService) GetSettings

func (s MockUsersService) GetSettings(user UserSpec) (*UserSettings, Response, error)

func (MockUsersService) List

func (s MockUsersService) List(opt *UsersListOptions) ([]*User, Response, error)

func (MockUsersService) ListAuthors

func (MockUsersService) ListClients

func (MockUsersService) ListEmails

func (s MockUsersService) ListEmails(user UserSpec) ([]*EmailAddr, Response, error)

func (MockUsersService) ListOrgs

func (s MockUsersService) ListOrgs(member UserSpec, opt *UsersListOrgsOptions) ([]*Org, Response, error)

func (MockUsersService) RefreshProfile

func (s MockUsersService) RefreshProfile(userSpec UserSpec) (Response, error)

func (MockUsersService) UpdateSettings

func (s MockUsersService) UpdateSettings(user UserSpec, settings UserSettings) (Response, error)

type NewRepoSpec

type NewRepoSpec struct {
	Type        string
	CloneURLStr string `json:"CloneURL"`
}

type Org

type Org struct {
	User
}

func (*Org) OrgSpec

func (o *Org) OrgSpec() OrgSpec

OrgSpec returns the OrgSpec that specifies o.

type OrgListMembersOptions

type OrgListMembersOptions struct {
	ListOptions
}

type OrgSettings

type OrgSettings struct {
	PlanSettings `json:",omitempty"`
}

OrgSettings describes an org's configuration settings.

type OrgSpec

type OrgSpec struct {
	Org string // name of organization
	UID int    // user ID of the "user" record for this organization
}

OrgSpec specifies an organization. At least one of Email, Login, and UID must be nonempty.

func ParseOrgSpec

func ParseOrgSpec(pathComponent string) (OrgSpec, error)

ParseOrgSpec parses a string generated by (*OrgSpec).String() and returns the equivalent OrgSpec struct.

func (*OrgSpec) PathComponent

func (s *OrgSpec) PathComponent() string

PathComponent returns the URL path component that specifies the org.

func (*OrgSpec) RouteVars

func (s *OrgSpec) RouteVars() map[string]string

type OrgsService

type OrgsService interface {
	// Get fetches an organization.
	Get(org OrgSpec) (*Org, Response, error)

	// ListMembers lists members of an organization.
	ListMembers(org OrgSpec, opt *OrgListMembersOptions) ([]*User, Response, error)

	// GetSettings fetches an org's configuration settings.
	GetSettings(org OrgSpec) (*OrgSettings, Response, error)

	// UpdateSettings updates an org's configuration settings.
	UpdateSettings(org OrgSpec, settings OrgSettings) (Response, error)
}

OrgsService communicates with the organizations-related endpoints in the Sourcegraph API.

type PeopleService

type PeopleService interface {
	// Get gets a person. If an email is provided and it resolves to a
	// registered user, information about that user is
	// returned. Otherwise a transient person is created and returned.
	Get(person PersonSpec) (*Person, Response, error)
}

PeopleService communicates with the people-related endpoints in the Sourcegraph API.

type Person

type Person struct {
	// PersonSpec is an identifier for the person. If the person was
	// resolved to a user, then both Login and UID are set. Otherwise
	// only Email is set, and it may be obfuscated (to protect
	// privacy).
	PersonSpec

	// FullName is the (possibly empty) full name of the person.
	FullName string

	// AvatarURL is the URL to the user's avatar image.
	AvatarURL string
}

A Person represents either a registered user or a committer to a repository (typically when their commit email can't be resolved to a user).

func (*Person) AvatarURLOfSize

func (p *Person) AvatarURLOfSize(width int) string

AvatarURLOfSize returns the URL to an avatar for the user with the given width (in pixels).

func (*Person) HasProfile

func (p *Person) HasProfile() bool

HasProfile is true if the person has a profile page on Sourcegraph. Transient users currently do not have profile pages.

func (*Person) ShortName

func (p *Person) ShortName() string

ShortName returns the person's Login if nonempty and otherwise returns the portion of Email before the '@'.

func (*Person) Transient

func (p *Person) Transient() bool

Transient is true if this person was constructed on the fly and is not persisted or resolved to a Sourcegraph/GitHub/etc. user.

type PersonSpec

type PersonSpec struct {
	// Email is a person's email address. It may be obfuscated (to
	// protect privacy).
	Email string

	// Login is a user's login.
	Login string

	// UID is a user's UID.
	UID int
}

PersonSpec specifies a person. At least one of Email, Login, and UID must be nonempty.

func ParsePersonSpec

func ParsePersonSpec(pathComponent string) (PersonSpec, error)

ParsePersonSpec parses a string generated by (*PersonSpec).String() and returns the equivalent PersonSpec struct.

func (*PersonSpec) PathComponent

func (s *PersonSpec) PathComponent() string

PathComponent returns the URL path component that specifies the person.

func (*PersonSpec) RouteVars

func (s *PersonSpec) RouteVars() map[string]string

type PersonStatType

type PersonStatType string

func (*PersonStatType) Scan

func (x *PersonStatType) Scan(v interface{}) error

func (PersonStatType) Value

func (x PersonStatType) Value() (driver.Value, error)

type PersonStats

type PersonStats map[PersonStatType]int

type PersonUsageByClient

type PersonUsageByClient struct {
	AuthorUID   nnz.Int    `db:"author_uid"`
	AuthorEmail nnz.String `db:"author_email"`
	RefCount    int        `db:"ref_count"`
}

type PersonUsageOfAuthor

type PersonUsageOfAuthor struct {
	ClientUID   nnz.Int    `db:"client_uid"`
	ClientEmail nnz.String `db:"client_email"`
	RefCount    int        `db:"ref_count"`
}

type Plan

type Plan struct {
	Repos *RepoListOptions
	Defs  *DefListOptions
	Users *UsersListOptions

	Tree *RepoTreeSearchOptions

	// TreeRepoRevs constrains the Tree search results to a set of
	// repository revisions (given by their URIs plus an optional "@"
	// and a revision specifier). For example, "repo.com/foo@revspec".
	//
	// TODO(sqs): gorilla/schema does not respect ",comma" and it has
	// no similar option, so specifying multiple repo revs here does
	// NOT work.
	TreeRepoRevs []string `url:",omitempty,comma" json:",omitempty"`
}

A Plan is a query plan that fetches the data necessary to satisfy (and provide autocomplete suggestions for) a query.

func (*Plan) String

func (p *Plan) String() string

type PlanSettings

type PlanSettings struct {
	PlanID *string `json:",omitempty"`
}

PlanSettings describes the pricing plan that the user or org has selected.

type PullRequest

type PullRequest struct {
	github.PullRequest

	// Checklist is a summary of all the checkboxes in the pull request (number of checked and unchecked).
	Checklist *Checklist `json:",omitempty"`
}

PullRequest is a pull request returned by the Sourcegraph API.

func (*PullRequest) Spec

func (r *PullRequest) Spec() PullRequestSpec

Spec returns the PullRequestSpec that specifies r.

type PullRequestComment

type PullRequestComment struct {
	github.PullRequestComment

	// Published is whether the comment is in a published state, currently always true.
	Published bool

	// RenderedBody is the comment body rendered as HTML (from raw markdown).
	RenderedBody string

	// Checklist is a summary of all the checkboxes in the comment (number of checked and unchecked).
	Checklist *Checklist
}

type PullRequestCommentSpec

type PullRequestCommentSpec struct {
	Pull    PullRequestSpec
	Comment int
}

func UnmarshalPullRequestCommentSpec

func UnmarshalPullRequestCommentSpec(v map[string]string) (spec PullRequestCommentSpec, err error)

func (PullRequestCommentSpec) RouteVars

func (c PullRequestCommentSpec) RouteVars() map[string]string

type PullRequestGetOptions

type PullRequestGetOptions struct {
	// Checklist is whether to populate the Checklist field on the returned PullRequest.
	Checklist bool
}

type PullRequestListCommentsOptions

type PullRequestListCommentsOptions struct {
	ListOptions
}

type PullRequestListOptions

type PullRequestListOptions struct {
	State string `url:",omitempty"` // "open", "closed", or "all"
	ListOptions
}

type PullRequestMergeRequest

type PullRequestMergeRequest struct {
	CommitMessage string
}

type PullRequestMergeResult

type PullRequestMergeResult struct {
	github.PullRequestMergeResult
}

type PullRequestSpec

type PullRequestSpec struct {
	Repo RepoSpec // the base repository of the pull request

	Number int // Sequence number of the pull request
}

PullRequestSpec specifies a pull request.

func UnmarshalPullRequestSpec

func UnmarshalPullRequestSpec(v map[string]string) (PullRequestSpec, error)

UnmarshalPullRequestSpec parses route variables (a map returned by (PullRequestSpec).RouteVars()) to construct a PullRequestSpec.

func (PullRequestSpec) IssueSpec

func (s PullRequestSpec) IssueSpec() IssueSpec

IssueSpec returns a specifier for the issue associated with this pull request (same repo, same number).

func (PullRequestSpec) RouteVars

func (s PullRequestSpec) RouteVars() map[string]string

RouteVars returns the route variables for generating pull request URLs.

type PullRequestsService

type PullRequestsService interface {
	// Get fetches a pull request.
	Get(pull PullRequestSpec, opt *PullRequestGetOptions) (*PullRequest, Response, error)

	// List pull requests for a repository.
	ListByRepo(repo RepoSpec, opt *PullRequestListOptions) ([]*PullRequest, Response, error)

	// ListComments lists comments on a pull request.
	ListComments(pull PullRequestSpec, opt *PullRequestListCommentsOptions) ([]*PullRequestComment, Response, error)

	// CreateComment creates a comment on a pull request.
	CreateComment(pull PullRequestSpec, comment *PullRequestComment) (*PullRequestComment, Response, error)

	// EditComment updates an existing comment on a pull request.
	EditComment(pull PullRequestSpec, comment *PullRequestComment) (*PullRequestComment, Response, error)

	// DeleteComment deletes a comment on a pull request.
	DeleteComment(pull PullRequestSpec, commentID int) (Response, error)

	// Merge merges a pull request
	Merge(pull PullRequestSpec, mergeRequest *PullRequestMergeRequest) (*PullRequestMergeResult, Response, error)
}

PullRequestsService communicates with the pull request-related endpoints in the Sourcegraph API.

type QualFormatStrings

type QualFormatStrings struct {
	Unqualified             string `json:",omitempty"`
	ScopeQualified          string `json:",omitempty"`
	DepQualified            string `json:",omitempty"`
	RepositoryWideQualified string `json:",omitempty"`
	LanguageWideQualified   string `json:",omitempty"`
}

QualFormatStrings holds the formatted string for each Qualification for a def (for either Name or Type).

type Range

type Range struct {
	Start, End int
}

Range is a character range within a file.

TODO(sqs): rune range?

type RawQuery

type RawQuery struct {
	// String is the raw query string from the client.
	String string

	// InsertionPoint is the 0-indexed character offset of the text
	// insertion cursor on the client.
	InsertionPoint int
}

A RawQuery is a raw search query. To obtain the results for the query, it must be tokenized, parsed, resolved, planned, etc.

func Join

func Join(tokens []Token) RawQuery

Join joins tokens to reconstruct a query string (that, when tokenized, would yield the same tokens). It returns the query and the insertion point (which is the position of the active token's last character, or the position after the last token's last character if there is no active token).

type Ref

type Ref struct {
	graph.Ref
	Authorship *AuthorshipInfo
}

type Refs

type Refs []*Ref

func (Refs) Len

func (vs Refs) Len() int

func (Refs) Less

func (vs Refs) Less(i, j int) bool

func (Refs) Swap

func (vs Refs) Swap(i, j int)

type Repo

type Repo struct {
	// RID is the numeric primary key for a repository.
	RID int

	// URI is a normalized identifier for this repository based on its primary
	// clone URL. E.g., "github.com/user/repo".
	URI string

	// URIAlias is another URI that, if accessed, will redirect to
	// this repository's primary URI. It's used, for example, to
	// redirect from GitHub repos to their canonical URI (such as Go
	// repos on gopkg.in).
	URIAlias nnz.String `db:"uri_alias"`

	// Name is the base name (the final path component) of the repository,
	// typically the name of the directory that the repository would be cloned
	// into. (For example, for git://example.com/foo.git, the name is "foo".)
	Name string

	// OwnerUserID is the account that owns this repository.
	OwnerUserID int `db:"owner_user_id"`

	// OwnerGitHubUserID is the GitHub user ID of this repository's owner, if this
	// is a GitHub repository.
	OwnerGitHubUserID nnz.Int `db:"owner_github_user_id" json:",omitempty"`

	// Description is a brief description of the repository.
	Description string `json:",omitempty"`

	// VCS is the short name of the VCS system that this repository uses: "git"
	// or "hg".
	VCS string `db:"vcs"`

	// HTTPCloneURL is the HTTPS clone URL of the repository (or the
	// HTTP clone URL, if no HTTPS clone URL is available).
	HTTPCloneURL string `db:"http_clone_url"`

	// SSHCloneURL is the SSH clone URL if the repository, if any.
	SSHCloneURL nnz.String `db:"ssh_clone_url"`

	// HomepageURL is the URL to the repository's homepage, if any.
	HomepageURL nnz.String `db:"homepage_url"`

	// DefaultBranch is the default VCS branch used (typically "master" for git
	// repositories and "default" for hg repositories).
	DefaultBranch string `db:"default_branch"`

	// Language is the primary programming language used in this repository.
	Language string

	// GitHubStars is the number of stargazers this repository has on GitHub (or
	// 0 if it is not a GitHub repository).
	GitHubStars int `db:"github_stars"`

	// GitHubID is the GitHub ID of this repository. If a GitHub repository is
	// renamed, the ID remains the same and should be used to resolve across the
	// name change.
	GitHubID nnz.Int `db:"github_id" json:",omitempty"`

	// Disabled is whether this repo should not be downloaded and processed by the worker.
	Disabled bool `json:",omitempty"`

	// Deprecated repositories are labeled as such and hidden from global search results.
	Deprecated bool

	// Fork is whether this repository is a fork.
	Fork bool

	// Mirror is whether this repository is a mirror.
	Mirror bool

	// Private is whether this repository is private.
	Private bool

	// CreatedAt is when this repository was created. If it represents
	// an externally hosted (e.g., GitHub) repository, the creation
	// date is when it was created at that origin.
	CreatedAt time.Time `db:"created_at"`

	// UpdatedAt is when this repository's metadata was last updated
	// (on its origin if it's an externally hosted repository).
	UpdatedAt time.Time `db:"updated_at"`

	// PushedAt is when this repository's was last (VCS-)pushed to.
	PushedAt time.Time `db:"pushed_at"`

	// Stat holds repository statistics. It's only filled in if Repo{Get,List}Options has Stats == true.
	Stat RepoStats `db:"-" json:",omitempty"`

	// Permissions describes the permissions that the current user (or
	// anonymous users, if there is no current user) is granted to
	// this repository.
	Permissions RepoPermissions `db:"-"`
}

Repo is a code repository returned by the Sourcegraph API.

func (*Repo) GitHubHTMLURL

func (r *Repo) GitHubHTMLURL() string

GitHubHTMLURL returns URL to the GitHub HTML page (e.g., https://github.com/foo/bar, not a clone URL) for this repo, if it's a GitHub repo. Otherwise it returns the empty string.

func (*Repo) IsGitHubRepo

func (r *Repo) IsGitHubRepo() bool

IsGitHubRepo returns true iff this repository is hosted on GitHub.

func (*Repo) RepoSpec

func (r *Repo) RepoSpec() RepoSpec

RepoSpec returns the RepoSpec that specifies r.

type RepoAuthor

type RepoAuthor struct {
	UID   nnz.Int
	Email nnz.String
	AuthorStats
}

type RepoBuildInfo

type RepoBuildInfo struct {
	Exact *Build // the newest build, if any, that exactly matches the revspec (can be same as LastSuccessful)

	LastSuccessful *Build // the last successful build of a commit ID reachable from the revspec (can be same as Exact)

	CommitsBehind        int     // the number of commits between the revspec and the commit of the LastSuccessful build
	LastSuccessfulCommit *Commit // the commit of the LastSuccessful build
}

RepoBuildInfo holds a repository build (if one exists for the originally specified revspec) and additional information. It is returned by Repos.GetBuild.

type RepoClient

type RepoClient struct {
	UID   nnz.Int
	Email nnz.String
	ClientStats
}

type RepoContribution

type RepoContribution struct {
	RepoURI string `db:"repo"`
	AuthorStats
}

type RepoDependency

type RepoDependency struct {
	ToRepo string `db:"to_repo"`
}

type RepoDependent

type RepoDependent struct {
	FromRepo string `db:"from_repo"`
}

type RepoGetBuildOptions

type RepoGetBuildOptions struct {
	// Exact is whether only a build whose commit ID exactly matches
	// the revspec should be returned. (For non-full-commit ID
	// revspecs, such as branches, tags, and partial commit IDs, this
	// means that the build's commit ID matches the resolved revspec's
	// commit ID.)
	//
	// If Exact is false, then builds for older commits that are
	// reachable from the revspec may also be returned. For example,
	// if there's a build for master~1 but no build for master, and
	// your revspec is master, using Exact=false will return the build
	// for master~1.
	//
	// Using Exact=true is faster as the commit and build history
	// never needs to be searched. If the exact build is not
	// found, or the exact build was found but it failed,
	// LastSuccessful and LastSuccessfulCommit for RepoBuildInfo
	// will be nil.
	Exact bool `url:",omitempty" json:",omitempty"`
}

RepoGetBuildOptions sets options for the Repos.GetBuild call.

type RepoGetCommitOptions

type RepoGetCommitOptions struct {
}

type RepoGetOptions

type RepoGetOptions struct {
	Stats bool `url:",omitempty" json:",omitempty"` // whether to fetch and include stats in the returned repository
}

RepoGetOptions specifies options for getting a repository.

type RepoListAuthorsOptions

type RepoListAuthorsOptions struct {
	ListOptions
}

type RepoListBranchesOptions

type RepoListBranchesOptions struct {
	ListOptions
}

type RepoListByClientOptions

type RepoListByClientOptions struct {
	ListOptions
}

type RepoListByContributorOptions

type RepoListByContributorOptions struct {
	NoFork bool
	ListOptions
}

type RepoListByRefdAuthorOptions

type RepoListByRefdAuthorOptions struct {
	ListOptions
}

type RepoListClientsOptions

type RepoListClientsOptions struct {
	ListOptions
}

type RepoListCommitsOptions

type RepoListCommitsOptions struct {
	Head string `url:",omitempty" json:",omitempty"`
	Base string `url:",omitempty" json:",omitempty"`
	ListOptions
}

type RepoListDependenciesOptions

type RepoListDependenciesOptions struct {
	ListOptions
}

type RepoListDependentsOptions

type RepoListDependentsOptions struct{ ListOptions }

type RepoListOptions

type RepoListOptions struct {
	Name string `url:",omitempty" json:",omitempty"`

	// Specifies a search query for repositories. If specified, then the Sort and Direction options are ignored
	Query string `url:",omitempty" json:",omitempty"`

	URIs []string `url:",comma,omitempty" json:",omitempty"`

	BuiltOnly bool `url:",omitempty" json:",omitempty"`

	Sort      string `url:",omitempty" json:",omitempty"`
	Direction string `url:",omitempty" json:",omitempty"`

	NoFork bool `url:",omitempty" json:",omitempty"`

	Type string `url:",omitempty" json:",omitempty"` // "public" or "private" (empty default means "all")

	State string `url:",omitempty" json:",omitempty"` // "enabled" or "disabled" (empty default means return "all")

	Owner string `url:",omitempty" json:",omitempty"`

	Stats bool `url:",omitempty" json:",omitempty"` // whether to fetch and include stats in the returned repositories

	ListOptions
}

type RepoListTagsOptions

type RepoListTagsOptions struct {
	ListOptions
}

type RepoPermissions

type RepoPermissions struct {
	Read  bool
	Write bool
	Admin bool
}

RepoPermissions describes the possible permissions that a user (or an anonymous user) can be granted to a repository.

type RepoRevSpec

type RepoRevSpec struct {
	RepoSpec        // repository URI or RID
	Rev      string // the abstract/unresolved revspec, such as a branch name or abbreviated commit ID
	CommitID string // the full commit ID that Rev resolves to
}

RepoRevSpec specifies a repository at a specific commit (or revision specifier, such as a branch, which is resolved on the server side to a specific commit).

Filling in CommitID is an optional optimization. It avoids the need for another resolution of Rev. If CommitID is filled in, the "Rev" route variable becomes "Rev===CommitID" (e.g., "master===af4cd6"). Handlers can parse this string to retrieve the pre-resolved commit ID (e.g., "af4cd6") and still return data that constructs URLs using the unresolved revspec (e.g., "master").

Why is it important/useful to pass the resolved commit ID instead of just using a revspec everywhere? Consider this case. Your application wants to make a bunch of requests for resources relating to "master"; for example, it wants to retrieve a source file foo.go at master and all of the definitions and references contained in the file. This may consist of dozens of API calls. If each API call specified just "master", there would be 2 problems: (1) each API call would have to re-resolve "master" to its actual commit ID, which takes a lot of extra work; and (2) if the "master" ref changed during the API calls (if someone pushed in the middle of the API call, for example), then your application would receive data from 2 different commits. The solution is for your application to resolve the revspec once and pass both the original revspec and the resolved commit ID in all API calls it makes.

And why do we want to preserve the unresolved revspec? In this case, your app wants to let the user continue browsing "master". If the API data all referred to a specific commit ID, then the user would cease browsing master the next time she clicked a link on your app. Preserving the revspec gives the user a choice whether to use the absolute commit ID or the revspec (similar to how GitHub lets you canonicalize a URL with 'y' but does not default to using the canonical URL).

func UnmarshalRepoRevSpec

func UnmarshalRepoRevSpec(routeVars map[string]string) (RepoRevSpec, error)

UnmarshalRepoRevSpec marshals a map containing route variables generated by (*RepoRevSpec).RouteVars() and returns the equivalent RepoRevSpec struct.

func (RepoRevSpec) RevPathComponent

func (s RepoRevSpec) RevPathComponent() string

RevPathComponent encodes the revision and commit ID for use in a URL path. If CommitID is set, the path component is "Rev===CommitID"; otherwise, it is just "Rev". See the docstring for RepoRevSpec for an explanation why.

func (RepoRevSpec) RouteVars

func (s RepoRevSpec) RouteVars() map[string]string

RouteVars returns route variables for constructing routes to a repository commit.

type RepoSettings

type RepoSettings struct {
	// Enabled is whether this repository has been enabled for use on
	// Sourcegraph by a repository owner or a site admin.
	Enabled *bool `db:"enabled" json:",omitempty"`

	// BuildPushes is whether head commits on newly pushed branches
	// should be automatically built.
	BuildPushes *bool `db:"build_pushes" json:",omitempty"`

	// ExternalCommitStatuses is whether the build status
	// (pending/failure/success) of each commit should be published to
	// GitHub using the repo status API
	// (https://developer.github.com/v3/repos/statuses/).
	//
	// This behavior is also subject to the
	// UnsuccessfulExternalCommitStatuses setting value.
	ExternalCommitStatuses *bool `db:"external_commit_statuses" json:",omitempty"`

	// UnsuccessfulExternalCommitStatuses, if true, indicates that
	// pending/failure commit statuses should be published to
	// GitHub. If false (default), only successful commit status are
	// published. The default of false avoids bothersome warning
	// messages and UI pollution in case the Sourcegraph build
	// fails. Until our builds are highly reliable, a Sourcegraph
	// build failure is not necessarily an indication of a problem
	// with the repository.
	//
	// This setting is only meaningful if ExternalCommitStatuses is
	// true.
	UnsuccessfulExternalCommitStatuses *bool `db:"unsuccessful_external_commit_statuses" json:",omitempty"`

	// UseSSHPrivateKey is whether Sourcegraph should clone and update
	// the repository using an SSH key, and whether it should copy the
	// corresponding public key to the repository's origin host as an
	// authorized key. It is only necessary for private repositories
	// and for write operations on public repositories.
	UseSSHPrivateKey *bool `db:"use_ssh_private_key" json:",omitempty"`
}

RepoSettings describes a repository's configuration settings.

type RepoSpec

type RepoSpec struct {
	URI string
	RID int
}

RepoSpec specifies a repository.

func ParseRepoSpec

func ParseRepoSpec(pathComponent string) (RepoSpec, error)

ParseRepoSpec parses a string generated by (*RepoSpec).PathComponent() and returns the equivalent RepoSpec struct.

func UnmarshalRepoSpec

func UnmarshalRepoSpec(routeVars map[string]string) (RepoSpec, error)

UnmarshalRepoSpec marshals a map containing route variables generated by (*RepoSpec).RouteVars() and returns the equivalent RepoSpec struct.

func (RepoSpec) PathComponent

func (s RepoSpec) PathComponent() string

PathComponent returns the URL path component that specifies the repository.

func (RepoSpec) RouteVars

func (s RepoSpec) RouteVars() map[string]string

RouteVars returns route variables for constructing repository routes.

type RepoStatType

type RepoStatType string

StatType is the name of a repository statistic (see below for a listing).

func (*RepoStatType) Scan

func (x *RepoStatType) Scan(v interface{}) error

Scan implements database/sql.Scanner.

func (RepoStatType) Value

func (x RepoStatType) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer.

type RepoStats

type RepoStats map[RepoStatType]int

Stats holds statistics for a repository.

type RepoStatus

type RepoStatus struct {
	github.RepoStatus
}

type RepoToken

type RepoToken struct {
	URI string

	Repo *Repo `json:",omitempty"`
}

A RepoToken represents a repository, although it does not necessarily uniquely identify the repository. It consists of any number of slash-separated path components, such as "a/b" or "github.com/foo/bar".

func (RepoToken) Spec

func (t RepoToken) Spec() RepoSpec

func (RepoToken) String

func (t RepoToken) String() string

type RepoTreeGetOptions

type RepoTreeGetOptions struct {
	// Formatted is whether the specified entry, if it's a file, should have its
	// Contents code-formatted using HTML.
	Formatted bool

	// HighlightStrings is a list of fixed strings that should be
	// wrapped in a <span class="highlight"> in the returned HTML. It
	// only takes effect if Formatted is true.
	HighlightStrings []string

	// TokenizedSource requests that the source code be returned as a tokenized data
	// structure rather than an (annotated) string.
	//
	// This is useful when the client wants to take full control of rendering and manipulating
	// the contents.
	TokenizedSource bool `url:",omitempty"`

	ContentsAsString bool `url:",omitempty"`

	vcsclient.GetFileOptions
}

RepoTreeGetOptions specifies options for (RepoTreeService).Get.

type RepoTreeSearchOptions

type RepoTreeSearchOptions struct {
	vcs.SearchOptions
	Formatted bool
}

type RepoTreeSearchResult

type RepoTreeSearchResult struct {
	vcs.SearchResult
	RepoRev RepoRevSpec
}

A RepoTreeSearchResult is a tree search result that includes the repo and rev it came from.

type RepoTreeService

type RepoTreeService interface {
	Get(entry TreeEntrySpec, opt *RepoTreeGetOptions) (*TreeEntry, Response, error)
	Search(RepoRevSpec, *RepoTreeSearchOptions) ([]*vcs.SearchResult, Response, error)
}

RepoTreeService communicates with the Sourcegraph API endpoints that fetch file and directory entries in repositories.

type RepoUsageByClient

type RepoUsageByClient struct {
	// DefRepo is the repository that defines the code that was referenced.
	// It's called DefRepo because "Repo" usually refers to the repository
	// whose analysis created this linkage (i.e., the repository that contains
	// the reference).
	DefRepo string `db:"def_repo"`

	RefCount int `db:"ref_count"`

	AuthorshipInfo
}

RepoUsageByClient describes a repository whose code is referenced by a specific person.

type RepoUsageOfAuthor

type RepoUsageOfAuthor struct {
	Repo string

	RefCount int `db:"ref_count"`
}

RepoUsageOfAuthor describes a repository referencing code committed by a specific person.

type Repos

type Repos []*Repo

func (Repos) URIs

func (rs Repos) URIs() (uris []string)

type ReposService

type ReposService interface {
	// Get fetches a repository.
	Get(repo RepoSpec, opt *RepoGetOptions) (*Repo, Response, error)

	// GetStats gets statistics about a repository at a specific
	// commit. Some statistics are per-commit and some are global to
	// the repository. If you only care about global repository
	// statistics, pass an empty Rev to the RepoRevSpec (which will be
	// resolved to the repository's default branch).
	GetStats(repo RepoRevSpec) (RepoStats, Response, error)

	// CreateStatus creates a repository status for the given commit.
	CreateStatus(spec RepoRevSpec, st RepoStatus) (*RepoStatus, Response, error)

	// GetCombinedStatus fetches the combined repository status for
	// the given commit.
	GetCombinedStatus(spec RepoRevSpec) (*CombinedStatus, Response, error)

	// GetOrCreate fetches a repository using Get. If no such repository exists
	// with the URI, and the URI refers to a recognized repository host (such as
	// github.com), the repository's information is fetched from the external
	// host and the repository is created.
	GetOrCreate(repo RepoSpec, opt *RepoGetOptions) (*Repo, Response, error)

	// GetSettings fetches a repository's configuration settings.
	GetSettings(repo RepoSpec) (*RepoSettings, Response, error)

	// UpdateSettings updates a repository's configuration settings.
	UpdateSettings(repo RepoSpec, settings RepoSettings) (Response, error)

	// RefreshProfile updates the repository metadata for a repository, fetching
	// it from an external host if the host is recognized (such as GitHub).
	//
	// This operation is performed asynchronously on the server side (after
	// receiving the request) and the API currently has no way of notifying
	// callers when the operation completes.
	RefreshProfile(repo RepoSpec) (Response, error)

	// RefreshVCSData updates the repository VCS (git/hg) data, fetching all new
	// commits, branches, tags, and blobs.
	//
	// This operation is performed asynchronously on the server side (after
	// receiving the request) and the API currently has no way of notifying
	// callers when the operation completes.
	RefreshVCSData(repo RepoSpec) (Response, error)

	// ComputeStats updates the statistics about a repository.
	//
	// This operation is performed asynchronously on the server side (after
	// receiving the request) and the API currently has no way of notifying
	// callers when the operation completes.
	ComputeStats(repo RepoRevSpec) (Response, error)

	// GetBuild gets the build for a specific revspec. It returns
	// additional information about the build, such as whether it is
	// exactly up-to-date with the revspec or a few commits behind the
	// revspec. The opt param controls what is returned in this case.
	GetBuild(repo RepoRevSpec, opt *RepoGetBuildOptions) (*RepoBuildInfo, Response, error)

	// Create adds the repository at cloneURL, filling in all information about
	// the repository that can be inferred from the URL (or, for GitHub
	// repositories, fetched from the GitHub API). If a repository with the
	// specified clone URL, or the same URI, already exists, it is returned.
	Create(newRepoSpec NewRepoSpec) (*Repo, Response, error)

	// GetReadme fetches the formatted README file for a repository.
	GetReadme(repo RepoRevSpec) (*vcsclient.TreeEntry, Response, error)

	// List repositories.
	List(opt *RepoListOptions) ([]*Repo, Response, error)

	// List commits.
	ListCommits(repo RepoSpec, opt *RepoListCommitsOptions) ([]*Commit, Response, error)

	// GetCommit gets a commit.
	GetCommit(rev RepoRevSpec, opt *RepoGetCommitOptions) (*Commit, Response, error)

	// ListBranches lists a repository's branches.
	ListBranches(repo RepoSpec, opt *RepoListBranchesOptions) ([]*vcs.Branch, Response, error)

	// ListTags lists a repository's tags.
	ListTags(repo RepoSpec, opt *RepoListTagsOptions) ([]*vcs.Tag, Response, error)

	// ListBadges lists the available badges for repo.
	ListBadges(repo RepoSpec) ([]*Badge, Response, error)

	// ListCounters lists the available counters for repo.
	ListCounters(repo RepoSpec) ([]*Counter, Response, error)

	// ListAuthors lists people who have contributed (i.e., committed) code to
	// repo.
	ListAuthors(repo RepoRevSpec, opt *RepoListAuthorsOptions) ([]*AugmentedRepoAuthor, Response, error)

	// ListClients lists people who reference defs defined in repo.
	ListClients(repo RepoSpec, opt *RepoListClientsOptions) ([]*AugmentedRepoClient, Response, error)

	// ListDependents lists repositories that contain defs referenced by
	// repo.
	ListDependencies(repo RepoRevSpec, opt *RepoListDependenciesOptions) ([]*AugmentedRepoDependency, Response, error)

	// ListDependents lists repositories that reference defs defined in repo.
	ListDependents(repo RepoSpec, opt *RepoListDependentsOptions) ([]*AugmentedRepoDependent, Response, error)

	// ListByContributor lists repositories that user has contributed (i.e.,
	// committed) code to.
	ListByContributor(user UserSpec, opt *RepoListByContributorOptions) ([]*AugmentedRepoContribution, Response, error)

	// ListByClient lists repositories that contain defs referenced by
	// user.
	ListByClient(user UserSpec, opt *RepoListByClientOptions) ([]*AugmentedRepoUsageByClient, Response, error)

	// ListByRefdAuthor lists repositories that reference code authored by
	// user.
	ListByRefdAuthor(user UserSpec, opt *RepoListByRefdAuthorOptions) ([]*AugmentedRepoUsageOfAuthor, Response, error)
}

ReposService communicates with the repository-related endpoints in the Sourcegraph API.

type ResolvedQuery

type ResolvedQuery struct {
	// Tokens are resolved tokens, each of whose meaning is
	// unambiguous.
	Tokens []Token
}

A ResolvedQuery is a query that has been parsed and resolved so that each token is given an unambiguous meaning.

type Response

type Response interface {
	// TotalCount is the total number of items in the resource or result set
	// that exist remotely. Only a portion of the total may be in the response
	// body. If the endpoint did not return a total count, then TotalCount
	// returns -1.
	TotalCount() int
}

Response is a response from the Sourcegraph API. When using the HTTP API, API methods return *HTTPResponse values that implement Response.

type RevToken

type RevToken struct {
	Rev string // Rev is either a revspec or commit ID

	Commit *Commit `json:",omitempty"`
}

A RevToken represents a specific revision (either a revspec or a commit ID) of a repository (which must be specified by a previous RepoToken in the query).

func (RevToken) String

func (t RevToken) String() string

type SearchOptions

type SearchOptions struct {
	Query string `url:"q" schema:"q"`

	Defs   bool
	Repos  bool
	People bool
	Tree   bool

	ListOptions
}

type SearchResults

type SearchResults struct {
	Defs   []*Def                  `json:",omitempty"`
	People []*Person               `json:",omitempty"`
	Repos  []*Repo                 `json:",omitempty"`
	Tree   []*RepoTreeSearchResult `json:",omitempty"`

	// RawQuery is the raw query passed to search.
	RawQuery RawQuery

	// Tokens are the unresolved tokens.
	Tokens Tokens `json:",omitempty"`

	// Plan is the query plan used to fetch the results.
	Plan *Plan `json:",omitempty"`

	// ResolvedTokens holds the resolved tokens from the original query
	// string.
	ResolvedTokens Tokens

	ResolveErrors []TokenError `json:",omitempty"`

	// Tips are helpful tips for the user about their query. They are
	// not errors per se, but they use the TokenError type because it
	// allows us to associate a message with a particular token (and
	// JSON de/serialize that).
	Tips []TokenError `json:",omitempty"`

	// Canceled is true if the query was canceled. More information
	// about how to correct the issue can be found in the
	// ResolveErrors and Tips.
	Canceled bool
}

func (*SearchResults) Empty

func (r *SearchResults) Empty() bool

Empty is whether there are no search results for any result type.

type SearchService

type SearchService interface {
	// Search searches the full index.
	Search(opt *SearchOptions) (*SearchResults, Response, error)

	// Complete completes the token at the RawQuery's InsertionPoint.
	Complete(q RawQuery) (*Completions, Response, error)

	// Suggest suggests queries given an existing query. It can be
	// called with an empty query to get example queries that pertain
	// to the current user's repositories, orgs, etc.
	Suggest(q RawQuery) ([]*Suggestion, Response, error)
}

SearchService communicates with the search-related endpoints in the Sourcegraph API.

type SourceCode

type SourceCode struct {
	// Lines contains all the lines of the contained code snippet.
	Lines []*SourceCodeLine `json:",omitempty"`

	NumRefs     int
	TooManyRefs bool
}

SourceCode contains a snippet of code with linked and classed tokens, along with other information about the contents.

This data structure is useful when one desires to take full control of rendering and manipulating the contents of the requested TreeEntry or snippet, rather than dealing with an (annotated) string or parsing text. To obtain this strcture in the TreeEntry, TokenizedSource must be set to "true" in the RepoTreeGetOptions.

type SourceCodeLine

type SourceCodeLine struct {
	// StartByte and EndByte are the start and end offsets in bytes, in the original file.
	StartByte int
	EndByte   int

	// Tokens contains any tokens that may be on this line, including whitespace. Whitespace
	// is stored as an HTML encoded "string" and token information is stored as
	// "SourceCodeToken". New lines ('\n') are not present.
	Tokens []interface{} `json:",omitempty"`
}

SourceCodeLine contains all tokens on this line along with other information such as byte offsets in original source.

type SourceCodeToken

type SourceCodeToken struct {
	// Start and end byte offsets in original file.
	StartByte int `json:"-"`
	EndByte   int `json:"-"`

	// If the token is a reference URL contains the DefKey-based URLs for all the
	// definitions at this position.
	URL []string `json:",omitempty"`

	// IsDef specifies whether the token is a definition.
	IsDef bool `json:",omitempty"`

	// Class specifies the token type as per
	// [google-code-prettify](https://code.google.com/p/google-code-prettify/).
	Class string

	// Label is non-whitespace HTML encoded source code.
	Label string
}

SourceCodeToken contains information about a code token.

type Sourcebox

type Sourcebox struct {
	// HTML is the fully linked and rendered HTML of the sourcebox
	// contents and surrounding box UI element.
	HTML template.HTML

	// StylesheetURL is the URL to a CSS stylesheet that must be
	// included on the web page where this sourcebox is shown. It only
	// needs to be included once per web page, even if there are
	// multiple sourceboxes, and all sourceboxes' StylesheetURL is the same.
	StylesheetURL string

	// ScriptURL is the URL to a JavaScript script that must be
	// included and executed on the page in order to display tooltips
	// and certain highlights. It only needs to be included once per
	// web page, even if there are multiple sourceboxes, and all
	// sourceboxes' StylesheetURL is the same.
	ScriptURL string
}

A Sourcebox represents an embeddable code snippet, either for a file (or portion thereof) or for a def.

It is not currently returned by any API client methods, but it is available by changing the ".js" suffix in a Sourcebox embed URL to ".json". This struct is provided for clients that manually construct this URL to decode the response JSON.

type Suggestion

type Suggestion struct {
	// Query is a suggested query related to the original query.
	Query Tokens

	// QueryString is what the user needs to enter into the search
	// field to search using this suggested query.
	QueryString string

	// Description is the human-readable description of Query (usually
	// generated by calling the Describe func).
	Description string `json:",omitempty"`
}

A Suggestion is a possible completion of a query (returned by Suggest method). It does not attempt to "complete" a query but rather indicate to the user what types of queries are possible.

type TaskSpec

type TaskSpec struct {
	BuildSpec
	TaskID int64
}

func (TaskSpec) IDString

func (t TaskSpec) IDString() string

IDString returns a succinct string that uniquely identifies this build task.

func (*TaskSpec) RouteVars

func (s *TaskSpec) RouteVars() map[string]string

type TaskUpdate

type TaskUpdate struct {
	StartedAt *time.Time
	EndedAt   *time.Time
	Success   *bool
	Failure   *bool
}

A TaskUpdate contains updated information to update on an existing task.

type Term

type Term string

A Term is a query term token. It is either a word or an arbitrary string (if quoted in the raw query).

func (Term) String

func (t Term) String() string

func (Term) UnquotedString

func (t Term) UnquotedString() string

type Token

type Token interface {
	// String returns the string representation of the term.
	String() string
}

A Token is the smallest indivisible component of a query, either a term or a "field:val" specifier (e.g., "repo:example.com/myrepo").

type TokenError

type TokenError struct {
	// Index is the 1-indexed index of the token that caused the error
	// (0 means not associated with any particular token).
	//
	// NOTE: Index is 1-indexed (not 0-indexed) because some
	// TokenErrors don't pertain to a token, and it's misleading if
	// the Index in the JSON is 0 (which could mean that it pertains
	// to the 1st token if index was 0-indexed).
	Index int `json:",omitempty"`

	Token   Token  `json:",omitempty"` // the token that caused the error
	Message string // the public, user-readable error message to display
}

A TokenError is an error about a specific token.

func (TokenError) Error

func (e TokenError) Error() string

func (TokenError) MarshalJSON

func (e TokenError) MarshalJSON() ([]byte, error)

func (*TokenError) UnmarshalJSON

func (e *TokenError) UnmarshalJSON(b []byte) error

type Tokens

type Tokens []Token

Tokens wraps a list of tokens and adds some helper methods. It also serializes to JSON with "Type" fields added to each token and deserializes that same JSON back into a typed list of tokens.

func (Tokens) MarshalJSON

func (d Tokens) MarshalJSON() ([]byte, error)

func (Tokens) RawQueryString

func (d Tokens) RawQueryString() string

func (*Tokens) UnmarshalJSON

func (d *Tokens) UnmarshalJSON(b []byte) error

type TreeEntry

type TreeEntry struct {
	*vcsclient.TreeEntry

	*vcsclient.FileRange // only set for files

	ContentsString string `json:",omitempty"`

	// SourceCode is set when TokenizedSource is enabled in RepoTreeGetOptions.
	SourceCode *SourceCode `json:",omitempty"`

	// FormatResult is only set if this TreeEntry is a file.
	FormatResult *FormatResult `json:",omitempty"`
}

TreeEntry is a file or directory in a repository, with additional feedback from the formatting operation (if Formatted is true in the options).

type TreeEntrySpec

type TreeEntrySpec struct {
	RepoRev RepoRevSpec
	Path    string
}

func (*TreeEntrySpec) RouteVars

func (s *TreeEntrySpec) RouteVars() map[string]string

func (TreeEntrySpec) String

func (s TreeEntrySpec) String() string

type UnitDelta

type UnitDelta struct {
	Base *unit.SourceUnit // the unit in the base commit (if nil, this unit was added in the head)
	Head *unit.SourceUnit // the unit in the head commit (if nil, this unit was deleted in the head)
}

A UnitDelta represents a single source unit that was changed. It has fields for the before (Base) and after (Head) versions. If both Base and Head are non-nil, then the unit was changed from base to head. Otherwise, one of the fields being nil means that the unit did not exist in that revision (e.g., it was added or deleted from base to head).

func (UnitDelta) Added

func (ud UnitDelta) Added() bool

Added is whether this represents an added source unit (not present in base, present in head).

func (UnitDelta) Changed

func (ud UnitDelta) Changed() bool

Changed is whether this represents a changed source unit (present in base, present in head).

func (UnitDelta) Deleted

func (ud UnitDelta) Deleted() bool

Deleted is whether this represents a deleted source unit (present in base, not present in head).

type UnitDeltas

type UnitDeltas []*UnitDelta

func (UnitDeltas) Len

func (v UnitDeltas) Len() int

func (UnitDeltas) Less

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

func (UnitDeltas) Swap

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

type UnitListOptions

type UnitListOptions struct {
	// RepoRevs constrains the results to a set of repository
	// revisions (given by their URIs plus an optional "@" and a
	// revision specifier). For example, "repo.com/foo@revspec".
	RepoRevs []string `url:",omitempty,comma" json:",omitempty"`

	UnitType string `url:",omitempty"`
	Unit     string `url:",omitempty"`

	// NameQuery specifies a full-text search query over the unit
	// name.
	NameQuery string `url:",omitempty" json:",omitempty"`

	// Query specifies a full-text search query over the repo URI,
	// unit name, and unit data.
	Query string `url:",omitempty" json:",omitempty"`

	// Paging
	ListOptions
}

UnitListOptions specifies options for UnitsService.List.

type UnitSpec

type UnitSpec struct {
	RepoRevSpec
	UnitType string
	Unit     string
}

UnitSpec specifies a source unit.

func NewUnitSpecFromUnit

func NewUnitSpecFromUnit(u *unit.RepoSourceUnit) UnitSpec

func UnmarshalUnitSpec

func UnmarshalUnitSpec(vars map[string]string) (UnitSpec, error)

func (UnitSpec) RouteVars

func (s UnitSpec) RouteVars() map[string]string

type UnitToken

type UnitToken struct {
	// UnitType is the type of the source unit (e.g., GoPackage).
	UnitType string

	// Name is the name of the source unit (e.g., mypkg).
	Name string

	// Unit is the source unit object.
	Unit *unit.RepoSourceUnit
}

A UnitToken represents a source unit in a repository.

func (UnitToken) String

func (t UnitToken) String() string

type UnitsService

type UnitsService interface {
	// Get fetches a unit.
	Get(spec UnitSpec) (*unit.RepoSourceUnit, Response, error)

	// List units.
	List(opt *UnitListOptions) ([]*unit.RepoSourceUnit, Response, error)
}

UnitsService communicates with the source unit-related endpoints in the Sourcegraph API.

type User

type User struct {
	// UID is the numeric primary key for a user.
	UID int `db:"uid"`

	// GitHubID is the numeric ID of the GitHub user account corresponding to
	// this user.
	GitHubID nnz.Int `db:"github_id"`

	// Login is the user's username, which typically corresponds to the user's
	// GitHub login.
	Login string

	// Name is the (possibly empty) full name of the user.
	Name string

	// Type is either "User" or "Organization".
	Type string

	// AvatarURL is the URL to an avatar image specified by the user.
	AvatarURL string

	// Location is the user's physical location (from their GitHub profile).
	Location string `json:",omitempty"`

	// Company is the user's company (from their GitHub profile).
	Company string `json:",omitempty"`

	// HomepageURL is the user's homepage or blog URL (from their GitHub
	// profile).
	HomepageURL string `db:"homepage_url" json:",omitempty"`

	// UserProfileDisabled is whether the user profile should not be displayed
	// on the Web app.
	UserProfileDisabled bool `db:"user_profile_disabled" json:",omitempty"`

	// RegisteredAt is the date that the user registered. If the user has not
	// registered (i.e., we have processed their repos but they haven't signed
	// into Sourcegraph), it is null.
	RegisteredAt db_common.NullTime `db:"registered_at"`

	// Stat contains statistics about this user. It's only filled in
	// by certain API responses.
	Stat PersonStats `db:"-" json:",omitempty"`
}

User represents a registered user.

func (*User) AvatarURLOfSize

func (u *User) AvatarURLOfSize(width int) string

AvatarURLOfSize returns the URL to an avatar for the user with the given width (in pixels).

func (*User) CanAttributeCodeTo

func (u *User) CanAttributeCodeTo() bool

CanAttributeCodeTo is whether this user can commit code. It is false for organizations and true for both users and transient users.

func (*User) CanOwnRepositories

func (u *User) CanOwnRepositories() bool

CanOwnRepositories is whether the user is capable of owning repositories (e.g., GitHub users can own GitHub repositories).

func (*User) GitHubLogin

func (u *User) GitHubLogin() string

GitHubLogin returns the user's Login. They are the same for now, but callers that intend to get the GitHub login should call GitHubLogin() so that we can decouple the logins in the future if needed.

func (*User) IsOrganization

func (u *User) IsOrganization() bool

IsOrganization is whether this user represents a GitHub organization (which are treated as a subclass of User in GitHub's data model).

func (*User) Person

func (u *User) Person() *Person

Person returns an equivalent Person.

func (*User) Spec

func (u *User) Spec() UserSpec

type UserGetOptions

type UserGetOptions struct {
	// Stats is whether to include statistics about the user in the response.
	Stats bool `url:",omitempty"`
}

type UserSettings

type UserSettings struct {
	// RequestedUpgradeAt is the date on which a user requested an upgrade
	RequestedUpgradeAt db_common.NullTime `json:",omitempty"`

	PlanSettings `json:",omitempty"`
}

UserSettings describes a user's configuration settings.

type UserSpec

type UserSpec struct {
	// Login is a user's login.
	Login string

	// UID is a user's UID.
	UID int
}

UserSpec specifies a user. At least one of Login, and UID must be nonempty.

func ParseUserSpec

func ParseUserSpec(pathComponent string) (UserSpec, error)

ParseUserSpec parses a string generated by (*UserSpec).String() and returns the equivalent UserSpec struct.

func (*UserSpec) PathComponent

func (s *UserSpec) PathComponent() string

PathComponent returns the URL path component that specifies the user.

func (*UserSpec) RouteVars

func (s *UserSpec) RouteVars() map[string]string

type UserToken

type UserToken struct {
	Login string

	User *User `json:",omitempty"`
}

A UserToken represents a user or org, although it does not necessarily uniquely identify one. It consists of the string "@" followed by a full or partial user/org login.

func (UserToken) String

func (t UserToken) String() string

type UsersListAuthorsOptions

type UsersListAuthorsOptions UsersListOptions

UsersListAuthorsOptions specifies options for the UsersService.ListAuthors method.

type UsersListClientsOptions

type UsersListClientsOptions UsersListOptions

UsersListClientsOptions specifies options for the UsersService.ListClients method.

type UsersListOptions

type UsersListOptions struct {
	// Query filters the results to only those whose logins match. The
	// search algorithm is an implementation detail (currently it is a
	// prefix match).
	Query string `url:",omitempty" json:",omitempty"`

	Sort      string `url:",omitempty" json:",omitempty"`
	Direction string `url:",omitempty" json:",omitempty"`

	ListOptions
}

UsersListOptions specifies options for the UsersService.List method.

type UsersListOrgsOptions

type UsersListOrgsOptions struct {
	ListOptions
}

type UsersService

type UsersService interface {
	// Get fetches a user.
	Get(user UserSpec, opt *UserGetOptions) (*User, Response, error)

	// GetSettings fetches a user's configuration settings. If err is
	// nil, then the returned UserSettings must be non-nil.
	GetSettings(user UserSpec) (*UserSettings, Response, error)

	// UpdateSettings updates an user's configuration settings.
	UpdateSettings(user UserSpec, settings UserSettings) (Response, error)

	// ListEmails returns a list of a user's email addresses.
	ListEmails(user UserSpec) ([]*EmailAddr, Response, error)

	// GetOrCreateFromGitHub creates a new user based a GitHub user.
	GetOrCreateFromGitHub(user GitHubUserSpec, opt *UserGetOptions) (*User, Response, error)

	// RefreshProfile updates the user's profile information from external
	// sources, such as GitHub.
	//
	// This operation is performed asynchronously on the server side
	// (after receiving the request) and the API currently has no way
	// of notifying callers when the operation completes.
	RefreshProfile(userSpec UserSpec) (Response, error)

	// ComputeStats recomputes statistics about the user.
	//
	// This operation is performed asynchronously on the server side
	// (after receiving the request) and the API currently has no way
	// of notifying callers when the operation completes.
	ComputeStats(userSpec UserSpec) (Response, error)

	// List users.
	List(opt *UsersListOptions) ([]*User, Response, error)

	// ListAuthors lists users who authored code that user uses.
	ListAuthors(user UserSpec, opt *UsersListAuthorsOptions) ([]*AugmentedPersonUsageByClient, Response, error)

	// ListClients lists users who use code that user authored.
	ListClients(user UserSpec, opt *UsersListClientsOptions) ([]*AugmentedPersonUsageOfAuthor, Response, error)

	// ListOrgs lists organizations that a user is a member of.
	ListOrgs(member UserSpec, opt *UsersListOrgsOptions) ([]*Org, Response, error)
}

UsersService communicates with the users-related endpoints in the Sourcegraph API.

Jump to

Keyboard shortcuts

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