gerrit

package
v0.0.0-...-53353bc Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package gerrit provides library functions for interacting with the gerrit code review system.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRedirectOnGerrit       = errors.New("got redirection while downloading file from gerrit server")
	ErrRedirectOnGerritSSO    = errors.New("got redirection while downloading file from gerrit server using SSO cookie")
	ErrCookieNotExist         = errors.New("cookie file not found")
	ErrSSOPathNotSet          = errors.New("master SSO cookie path is not set, please run \"jiri init --sso-cookie-path PATH_TO_SSO\" and try again")
	ErrSSOCookieExpireInvalid = errors.New("SSO cookie is either invalid or expired, please run \"glogin\" and try again")
	ErrHTTPForbidden          = errors.New("server return HTTP 403, cookies are not accepted")
)
View Source
var (
	// ErrCloneBundleNotAvailable will be returned from FetchCloneBundle
	// if clone.bundle file does not exist or cannot be fetched from remote.
	ErrCloneBundleNotAvailable = errors.New("git clone bundle not available")
)

Functions

func BootstrapGerritSSO

func BootstrapGerritSSO(jirix *jiri.X)

BootstrapGerritSSO will setup cookie cache for SSO cookies and setup the path for master SSO cookie. Due to security concerns, we cannot hard code sso cookie paths in jiri, instead, we ask user to supply path to master sso cookie path using "jiri init --sso-cookie-path" command.

func CacheCookies

func CacheCookies(jiriCookiePath, hostName string, cookiejar *ssoCookieJar) error

CacheCookies saves the gerrit SSO cookie back jiriCookiePath file. As there is a limit on how many SSO cookies can be requested per hour, caching the gerrit SSO cookie allows jiri to avoid hitting the limiter.

func FetchCloneBundle

func FetchCloneBundle(jirix *jiri.X, remote, dir string) (string, error)

FetchCloneBundle fetches git clone.bundle file from remote and save it to dir/clone.bundle . If if clone.bundle file does not exist or cannot be fetched from remote, ErrCloneBundleNotAvailable will be returned.

func FetchFile

func FetchFile(gerritHost, path string) ([]byte, error)

FetchFile downloads a file and returns its content to a byte slice. It will return ErrRedirectOnGerrit if redirection is detected, which indicates that user authentication is required.

func FetchFileSSO

func FetchFileSSO(jirix *jiri.X, gerritHost, path string) ([]byte, error)

FetchFileSSO downloads a file from a gerrit host that requires SSO login and returns its content to a byte slice. Since it uses user's master SSO cookie, the scheme of the url should always be HTTPS, otherwise an error will be returned.

func LoadCookies

func LoadCookies(jirix *jiri.X, jiriCookiePath, hostName string, cookieType CookieType) (*ssoCookieJar, error)

LoadCookies loads necessary cookies from various sources (master sso, gitcookies and cached jiricookies), returning a cookiejar that contains necessary cookies to login to the hostName. An error will be returned if no suitable cookie is found or if there is an I/O error.

func MarshalNSCookieData

func MarshalNSCookieData(cookies []*http.Cookie) ([]byte, error)

MarshalNSCookieData packs the slice of golang cookies into the Netscape-format cookies.

func ParseRefString

func ParseRefString(ref string) (int, int, error)

ParseRefString parses the cl and patchset number from the given ref string.

func PresubmitTestTypes

func PresubmitTestTypes() []string

func Push

func Push(jirix *jiri.X, dir string, clOpts CLOpts) error

Push pushes the current branch to Gerrit.

func Reference

func Reference(opts CLOpts) string

Reference inputs CL options and returns a matching string representation of a Gerrit reference.

func UnmarshalNSCookieData

func UnmarshalNSCookieData(data []byte) ([]*http.Cookie, error)

UnmarshalNSCookieData parses the Netscape-format cookies from data and return a slice of golang cookies.

func WriteLog

func WriteLog(logFilePath string, cls CLList) (e error)

WriteLog writes the given list of CLs to a log file, as a json-encoded map of ref strings => CLs.

Types

type CLList

type CLList []Change

The following types reflect the schema Gerrit uses to represent CLs.

func NewOpenCLs

func NewOpenCLs(prevCLsMap CLRefMap, curCLs CLList) ([]CLList, []error)

