Documentation ¶
Overview ¶
Package gerrit provides library functions for interacting with the gerrit code review system.
Index ¶
- Variables
- func BootstrapGerritSSO(jirix *jiri.X)
- func CacheCookies(jiriCookiePath, hostName string, cookiejar *ssoCookieJar) error
- func FetchCloneBundle(jirix *jiri.X, remote, dir string) (string, error)
- func FetchFile(gerritHost, path string) ([]byte, error)
- func FetchFileSSO(jirix *jiri.X, gerritHost, path string) ([]byte, error)
- func LoadCookies(jirix *jiri.X, jiriCookiePath, hostName string, cookieType CookieType) (*ssoCookieJar, error)
- func MarshalNSCookieData(cookies []*http.Cookie) ([]byte, error)
- func ParseRefString(ref string) (int, int, error)
- func PresubmitTestTypes() []string
- func Push(jirix *jiri.X, dir string, clOpts CLOpts) error
- func Reference(opts CLOpts) string
- func UnmarshalNSCookieData(data []byte) ([]*http.Cookie, error)
- func WriteLog(logFilePath string, cls CLList) (e error)
- type CLList
- type CLOpts
- type CLRefMap
- type Change
- func GenCL(clNumber, patchset int, project string) Change
- func GenCLWithMoreData(clNumber, patchset int, project string, presubmit PresubmitTestType, ...) Change
- func GenMultiPartCL(clNumber, patchset int, project, topic string, index, total int) Change
- func GenMultiPartCLWithMoreData(clNumber, patchset int, project, topic string, index, total int, ...) Change
- type ChangeError
- type Comment
- type Commit
- type CookieType
- type Fetch
- type Files
- type Gerrit
- func (g *Gerrit) GetChange(changeNumber int) (*Change, error)
- func (g *Gerrit) GetChangeByID(changeID string) (*Change, error)
- func (g *Gerrit) GetChangeURL(changeNumber int) string
- func (g *Gerrit) GetRelatedChanges(changeNumber int, revisionId string) (*RelatedChanges, error)
- func (g *Gerrit) ListChangesByCommit(commit string) (CLList, error)
- func (g *Gerrit) ListOpenChangesByTopic(topic string) (CLList, error)
- func (g *Gerrit) PostReview(ref string, message string, labels map[string]string) (e error)
- func (g *Gerrit) Query(query string) (_ CLList, e error)
- func (g *Gerrit) SetTopic(cl string, opts CLOpts) (e error)
- func (g *Gerrit) Submit(changeID string) (e error)
- type Http
- type MultiPartCLInfo
- type MultiPartCLSet
- type Owner
- type Parent
- type PresubmitTestType
- type PushError
- type RelatedChange
- type RelatedChanges
- type Review
- type Revision
- type Revisions
- type Topic
Constants ¶
This section is empty.
Variables ¶
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") )
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
MarshalNSCookieData packs the slice of golang cookies into the Netscape-format cookies.
func ParseRefString ¶
ParseRefString parses the cl and patchset number from the given ref string.
func PresubmitTestTypes ¶
func PresubmitTestTypes() []string
func Reference ¶
Reference inputs CL options and returns a matching string representation of a Gerrit reference.
func UnmarshalNSCookieData ¶
UnmarshalNSCookieData parses the Netscape-format cookies from data and return a slice of golang cookies.
Types ¶
type CLList ¶
type CLList []Change
The following types reflect the schema Gerrit uses to represent CLs.
func NewOpenCLs ¶
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 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 GenCLWithMoreData ¶
func GenCLWithMoreData(clNumber, patchset int, project string, presubmit PresubmitTestType, ownerEmail string) Change
func GenMultiPartCL ¶
func (Change) OwnerEmail ¶
type ChangeError ¶
func NewChangeError ¶
func NewChangeError(cl Change, err error) *ChangeError
func (*ChangeError) Error ¶
func (ce *ChangeError) Error() 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 Gerrit ¶
type Gerrit struct {
// contains filtered or unexported fields
}
Gerrit records a hostname of a Gerrit instance.
func (*Gerrit) GetChangeURL ¶
func (*Gerrit) GetRelatedChanges ¶
func (g *Gerrit) GetRelatedChanges(changeNumber int, revisionId string) (*RelatedChanges, error)
func (*Gerrit) ListChangesByCommit ¶
func (*Gerrit) ListOpenChangesByTopic ¶
func (*Gerrit) PostReview ¶
PostReview posts a review to the given Gerrit reference.
func (*Gerrit) Query ¶
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
type MultiPartCLInfo ¶
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 PresubmitTestType ¶
type PresubmitTestType string
const ( PresubmitTestTypeNone PresubmitTestType = "none" PresubmitTestTypeAll PresubmitTestType = "all" )
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