NewOpenCLs returns a slice of CLLists that are "newer" relative to the previous query. A CLList is newer if one of the following condition holds: - If a CLList has only one cl, then it is newer if:

  • Its ref string cannot be found among the CLs from the previous query.

    For example: from the previous query, we got cl 1000/1 (cl number 1000 and patchset 1). Then CLLists 1000/2 and 2000/1 are both newer.

- If a CLList has multiple CLs, then it is newer if:

  • It forms a "consistent" (its CLs have the same topic) and "complete" (it contains all the parts) multi-part CL set.

  • At least one of their ref strings cannot be found in the CLs from the previous query.

    For example: from the previous query, we got cl 3001/1 which is the first part of a multi part cl set with topic "T1". Suppose the current query returns cl 3002/1 which is the second part of the same set. In this case, a CLList [3001/1 3002/1] will be returned. Then suppose in the next query, we got cl 3002/2 which is newer then 3002/1. In this case, a CLList [3001/1 3002/2] will be returned.

type CLOpts

type CLOpts struct {
	// Autosubmit determines if the CL should be auto-submitted when it
	// meets the submission rules.
	Autosubmit bool
	// Ccs records a list of email addresses to cc on the CL.
	Ccs []string
	// Draft determines if this CL is a draft.
	Draft bool
	// Edit determines if the user should be prompted to edit the commit
	// message when the CL is exported to Gerrit.
	Edit bool
	// GitOptions pass through additional git options
	GitOptions string
	// Labels records a list of labels needs to pass through gerrit.
	Labels []string
	// Remote identifies the Gerrit remote that this CL will be pushed to
	Remote string
	// Presubmit determines what presubmit tests to run.
	Presubmit PresubmitTestType
	// RemoteBranch identifies the remote branch the CL pertains to.
	RemoteBranch string
	// Reviewers records a list of email addresses of CL reviewers.
	Reviewers []string
	// Topic records the CL topic.
	Topic string
	// Verify controls whether git pre-push hooks should be run before uploading.
	Verify bool
	//Ref to upload. Default is HEAD
	RefToUpload string
}

CLOpts records the review options.

type CLRefMap

type CLRefMap map[string]Change

func ReadLog

func ReadLog(logFilePath string) (CLRefMap, error)

ReadLog returns a map of CLs indexed by their refs, read from the given log file.

type Change

type Change struct {
	// CL data.
	Change_id        string
	Current_revision string
	Project          string
	Topic            string
	Branch           string
	Revisions        Revisions
	Subject          string
	Number           int `json:"_number"`
	Owner            Owner
	Labels           map[string]map[string]interface{}
	Submitted        string

	// Custom labels.
	AutoSubmit    bool
	MultiPart     *MultiPartCLInfo
	PresubmitTest PresubmitTestType
}

func GenCL

func GenCL(clNumber, patchset int, project string) Change

func GenCLWithMoreData

func GenCLWithMoreData(clNumber, patchset int, project string, presubmit PresubmitTestType, ownerEmail string) Change

func GenMultiPartCL

func GenMultiPartCL(clNumber, patchset int, project, topic string, index, total int) Change

func GenMultiPartCLWithMoreData

func GenMultiPartCLWithMoreData(clNumber, patchset int, project, topic string, index, total int, ownerEmail string) Change

func (Change) OwnerEmail

func (c Change) OwnerEmail() string

func (Change) Reference

func (c Change) Reference() string

type ChangeError

type ChangeError struct {
	Err error
	CL  Change
}

func NewChangeError

func NewChangeError(cl Change, err error) *ChangeError

func (*ChangeError) Error

func (ce *ChangeError) Error() string

type Comment

type Comment struct {
	Line    int    `json:"line,omitempty"`
	Message string `json:"message,omitempty"`
}

Comment represents a single inline file comment.

type Commit

type Commit struct {
	Parents []Parent
	Message string
}

type CookieType

type CookieType int

CookieType specifies the type of cookies should be loaded by LoadCookies function.

const (
	// GitCookieOnly specifies that only git cookies should be loaded by
	// LoadCookies function.
	GitCookieOnly CookieType = iota
	// SiteSSO specifies that site SSO cookie should be loaded from jiri
	// cookie cache by LoadCookies function. If it is not found or experied,
	// The combination of master SSO and git cookies should be loaded.
	SiteSSO
	// MasterSSO specifies that the combination of master SSO and git cookies
	// should be loaded by LoadCookies function regardless of the status of
	// site SSO cookie.
	MasterSSO
)

type Fetch

type Fetch struct {
	Http `json:"http"`
}

type Files

type Files map[string]struct{}

type Gerrit

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

Gerrit records a hostname of a Gerrit instance.

func New

func New(jirix *jiri.X, host *url.URL) *Gerrit

New is the Gerrit factory.

func (*Gerrit) GetChange

func (g *Gerrit) GetChange(changeNumber int) (*Change, error)

GetChange returns a Change object for the given changeId number.

func (*Gerrit) GetChangeByID

func (g *Gerrit) GetChangeByID(changeID string) (*Change, error)

func (*Gerrit) GetChangeURL

func (g *Gerrit) GetChangeURL(changeNumber int) string

func (*Gerrit) GetRelatedChanges

func (g *Gerrit) GetRelatedChanges(changeNumber int, revisionId string) (*RelatedChanges, error)

func (*Gerrit) ListChangesByCommit

func (g *Gerrit) ListChangesByCommit(commit string) (CLList, error)

func (*Gerrit) ListOpenChangesByTopic

func (g *Gerrit) ListOpenChangesByTopic(topic string) (CLList, error)

func (*Gerrit) PostReview

func (g *Gerrit) PostReview(ref string, message string, labels map[string]string) (e error)

PostReview posts a review to the given Gerrit reference.

func (*Gerrit) Query

func (g *Gerrit) Query(query string) (_ CLList, e error)

Query returns a list of QueryResult entries matched by the given Gerrit query string from the given Gerrit instance. The result is sorted by the last update time, most recently updated to oldest updated.

See the following links for more details about Gerrit search syntax: - https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes - https://gerrit-review.googlesource.com/Documentation/user-search.html

func (*Gerrit) SetTopic

func (g *Gerrit) SetTopic(cl string, opts CLOpts) (e error)

SetTopic sets the topic of the given Gerrit reference.

func (*Gerrit) Submit

func (g *Gerrit) Submit(changeID string) (e error)

Submit submits the given changelist through Gerrit.

type Http

type Http struct {
	Ref string
}

type MultiPartCLInfo

type MultiPartCLInfo struct {
	Topic string
	Index int // This should be 1-based.
	Total int
}

MultiPartCLInfo contains data used to process multiple cls across different projects.

type MultiPartCLSet

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

MultiPartCLSet represents a set of CLs that spans multiple projects.

func NewMultiPartCLSet

func NewMultiPartCLSet() *MultiPartCLSet

NewMultiPartCLSet creates a new instance of MultiPartCLSet.

func (*MultiPartCLSet) AddCL

func (s *MultiPartCLSet) AddCL(cl Change) error

AddCL adds a CL to the set after it passes a series of checks.

func (*MultiPartCLSet) CLs

func (s *MultiPartCLSet) CLs() CLList

CLs returns a list of CLs in this set sorted by their part number.

func (*MultiPartCLSet) Complete

func (s *MultiPartCLSet) Complete() bool

Complete returns whether the current set has all the cl parts it needs.

type Owner

type Owner struct {
	Name  string
	Email string
}

type Parent

type Parent struct {
	Commit string
}

type PresubmitTestType

type PresubmitTestType string
const (
	PresubmitTestTypeNone PresubmitTestType = "none"
	PresubmitTestTypeAll  PresubmitTestType = "all"
)

type PushError

type PushError struct {
	Args        []string
	Output      string
	ErrorOutput string
}

func (PushError) Error

func (ge PushError) Error() string

type RelatedChange

type RelatedChange struct {
	Change_id string
}

type RelatedChanges

type RelatedChanges struct {
	Changes []RelatedChange
}

type Review

type Review struct {
	Message  string               `json:"message,omitempty"`
	Labels   map[string]string    `json:"labels,omitempty"`
	Comments map[string][]Comment `json:"comments,omitempty"`
}

Review represents a Gerrit review. For more details, see: http://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#review-input

type Revision

type Revision struct {
	Fetch  `json:"fetch"`
	Commit `json:"commit"`
	Files  `json:"files"`
}

type Revisions

type Revisions map[string]Revision

type Topic

type Topic struct {
	Topic string `json:"topic"`
}

Jump to

Keyboard shortcuts

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